Skip to content

Commit

Permalink
Clean up network page (#432)
Browse files Browse the repository at this point in the history
- no part off
- no typedefs
  • Loading branch information
Feichtmeier authored Aug 6, 2023
1 parent f7b7626 commit fa7014b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
6 changes: 5 additions & 1 deletion lib/view/pages/connections/models/access_point_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of 'wifi_model.dart';
import 'package:flutter/foundation.dart';
import 'package:nm/nm.dart';
import 'package:settings/view/pages/connections/models/property_stream_notifier.dart';

enum ActiveConnectionState {
unknown,
Expand All @@ -17,6 +19,8 @@ class AccessPointModel extends PropertyStreamNotifier {
addPropertyListener('Strength', notifyListeners);
}
final NetworkManagerAccessPoint _networkManagerAccessPoint;
NetworkManagerAccessPoint get networkManagerAccessPoint =>
_networkManagerAccessPoint;
late final NetworkManagerDeviceWireless _networkManagerDeviceWireless;

bool get isActive =>
Expand Down
7 changes: 6 additions & 1 deletion lib/view/pages/connections/models/wifi_device_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
part of 'wifi_model.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:nm/nm.dart';
import 'package:settings/view/pages/connections/models/access_point_model.dart';
import 'package:settings/view/pages/connections/models/property_stream_notifier.dart';

class WifiDeviceModel extends PropertyStreamNotifier {
WifiDeviceModel(this._networkManagerDevice) {
Expand All @@ -10,6 +14,7 @@ class WifiDeviceModel extends PropertyStreamNotifier {
addPropertyListener('LastScan', notifyListeners);
}
final NetworkManagerDevice _networkManagerDevice;
NetworkManagerDevice get networkManagerDevice => _networkManagerDevice;
late final NetworkManagerDeviceWireless _networkManagerDeviceWireless;

List<AccessPointModel> get accesPoints {
Expand Down
32 changes: 13 additions & 19 deletions lib/view/pages/connections/models/wifi_model.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import 'package:collection/collection.dart';
import 'package:dbus/dbus.dart';
import 'package:flutter/foundation.dart';
import 'package:nm/nm.dart';

import '../data/authentication.dart';
import '../extensions/network_service_x.dart';
import 'property_stream_notifier.dart';

part 'access_point_model.dart';
part 'wifi_device_model.dart';

typedef OnAuthenticate = Future<Authentication?> Function(
WifiDeviceModel wifiAdaptor,
AccessPointModel accessPoint,
);
import 'package:settings/view/pages/connections/data/authentication.dart';
import 'package:settings/view/pages/connections/extensions/network_service_x.dart';
import 'package:settings/view/pages/connections/models/access_point_model.dart';
import 'package:settings/view/pages/connections/models/property_stream_notifier.dart';
import 'package:settings/view/pages/connections/models/wifi_device_model.dart';

class WifiModel extends PropertyStreamNotifier {
WifiModel(this._networkManagerClient) {
Expand Down Expand Up @@ -47,14 +38,17 @@ class WifiModel extends PropertyStreamNotifier {
void connectToAccesPoint(
AccessPointModel accessPointModel,
WifiDeviceModel wifiAdaptorModel,
OnAuthenticate onAuth,
Future<Authentication?> Function(
WifiDeviceModel wifiAdaptor,
AccessPointModel accessPoint,
) onAuth,
) async {
if (accessPointModel.isActive) return;

try {
var connection = await _networkManagerClient.findConnectionFor(
accessPointModel._networkManagerAccessPoint,
wifiAdaptorModel._networkManagerDevice,
accessPointModel.networkManagerAccessPoint,
wifiAdaptorModel.networkManagerDevice,
);
if (connection == null) {
Authentication? authentication;
Expand All @@ -73,9 +67,9 @@ class WifiModel extends PropertyStreamNotifier {
}

await _networkManagerClient.activateConnection(
device: wifiAdaptorModel._networkManagerDevice,
device: wifiAdaptorModel.networkManagerDevice,
connection: connection,
accessPoint: accessPointModel._networkManagerAccessPoint,
accessPoint: accessPointModel.networkManagerAccessPoint,
);
} on DBusMethodResponseException catch (e) {
errorMessage = e.toString();
Expand Down
3 changes: 1 addition & 2 deletions lib/view/pages/connections/widgets/access_point_tile.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:settings/view/pages/connections/models/access_point_model.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '../models/wifi_model.dart';

class AccessPointTile extends StatelessWidget {
const AccessPointTile({
required this.accessPointModel,
Expand Down
5 changes: 2 additions & 3 deletions lib/view/pages/connections/widgets/authentication_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:settings/view/pages/connections/data/authentication.dart';
import 'package:settings/view/pages/connections/models/access_point_model.dart';
import 'package:yaru_icons/yaru_icons.dart';

import '../data/authentication.dart';
import '../models/wifi_model.dart';

class AuthenticationDialog extends StatelessWidget {
AuthenticationDialog({super.key});

Expand Down
1 change: 1 addition & 0 deletions lib/view/pages/connections/wifi_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:settings/constants.dart';
import 'package:settings/l10n/l10n.dart';
import 'package:settings/view/common/yaru_switch_row.dart';
import 'package:settings/view/pages/connections/models/access_point_model.dart';
import 'package:settings/view/pages/settings_page.dart';
import 'package:settings/view/settings_section.dart';
import 'package:yaru_icons/yaru_icons.dart';
Expand Down

0 comments on commit fa7014b

Please sign in to comment.