Skip to content

Commit

Permalink
bump version to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
hagaygo committed Feb 5, 2023
1 parent cb191a4 commit 38bc29b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 101 deletions.
155 changes: 55 additions & 100 deletions lib/Page/mainPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
try {
final PackageInfo info = await PackageInfo.fromPlatform();
_appVersion = info.version;
if (_appVersion.endsWith(".0"))
_appVersion = _appVersion.substring(0, _appVersion.length - 2);
if (_appVersion.endsWith(".0")) _appVersion = _appVersion.substring(0, _appVersion.length - 2);
} catch (exception) {
_appVersion = "1.20"; // currently there is an error on windows build
_appVersion = "1.21"; // currently there is an error on windows build
}
}

Expand Down Expand Up @@ -106,9 +105,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {

void initAutoRefreshTimer() {
if (_autoRefresh) {
autoRefreshTimer = new Timer.periodic(
Duration(seconds: SettingsUtil.appSettings.autoRefreshInterval),
(Timer t) {
autoRefreshTimer = new Timer.periodic(Duration(seconds: SettingsUtil.appSettings.autoRefreshInterval), (Timer t) {
var route = ModalRoute.of(context);
if (route != null && route.isCurrent) {
refreshOverviews();
Expand All @@ -119,8 +116,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {

void showAddDialog() {
if (SettingsUtil.devices.length == 0) {
Dialogs.simpleAlert(context, "No devices found",
"You must add at least one device on devices menu");
Dialogs.simpleAlert(context, "No devices found", "You must add at least one device on devices menu");
} else
showOverviewDialog("Add Overview Item for a device", null);
}
Expand Down Expand Up @@ -161,8 +157,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
featureId: showDrawerFeatureId,
tapTarget: Icon(Icons.menu),
title: Text('Click here to open menu'),
description: Text(
'On the menu you can setup identities, devices and more settings'),
description: Text('On the menu you can setup identities, devices and more settings'),
child: Icon(Icons.menu),
))),
body: RefreshIndicator(
Expand All @@ -181,8 +176,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
featureId: addOverviewFeatureId,
tapTarget: const Icon(Icons.add),
title: Text('Add new overview to main view'),
description: Text(
'After setting up your device, you can add an overview for that device'),
description: Text('After setting up your device, you can add an overview for that device'),
child: FloatingActionButton(
onPressed: () {
showAddDialog();
Expand Down Expand Up @@ -243,27 +237,22 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
children: <Widget>[
Text('Options'),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
SettingsUtil.getDevices().then((dvs) {
Clipboard.setData(ClipboardData(
text: OpenWrtClient
.lastJSONRequest +
"\n\n" +
OpenWrtClient
.lastJSONResponse +
"\n\n" +
jsonEncode(dvs)));
Dialogs.simpleAlert(context, "",
"Debug data\n Copied to clipboard");
});
},
icon: Icon(Icons.help_center))
]))
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
IconButton(
onPressed: () {
Navigator.pop(context);
SettingsUtil.getDevices().then((dvs) {
Clipboard.setData(ClipboardData(
text: OpenWrtClient.lastJSONRequest +
"\n\n" +
OpenWrtClient.lastJSONResponse +
"\n\n" +
jsonEncode(dvs)));
Dialogs.simpleAlert(context, "", "Debug data\n Copied to clipboard");
});
},
icon: Icon(Icons.help_center))
]))
],
)
],
Expand All @@ -273,42 +262,36 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
),
),
ListTile(
leading: Container(
width: drawerIconWidth, child: const Icon(Icons.refresh)),
leading: Container(width: drawerIconWidth, child: const Icon(Icons.refresh)),
title: Text('Refresh'),
onTap: () {
Navigator.pop(context);
refreshOverviews();
},
),
ListTile(
leading: Container(
width: drawerIconWidth,
child: const Icon(Icons.account_circle)),
leading: Container(width: drawerIconWidth, child: const Icon(Icons.account_circle)),
title: Text('Identities'),
onTap: () {
SettingsUtil.getIdentities().then((ids) {
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => IdentitiesPage()),
MaterialPageRoute(builder: (context) => IdentitiesPage()),
);
});
},
),
ListTile(
leading: Container(
width: drawerIconWidth, child: const Icon(Icons.router)),
leading: Container(width: drawerIconWidth, child: const Icon(Icons.router)),
title: Text('Devices'),
onTap: () {
SettingsUtil.getIdentities().then((ids) {
SettingsUtil.getDevices().then((dvs) {
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DevicesPage()),
MaterialPageRoute(builder: (context) => DevicesPage()),
).then((value) {
refreshOverviews();
});
Expand All @@ -317,19 +300,15 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
},
),
ListTile(
leading: Container(
width: drawerIconWidth,
child: const Icon(Icons.device_hub)),
leading: Container(width: drawerIconWidth, child: const Icon(Icons.device_hub)),
title: Text('Update Devices'),
onTap: () {
SettingsUtil.getIdentities().then((ids) {
SettingsUtil.getDevices().then((dvs) {
Navigator.pop(context);
updateDevicesData(dvs).then((x) {
Navigator.pop(context);
if (x.length > 0)
Dialogs.simpleAlert(
context, "Update Device failed", x.join(","));
if (x.length > 0) Dialogs.simpleAlert(context, "Update Device failed", x.join(","));
});
Dialogs.showLoadingDialog(context);
});
Expand All @@ -347,9 +326,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
onChanged: (bool value) {
setState(() {
_darkTheme = value;
Provider.of<ThemeChangeNotifier>(context,
listen: false)
.toggleTheme();
Provider.of<ThemeChangeNotifier>(context, listen: false).toggleTheme();
});
},
value: _darkTheme,
Expand Down Expand Up @@ -404,8 +381,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
Expanded(
child: Align(
alignment: Alignment.bottomLeft,
child: Container(
padding: EdgeInsets.all(10), child: Text(_appVersion))))
child: Container(padding: EdgeInsets.all(10), child: Text(_appVersion))))
])
]));
}
Expand All @@ -428,16 +404,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
});
} else {
for (var oi in SettingsUtil.overviews) {
if (!requestMap.containsKey(oi.deviceGuid))
requestMap[oi.deviceGuid] = [];
if (!requestMap.containsKey(oi.deviceGuid)) requestMap[oi.deviceGuid] = [];
var l = requestMap[oi.deviceGuid];
for (var n in OverviewItemManager.items[oi.overiviewItemGuid].commands)
if (l.firstWhere((x) => x.runtimeType == n.runtimeType,
orElse: () => null) ==
null) {
if (l.firstWhere((x) => x.runtimeType == n.runtimeType, orElse: () => null) == null) {
var nr = n.createReply(ReplyStatus.Ok, null,
device: SettingsUtil.devices
.firstWhere((d) => d.guid == oi.deviceGuid));
device: SettingsUtil.devices.firstWhere((d) => d.guid == oi.deviceGuid));
if (nr is CommandReplyBase) {
l.add(nr);
} else
Expand All @@ -451,27 +423,20 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
}
}

if (_deviceAuthentication.keys.length >
0) // means at least one device got authentication result
if (_deviceAuthentication.keys.length > 0) // means at least one device got authentication result
{
if (_deviceReply.keys.length >
0) // at least one device got command replies
if (_deviceReply.keys.length > 0) // at least one device got command replies
{
setState(() {});
}
} else if (_refreshing && requestMap.keys.length > 0) {
for (var deviceGuid in requestMap.keys) {
var d = SettingsUtil.devices.firstWhere((x) => x.guid == deviceGuid);
var oc = OpenWrtClient(
d,
SettingsUtil.identities
.firstWhere((x) => x.guid == d.identityGuid));
var oc = OpenWrtClient(d, SettingsUtil.identities.firstWhere((x) => x.guid == d.identityGuid));
oc.authenticate().then((res) {
_deviceAuthentication[d] = res;
if (res.status == ReplyStatus.Ok) {
oc
.getData(res.authenticationCookie, requestMap[d.guid])
.then((dataResult) {
oc.getData(res.authenticationCookie, requestMap[d.guid]).then((dataResult) {
setState(() {
_deviceReply[d] = dataResult;
});
Expand Down Expand Up @@ -522,42 +487,37 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {

getOverviewMainWidget(SelectedOverviewItem oi) {
var ovi = OverviewItemManager.items[oi.overiviewItemGuid];
var device = SettingsUtil.devices
.firstWhere((x) => oi.deviceGuid == x.guid, orElse: () => null);
var device = SettingsUtil.devices.firstWhere((x) => oi.deviceGuid == x.guid, orElse: () => null);
if (device == null) return Text("Bad device");
AuthenticateReply deviceAuthenticationStatus;
if (_deviceAuthentication.containsKey(device))
deviceAuthenticationStatus = _deviceAuthentication[device];
if (_deviceAuthentication.containsKey(device)) deviceAuthenticationStatus = _deviceAuthentication[device];
List<CommandReplyBase> deviceReplies;
if (_deviceReply.containsKey(device)) deviceReplies = _deviceReply[device];
var inRefresh = _refreshing &&
deviceReplies == null &&
(deviceAuthenticationStatus == null ||
deviceAuthenticationStatus.status == ReplyStatus.Ok);
(deviceAuthenticationStatus == null || deviceAuthenticationStatus.status == ReplyStatus.Ok);
switch (ovi.type) {
case OverviewItemType.SystemInfo:
return SystemInfo(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return SystemInfo(device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
case OverviewItemType.NetworkStatus:
return NetworkStatus(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return NetworkStatus(
device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
case OverviewItemType.NetworkTraffic:
return NetworkTraffic(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return NetworkTraffic(
device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
case OverviewItemType.WifiStatus:
return WIFIStatus(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return WIFIStatus(device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
case OverviewItemType.DHCPLeaseInfo:
return DHCPLeaseStatus(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return DHCPLeaseStatus(
device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
case OverviewItemType.ActiveConnections:
return ActiveConnections(device, inRefresh, deviceAuthenticationStatus,
deviceReplies, ovi, oi.guid, refreshOverviews);
return ActiveConnections(
device, inRefresh, deviceAuthenticationStatus, deviceReplies, ovi, oi.guid, refreshOverviews);
break;
}
}
Expand All @@ -567,18 +527,13 @@ Future<List<String>> updateDevicesData(List<Device> devices) async {
List<String> failedDevices = [];

for (var d in devices) {
var cli = OpenWrtClient(
d, SettingsUtil.identities.firstWhere((i) => i.guid == d.identityGuid));
var cli = OpenWrtClient(d, SettingsUtil.identities.firstWhere((i) => i.guid == d.identityGuid));

try {
await cli.authenticate().then((c) {
cli.getData(c.authenticationCookie,
[NetworkDeviceReply(ReplyStatus.Ok)]).then((res) {
var interfaces =
(res[0].data['result'] as List)[1] as Map<String, dynamic>;
d.wifiDevices = interfaces.keys
.where((i) => interfaces[i]['wireless'] == true)
.toList();
cli.getData(c.authenticationCookie, [NetworkDeviceReply(ReplyStatus.Ok)]).then((res) {
var interfaces = (res[0].data['result'] as List)[1] as Map<String, dynamic>;
d.wifiDevices = interfaces.keys.where((i) => interfaces[i]['wireless'] == true).toList();
SettingsUtil.saveDevices();
}).catchError((e) {
failedDevices.add(d.displayName);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: openwrt_manager
description: OpenWrt Manager app for your devices.

version: 1.20.0+201200
version: 1.21.0+201210

environment:
sdk: ">=2.3.0 <3.0.0"
Expand Down

0 comments on commit 38bc29b

Please sign in to comment.