Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: show exist window rather than show error dialog when application is launched twice

林晨8286468362ba
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..6362786e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,69 @@
+# Set default behavior to automatically normalize line endings
+* text=auto
+
+# Explicitly declare text files you want to always be normalized and converted to native line endings on checkout
+*.dart text eol=lf
+*.yaml text eol=lf
+*.yml text eol=lf
+*.json text eol=lf
+*.xml text eol=lf
+*.html text eol=lf
+*.css text eol=lf
+*.js text eol=lf
+*.md text eol=lf
+*.txt text eol=lf
+*.sh text eol=lf
+*.gradle text eol=lf
+*.properties text eol=lf
+
+# Source code files (C/C++/Objective-C/Swift)
+*.c text eol=lf
+*.cc text eol=lf
+*.cpp text eol=lf
+*.h text eol=lf
+*.hpp text eol=lf
+*.m text eol=lf
+*.mm text eol=lf
+*.swift text eol=lf
+
+# CMake files
+*.cmake text eol=lf
+CMakeLists.txt text eol=lf
+
+# Generated files should always use LF (Flutter generates these)
+**/generated_plugin_registrant.* text eol=lf
+**/generated_plugins.cmake text eol=lf
+**/GeneratedPluginRegistrant.* text eol=lf
+
+# Windows-specific files use CRLF
+*.bat text eol=crlf
+*.cmd text eol=crlf
+*.ps1 text eol=crlf
+
+# Visual Studio files
+*.sln text eol=crlf
+*.vcxproj text eol=crlf
+*.vcxproj.filters text eol=crlf
+
+# Denote all files that are truly binary and should not be modified
+*.png binary
+*.jpg binary
+*.jpeg binary
+*.gif binary
+*.ico binary
+*.ttf binary
+*.otf binary
+*.eot binary
+*.woff binary
+*.woff2 binary
+*.so binary
+*.dylib binary
+*.dll binary
+*.exe binary
+*.jar binary
+*.aar binary
+*.apk binary
+*.aab binary
+*.zip binary
+*.tar binary
+*.gz binary
diff --git a/pubspec.lock b/pubspec.lock
index 7cede8c0..558bcf0d 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -898,10 +898,10 @@ packages:
dependency: "direct dev"
description:
name: msix
- sha256: bbb9b3ff4a9f8e7e7507b2a22dc0517fd1fe3db44e72de7ab052cb6b362406ee
+ sha256: f88033fcb9e0dd8de5b18897cbebbd28ea30596810f4a7c86b12b0c03ace87e5
url: "https://pub.dev"
source: hosted
- version: "3.16.10"
+ version: "3.16.12"
nested:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index 9da62e83..eee68dfc 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -156,7 +156,7 @@ dev_dependencies:
hive_generator: ^2.0.0
flutter_launcher_icons: ^0.14.3
flutter_native_splash: ^2.4.3
- msix: ^3.16.8
+ msix: ^3.16.12
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp
index ae965c4a..a20bbc9e 100644
--- a/windows/runner/main.cpp
+++ b/windows/runner/main.cpp
@@ -19,6 +19,44 @@ extern "C"
HANDLE mutex = NULL;
+// Window class name must match the one in win32_window.cpp
+constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
+
+bool ActivateExistingWindow()
+{
+ // Find the existing window by class name
+ HWND hwnd = ::FindWindow(kWindowClassName, nullptr);
+ if (hwnd != NULL)
+ {
+ // Check if window is hidden (e.g., minimized to tray)
+ if (!::IsWindowVisible(hwnd))
+ {
+ // Show the hidden window
+ ::ShowWindow(hwnd, SW_SHOW);
+ }
+ // If window is minimized, restore it
+ else if (::IsIconic(hwnd))
+ {
+ ::ShowWindow(hwnd, SW_RESTORE);
+ }
+
+ // Bring window to foreground
+ ::SetForegroundWindow(hwnd);
+
+ // Flash the window to get user's attention
+ FLASHWINFO fwi = {0};
+ fwi.cbSize = sizeof(FLASHWINFO);
+ fwi.hwnd = hwnd;
+ fwi.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
+ fwi.uCount = 3;
+ fwi.dwTimeout = 0;
+ ::FlashWindowEx(&fwi);
+
+ return true;
+ }
+ return false;
+}
+
bool isSingleInstance()
{
if (mutex != NULL)
@@ -43,8 +81,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
// This is important for the application to work correctly with the local storage.
if (!isSingleInstance())
{
- MessageBox(NULL, L"Another instance is already running.", L"Error", MB_OK | MB_ICONERROR);
- return EXIT_FAILURE;
+ // Try to activate the existing window instead of showing an error
+ ActivateExistingWindow();
+ return EXIT_SUCCESS;
}
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.