mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:spotube/hooks/configurators/use_window_listener.dart';
|
|
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
|
import 'package:spotube/provider/user_preferences/user_preferences_state.dart';
|
|
import 'package:local_notifier/local_notifier.dart';
|
|
import 'package:spotube/utils/platform.dart';
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
final closeNotification = !kIsDesktop
|
|
? null
|
|
: (LocalNotification(
|
|
title: 'Spotube',
|
|
body: 'Running in background. Minimized to System Tray',
|
|
actions: [
|
|
LocalNotificationAction(text: 'Close The App'),
|
|
],
|
|
)..onClickAction = (value) {
|
|
exit(0);
|
|
});
|
|
|
|
void useCloseBehavior(WidgetRef ref) {
|
|
useWindowListener(
|
|
onWindowClose: () async {
|
|
final preferences = ref.read(userPreferencesProvider);
|
|
if (preferences.closeBehavior == CloseBehavior.minimizeToTray) {
|
|
await windowManager.hide();
|
|
closeNotification?.show();
|
|
} else {
|
|
exit(0);
|
|
}
|
|
},
|
|
);
|
|
}
|