mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-13 20:03:46 +00:00
feat(ui): support running as menubar app (#1216)
This commit is contained in:
1 parent
b0e133b554
commit
cb6331c20d
28 files changed
+214
-40
No files matched your search
@@ -115,6 +115,9 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
@override
|
||||
void onWindowFocus() {
|
||||
refresh();
|
||||
if (Util.isMacos() && Database.instance.getRunAsMenubarApp()) {
|
||||
windowManager.setSkipTaskbar(true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -9,9 +9,11 @@ import 'package:gopeed/app/views/copy_button.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:launch_at_startup/launch_at_startup.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../../../../api/api.dart' as api;
|
||||
import '../../../../api/model/downloader_config.dart';
|
||||
import '../../../../database/database.dart';
|
||||
import '../../../../i18n/message.dart';
|
||||
import '../../../../util/input_formatter.dart';
|
||||
import '../../../../util/locale_manager.dart';
|
||||
@@ -369,6 +371,46 @@ class SettingView extends GetView<SettingController> {
|
||||
);
|
||||
});
|
||||
|
||||
// Menubar mode only for macOS
|
||||
final buildMenubarMode = !Util.isMacos()
|
||||
? () => null
|
||||
: _buildConfigItem('runAsMenubarApp', () {
|
||||
return Database.instance.getRunAsMenubarApp() ? 'on'.tr : 'off'.tr;
|
||||
}, (Key key) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Switch(
|
||||
value: Database.instance.getRunAsMenubarApp(),
|
||||
onChanged: (bool value) async {
|
||||
// Save to database (single source of truth)
|
||||
Database.instance.saveRunAsMenubarApp(value);
|
||||
// Apply dock icon visibility
|
||||
await windowManager.setSkipTaskbar(value);
|
||||
// Small delay to let macOS process the activation policy change
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
// Ensure window stays visible after toggle
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
// Force UI refresh
|
||||
controller.clearTap();
|
||||
await debounceSave();
|
||||
},
|
||||
),
|
||||
Text(
|
||||
'runAsMenubarAppDesc'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).hintColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
// http config items start
|
||||
final httpConfig = downloaderCfg.value.protocolConfig.http;
|
||||
final buildHttpUa =
|
||||
@@ -1353,6 +1395,7 @@ class SettingView extends GetView<SettingController> {
|
||||
buildDefaultDirectDownload(),
|
||||
buildBrowserExtension(),
|
||||
buildAutoStartup(),
|
||||
buildMenubarMode(),
|
||||
]),
|
||||
)),
|
||||
Text('archives'.tr),
|
||||
|
||||
Reference in new issue
Block a user