Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add minimize to tray on close feature for Windows

Tristan1ab1ea061e27
diff --git a/mobile/apps/auth/lib/app/view/app.dart b/mobile/apps/auth/lib/app/view/app.dart
index cfae7f23ff..84aba1b030 100644
--- a/mobile/apps/auth/lib/app/view/app.dart
+++ b/mobile/apps/auth/lib/app/view/app.dart
@@ -9,6 +9,7 @@ import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/locale.dart';
import "package:ente_auth/onboarding/view/onboarding_page.dart";
import 'package:ente_auth/services/authenticator_service.dart';
+import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/services/update_service.dart';
import 'package:ente_auth/services/window_listener_service.dart';
import 'package:ente_auth/ui/home_page.dart';
@@ -213,4 +214,17 @@ class _AppState extends State<App>
break;
}
}
+
+ @override
+ void onWindowClose() {
+ final shouldMinimizeToTray =
+ PreferenceService.instance.shouldMinimizeToTrayOnClose();
+ if (shouldMinimizeToTray) {
+ windowManager.hide();
+ windowManager.setSkipTaskbar(true);
+ } else {
+ windowManager.setPreventClose(false);
+ windowManager.destroy();
+ }
+ }
}
diff --git a/mobile/apps/auth/lib/main.dart b/mobile/apps/auth/lib/main.dart
index 5136e72feb..2e10a1ef5b 100644
--- a/mobile/apps/auth/lib/main.dart
+++ b/mobile/apps/auth/lib/main.dart
@@ -7,7 +7,7 @@ import "package:ente_auth/app/view/app.dart";
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/core/constants.dart';
import 'package:ente_auth/ente_theme_data.dart';
-import 'package:ente_auth/l10n/l10n.dart';
+import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/locale.dart';
import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/services/billing_service.dart';
@@ -74,6 +74,7 @@ void main() async {
if (PlatformUtil.isDesktop()) {
await windowManager.ensureInitialized();
await WindowListenerService.instance.init();
+ await windowManager.setPreventClose(true);
WindowOptions windowOptions = WindowOptions(
size: WindowListenerService.instance.getWindowSize(),
maximumSize: const Size(8192, 8192),
@@ -116,7 +117,7 @@ Future<void> _runInForeground() async {
darkTheme: darkThemeData,
savedThemeMode: savedThemeMode,
localeListResolutionCallback: localResolutionCallBack,
- localizationsDelegates: const [
+ localizationsDelegates: const [
...StringsLocalizations.localizationsDelegates,
...AppLocalizations.localizationsDelegates,
],
diff --git a/mobile/apps/auth/lib/services/preference_service.dart b/mobile/apps/auth/lib/services/preference_service.dart
index fd3b6d68c7..1f336461ec 100644
--- a/mobile/apps/auth/lib/services/preference_service.dart
+++ b/mobile/apps/auth/lib/services/preference_service.dart
@@ -23,6 +23,8 @@ class PreferenceService {
static const kShouldHideCodesKey = "should_hide_codes";
static const kShouldAutoFocusOnSearchBar = "should_auto_focus_on_search_bar";
static const kShouldMinimizeOnCopy = "should_minimize_on_copy";
+ static const kShouldMinimizeToTrayOnClose =
+ "should_minimize_to_tray_on_close";
static const kCompactMode = "vi.compactMode";
static const kAppInstallTime = "appInstallTime";
@@ -106,6 +108,18 @@ class PreferenceService {
await _prefs.setBool(kShouldMinimizeOnCopy, value);
}
+ bool shouldMinimizeToTrayOnClose() {
+ if (_prefs.containsKey(kShouldMinimizeToTrayOnClose)) {
+ return _prefs.getBool(kShouldMinimizeToTrayOnClose)!;
+ } else {
+ return false;
+ }
+ }
+
+ Future<void> setShouldMinimizeToTrayOnClose(bool value) async {
+ await _prefs.setBool(kShouldMinimizeToTrayOnClose, value);
+ }
+
int getAppInstalledTime() {
if (_prefs.containsKey(kAppInstallTime)) {
return _prefs.getInt(kAppInstallTime)!;
@@ -122,9 +136,7 @@ class PreferenceService {
return _prefs.getInt(kLocalTimeOffsetKey) ?? 0;
}
- void computeAndStoreTimeOffset(
- int? epochTimeInMicroseconds,
- ) {
+ void computeAndStoreTimeOffset(int? epochTimeInMicroseconds) {
if (epochTimeInMicroseconds == null) {
_prefs.remove(kLocalTimeOffsetKey);
return;
diff --git a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
index 8475f45c3a..b16cd22389 100644
--- a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
+++ b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
@@ -147,6 +147,24 @@ class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {
),
sectionOptionSpacing,
],
+ if (Platform.isWindows) ...[
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: l10n.minimizeToTrayOnClose,
+ ),
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ PreferenceService.instance.shouldMinimizeToTrayOnClose(),
+ onChanged: () async {
+ await PreferenceService.instance.setShouldMinimizeToTrayOnClose(
+ !PreferenceService.instance.shouldMinimizeToTrayOnClose(),
+ );
+ setState(() {});
+ },
+ ),
+ ),
+ sectionOptionSpacing,
+ ],
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: l10n.crashAndErrorReporting,