Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
✨ Add Silent Start Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
uiYzzi committed Apr 8, 2024
1 parent 7b50534 commit 8e102c8
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/common/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Global {
static String videosRule = defaultVideosRule;
static int maxConcurrentDownloads = defaultMaxConcurrentDownloads;
static int maxConnectionPerServer = defaultMaxConnectionPerServer;
static bool silentStart = false;
static Future init() async {
WidgetsFlutterBinding.ensureInitialized();
prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -102,5 +103,6 @@ class Global {
prefs.getString('TrackerSubscriptionAddress') ??
defaultTrackerSubscriptionAddress;
trackerServersList = prefs.getString('TrackerServersList') ?? '';
silentStart = prefs.getBool('SilentStart') ?? false;
}
}
3 changes: 3 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class MessageLookup extends MessageLookupByLibrary {
"Sets the theme of the application."),
"settings": MessageLookupByLibrary.simpleMessage("Settings"),
"showWindow": MessageLookupByLibrary.simpleMessage("Show Window"),
"silentStart": MessageLookupByLibrary.simpleMessage("Silent Start"),
"silentStartInfo": MessageLookupByLibrary.simpleMessage(
"Minimize to tray after startup"),
"sourceCode": MessageLookupByLibrary.simpleMessage("Source code"),
"speedLimit": MessageLookupByLibrary.simpleMessage("Speed Limit"),
"speedLimitInfo": MessageLookupByLibrary.simpleMessage(
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("设置应用程序的主题"),
"settings": MessageLookupByLibrary.simpleMessage("设置"),
"showWindow": MessageLookupByLibrary.simpleMessage("显示窗口"),
"silentStart": MessageLookupByLibrary.simpleMessage("静默启动"),
"silentStartInfo": MessageLookupByLibrary.simpleMessage("启动后最小化到托盘"),
"sourceCode": MessageLookupByLibrary.simpleMessage("源代码"),
"speedLimit": MessageLookupByLibrary.simpleMessage("速度限制"),
"speedLimitInfo": MessageLookupByLibrary.simpleMessage("限制下载或上传速度"),
Expand Down
20 changes: 20 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
"subscriptionAddress":"Subscription Address",
"subscriptionAddressInfo":"Separate links with commas(,)",
"autoUpdateTrackerList":"Update tracker list every day automatically",
"noTaskDownloaded":"There are no current tasks"
"noTaskDownloaded":"There are no current tasks",
"silentStart":"Silent Start",
"silentStartInfo":"Minimize to tray after startup"
}
4 changes: 3 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
"subscriptionAddress":"订阅地址",
"subscriptionAddressInfo":"请以英文逗号(,)分隔链接",
"autoUpdateTrackerList":"每天自动更新 Tracker 服务器列表",
"noTaskDownloaded":"当前没有下载任务"
"noTaskDownloaded":"当前没有下载任务",
"silentStart":"静默启动",
"silentStartInfo":"启动后最小化到托盘"
}
11 changes: 10 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ void main() async {
await windowManager.setMinimumSize(const Size(400, 600));
await windowManager
.setSize(Size(Global.windowWidth, Global.windowHeight));
await windowManager.show();
if (Global.silentStart) {
await windowManager.hide();
} else {
await windowManager.show();
}
await windowManager.setPreventClose(true);
await windowManager.setSkipTaskbar(false);
});
Expand Down Expand Up @@ -268,6 +272,11 @@ class _MyHomePageState extends State<MyHomePage>
trayManager.popUpContextMenu();
}

@override
void onWindowFocus() {
setState(() {});
}

@override
void onTrayMenuItemClick(MenuItem menuItem) {
if (menuItem.key == 'show_window') {
Expand Down
17 changes: 17 additions & 0 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class _SettingsState extends State<Settings> with PageMixin {
late int _maxConnectionPerServer;
late bool _rememberWindowSize;
late bool _classificationSaving;
late bool _silentStart;
@override
void initState() {
super.initState();
Expand All @@ -65,6 +66,7 @@ class _SettingsState extends State<Settings> with PageMixin {
_downloadPathEditingController =
TextEditingController(text: Global.downloadPath);
_rememberWindowSize = Global.rememberWindowSize;
_silentStart = Global.silentStart;
_maxOverallDownloadLimitEditingController =
TextEditingController(text: Global.maxOverallDownloadLimit.toString());
_maxDownloadLimitEditingController =
Expand Down Expand Up @@ -202,6 +204,21 @@ class _SettingsState extends State<Settings> with PageMixin {
),
),
spacer,
SettingsCard(
title: S.of(context).silentStart,
subtitle: S.of(context).silentStartInfo,
content: ToggleSwitch(
checked: _silentStart,
onChanged: (bool value) {
setState(() {
_silentStart = value; // 更新状态
Global.silentStart = value;
Global.prefs.setBool('SilentStart', value);
});
},
),
),
spacer,
],
if (isDesktop || isTablet(MediaQuery.of(context))) ...[
SettingsCard(
Expand Down
2 changes: 1 addition & 1 deletion linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void my_application_activate(GApplication* application) {

fl_register_plugins(FL_PLUGIN_REGISTRY(view));

gtk_widget_show(GTK_WIDGET(window));
gtk_widget_realize(GTK_WIDGET(window));
gtk_widget_show(GTK_WIDGET(view));
gtk_widget_grab_focus(GTK_WIDGET(view));
}
Expand Down
2 changes: 1 addition & 1 deletion windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool FlutterWindow::OnCreate() {
SetChildContent(flutter_controller_->view()->GetNativeWindow());

flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
//this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
Expand Down
3 changes: 2 additions & 1 deletion windows/runner/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ bool Win32Window::Create(const std::wstring& title,
double scale_factor = dpi / 96.0;

HWND window = CreateWindow(
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
window_class, title.c_str(),
WS_OVERLAPPEDWINDOW, // do not add WS_VISIBLE since the window will be shown later
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);
Expand Down

0 comments on commit 8e102c8

Please sign in to comment.