Skip to content

Commit f0bf4b7

Browse files
committed
Support for linux!
1 parent 84e2202 commit f0bf4b7

File tree

11 files changed

+43
-28
lines changed

11 files changed

+43
-28
lines changed

assets/globe.png

23.1 KB
Loading

assets/globe_leaked.png

24.2 KB
Loading

assets/iran.png

5.91 KB
Loading

assets/loading.png

7.66 KB
Loading

assets/network_error.png

3.44 KB
Loading

assets/offline.png

3.85 KB
Loading

lib/bloc.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ class AppBloc with AppSystemTray {
224224
}
225225

226226
Future<void> _checkProxySettings() async {
227-
if (Platform.isMacOS) {
228-
// todo: implement macOS
229-
return;
227+
if (Platform.isWindows == false) {
228+
// todo: implement other platforms
229+
return Future.value();
230230
}
231231
final localNetwork = await AppCmd.getLocalNetworkInfo();
232232
_localNetwork.value = localNetwork;
@@ -270,8 +270,8 @@ class AppBloc with AppSystemTray {
270270
}
271271

272272
void _showToast(String title) {
273-
if (Platform.isMacOS) {
274-
// todo: implement macOS
273+
if (Platform.isWindows == false) {
274+
// todo: implement other platforms
275275
return;
276276
}
277277
WinToast.instance().showToast(type: ToastType.text01, title: title);
@@ -349,12 +349,7 @@ class AppBloc with AppSystemTray {
349349
} else {
350350
tooltip = 'IRNet: $country';
351351
}
352-
var globIcon = 'assets/globe.ico';
353-
if (_foundALeakedSite && (await AppSharedPreferences.showLeakInSysTray)) {
354-
globIcon = 'assets/globe_leaked.ico';
355-
}
356-
final iconPath = isIran ? 'assets/iran.ico' : globIcon;
357-
updateSysTrayIcon(tooltip, iconPath);
352+
updateIconWhenCountryLoaded(_foundALeakedSite, isIran, tooltip);
358353
debugPrint('Country => $country');
359354
}
360355
}

lib/main.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ Future<void> initWindowManager() async {
3030
WindowOptions windowOptions = const WindowOptions(
3131
size: Size(1000, 780),
3232
);
33-
windowManager.waitUntilReadyToShow(windowOptions, () {
34-
windowManager.setTitle("IRNet: freedom does not have a price");
35-
},);
33+
windowManager.waitUntilReadyToShow(
34+
windowOptions,
35+
() {
36+
windowManager.setTitle("IRNet: freedom does not have a price");
37+
},
38+
);
3639
}
3740

3841
Future<void> initSingleInstance() async {
3942
await WindowsSingleInstance.ensureSingleInstance([], "pipeMain");
4043
}
4144

4245
Future<void> initWinToast() async {
43-
if (Platform.isMacOS) {
44-
// todo: implement macos
46+
if (Platform.isWindows == false) {
47+
// todo: implement other platforms
4548
return Future.value();
4649
}
4750
await WinToast.instance().initialize(

lib/utils/system_tray.dart

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4+
import 'package:ir_net/data/shared_preferences.dart';
45
import 'package:system_tray/system_tray.dart';
56

67
mixin AppSystemTray {
@@ -14,13 +15,31 @@ mixin AppSystemTray {
1415
_systemTray.setImage(iconPath);
1516
}
1617

18+
String _getIcon(String iconPath) {
19+
if (Platform.isLinux) {
20+
return '$iconPath.png';
21+
} else {
22+
return '$iconPath.ico';
23+
}
24+
}
25+
26+
void updateIconWhenCountryLoaded(
27+
bool foundLeak, bool isIran, String tooltip) async {
28+
var globIcon = _getIcon('assets/globe');
29+
if (foundLeak && (await AppSharedPreferences.showLeakInSysTray)) {
30+
globIcon = _getIcon('assets/globe_leaked');
31+
}
32+
final iconPath = isIran ? _getIcon('assets/iran') : globIcon;
33+
updateSysTrayIcon(tooltip, iconPath);
34+
}
35+
1736
void setSystemTrayStatusToOffline() {
18-
_systemTray.setImage('assets/offline.ico');
37+
_systemTray.setImage(_getIcon('assets/offline'));
1938
_systemTray.setToolTip('IRNet: OFFLINE');
2039
}
2140

2241
void setSystemTrayStatusToNetworkError() {
23-
_systemTray.setImage('assets/network_error.ico');
42+
_systemTray.setImage(_getIcon('assets/network_error'));
2443
_systemTray.setToolTip('IRNet: Network error');
2544
}
2645

@@ -31,7 +50,7 @@ mixin AppSystemTray {
3150
Future<void> initSystemTray() async {
3251
await _systemTray.initSystemTray(
3352
title: null,
34-
iconPath: 'assets/loading.ico',
53+
iconPath: _getIcon('assets/loading'),
3554
);
3655
final Menu menu = Menu();
3756
await menu.buildFrom([
@@ -65,4 +84,4 @@ mixin AppSystemTray {
6584
_appWindow.hide();
6685
_systemTray.setToolTip('IRNet: NOT READY');
6786
}
68-
}
87+
}

lib/views/options.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ class _AppOptionsState extends State<AppOptions> {
1919
width: 400,
2020
child: Column(
2121
crossAxisAlignment: CrossAxisAlignment.start,
22-
children: [
23-
showLeakInSysTray(),
24-
launchAtStartup()
25-
],
22+
children: [showLeakInSysTray(), launchAtStartup()],
2623
),
2724
);
2825
}
2926

3027
Widget launchAtStartup() {
28+
if (Platform.isWindows == false) {
29+
// todo: implement other platforms
30+
return SizedBox();
31+
}
3132
return FutureBuilder<bool>(
3233
future: LaunchAtStartup.instance.isEnabled(),
3334
builder: (context, snapshot) {
@@ -36,7 +37,6 @@ class _AppOptionsState extends State<AppOptions> {
3637
title: const Text('Launch on windows startup?'),
3738
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
3839
value: value,
39-
enabled: !Platform.isMacOS, // todo: implement macos
4040
onChanged: (enabled) {
4141
if (enabled == true) {
4242
LaunchAtStartup.instance.enable();

0 commit comments

Comments
 (0)