Skip to content

Commit

Permalink
Add exit option to system tray and add optional param to setSentry
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Dec 15, 2024
1 parent 8223563 commit 54b848c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ void main() async {
MenuItemLabel(
label: 'Show app',
onClicked: (menuItem) => appWindow.show(),
)
),
MenuItemLabel(label: 'Exit', onClicked: (menuItem) => appWindow.close())
]);

await systemTray.setContextMenu(menu);

systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint('eventName: $eventName');
if (eventName == kSystemTrayEventClick) {
Platform.isWindows ? appWindow.show() : systemTray.popUpContextMenu();
} else if (eventName == kSystemTrayEventRightClick) {
Expand All @@ -107,6 +106,7 @@ void main() async {
await Hive.openBox('vault');

final settings = Settings.init();

if (settings.isSentryEnabled) {
await SentryFlutter.init(
(options) {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/settings/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Settings extends _$Settings {
}

static SettingsModel init() {
const defaultValue =
SettingsModel(isSentryEnabled: false, themeMode: ThemeMode.system);
final defaultValue = SettingsModel.defaultValue();

try {
final Map<String, dynamic> raw = jsonDecode(
Expand All @@ -54,7 +53,7 @@ class Settings extends _$Settings {
}
}

void setSentry(Option<bool> choice) {
void setSentry({Option<bool> choice = const None()}) {
state = state.copyWith(
isSentryEnabled: choice.match(
() => !state.isSentryEnabled,
Expand All @@ -65,7 +64,9 @@ class Settings extends _$Settings {
}

void updateThemeMode(ThemeMode? newThemeMode) async {
if (newThemeMode == state.themeMode || newThemeMode == null) return;
if (newThemeMode == state.themeMode || newThemeMode == null) {
return;
}

state = state.copyWith(themeMode: newThemeMode);
Hive.box('vault').put('settings', jsonEncode(state.toJson()));
Expand Down
3 changes: 3 additions & 0 deletions lib/src/settings/models/settings_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ class SettingsModel with _$SettingsModel {

factory SettingsModel.fromJson(Map<String, Object?> json) =>
_$SettingsModelFromJson(json);

factory SettingsModel.defaultValue() =>
const SettingsModel(isSentryEnabled: false, themeMode: ThemeMode.system);
}
3 changes: 1 addition & 2 deletions lib/src/settings/views/settings_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:fpdart/fpdart.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:syncvault/helpers.dart';
import 'package:syncvault/src/accounts/controllers/folder_controller.dart';
Expand Down Expand Up @@ -78,7 +77,7 @@ class SettingsView extends ConsumerWidget {
Switch(
value: settings.isSentryEnabled,
onChanged: (val) {
settingsNotifier.setSentry(none());
settingsNotifier.setSentry();
},
)
],
Expand Down

0 comments on commit 54b848c

Please sign in to comment.