forked from canonical/multipass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gui] add basiscs for autostart and implement for linux
- Loading branch information
1 parent
0a8234f
commit 3fa513a
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Desktop Entry] | ||
Name=Multipass | ||
Exec=multipass.gui | ||
Type=Application | ||
Terminal=false | ||
Categories=Utility; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
final autostartProvider = | ||
AsyncNotifierProvider.autoDispose<AutostartNotifier, bool>(() { | ||
if (Platform.isLinux) return LinuxAutostartNotifier(); | ||
if (Platform.isWindows) return WindowsAutostartNotifier(); | ||
if (Platform.isMacOS) return MacOSAutostartNotifier(); | ||
throw UnimplementedError('no autostart notifier for this platform'); | ||
}); | ||
|
||
abstract class AutostartNotifier extends AutoDisposeAsyncNotifier<bool> { | ||
Future<void> set(bool value); | ||
} | ||
|
||
class LinuxAutostartNotifier extends AutostartNotifier { | ||
static const autostartFile = 'multipass.gui.autostart.desktop'; | ||
final file = File( | ||
'${Platform.environment['HOME']}/.config/autostart/$autostartFile', | ||
); | ||
|
||
@override | ||
Future<bool> build() => file.exists(); | ||
|
||
@override | ||
Future<void> set(bool value) async { | ||
if (value) { | ||
final data = await rootBundle.load('assets/$autostartFile'); | ||
await file.writeAsBytes(data.buffer.asUint8List()); | ||
} else { | ||
if (await file.exists()) await file.delete(); | ||
} | ||
|
||
ref.invalidateSelf(); | ||
} | ||
} | ||
|
||
class WindowsAutostartNotifier extends AutostartNotifier { | ||
@override | ||
FutureOr<bool> build() { | ||
// TODO: implement build | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<void> set(bool value) { | ||
// TODO: implement set | ||
throw UnimplementedError(); | ||
} | ||
} | ||
|
||
class MacOSAutostartNotifier extends AutostartNotifier { | ||
@override | ||
FutureOr<bool> build() { | ||
// TODO: implement build | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<void> set(bool value) { | ||
// TODO: implement set | ||
throw UnimplementedError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters