diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a64bd8..be6fb77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,8 +30,10 @@ jobs: - name: Install dependencies run: | + sudo apt-get update + # For FastForge - sudo apt install locate + sudo apt-get install locate wget -O appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage" chmod +x appimagetool mv appimagetool /usr/local/bin/ diff --git a/lib/application/objectbox.dart b/lib/application/objectbox.dart index 7c9f25c..2084f5c 100644 --- a/lib/application/objectbox.dart +++ b/lib/application/objectbox.dart @@ -43,8 +43,8 @@ class ObjectBox { return path.join(snapUserData, 'scrcpy_buddy'); } else { // Not running as snap, use default location - final docsDir = await getApplicationDocumentsDirectory(); - return path.join(docsDir.path, "scrcpy_buddy"); + final dir = await getApplicationSupportDirectory(); + return path.join(dir.path, "scrcpy_buddy_db"); } } } diff --git a/lib/init.dart b/lib/init.dart index 0ce37ba..ea81d7a 100644 --- a/lib/init.dart +++ b/lib/init.dart @@ -20,7 +20,9 @@ Future init() async { await flutter_acrylic.Window.setEffect(effect: flutter_acrylic.WindowEffect.acrylic); } await WindowManager.instance.ensureInitialized(); - windowManager.setPreventClose(true); + if (kReleaseMode) { + windowManager.setPreventClose(true); + } windowManager.waitUntilReadyToShow().then((_) async { await windowManager.setMinimumSize(const Size(500, 600)); await windowManager.setTitle(_appName); @@ -42,5 +44,4 @@ Future init() async { debugPrint(e.toString()); debugPrintStack(stackTrace: stack); } - } diff --git a/lib/presentation/home/console_section/widgets/console_view_widget.dart b/lib/presentation/home/console_section/widgets/console_view_widget.dart index ab2dc2d..938d99d 100644 --- a/lib/presentation/home/console_section/widgets/console_view_widget.dart +++ b/lib/presentation/home/console_section/widgets/console_view_widget.dart @@ -41,6 +41,7 @@ class _ConsoleViewWidgetState extends State { void _scrollToBottom() { try { + if (!_scrollController.hasClients) return; _scrollController.animateTo( _scrollController.position.maxScrollExtent, duration: context.theme.fasterAnimationDuration, diff --git a/lib/presentation/home/home_screen.dart b/lib/presentation/home/home_screen.dart index 1eef135..01740b1 100644 --- a/lib/presentation/home/home_screen.dart +++ b/lib/presentation/home/home_screen.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:fluent_ui/fluent_ui.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:scrcpy_buddy/application/model/scrcpy/scrcpy_error.dart'; @@ -77,7 +78,11 @@ class _HomeScreenState extends AppModuleState with WindowListener, T @override void onWindowClose() async { - windowManager.hide(); + if (kReleaseMode) { + windowManager.hide(); + } else { + _exitApp(); + } } @override diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index db44369..b762414 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -10,4 +10,18 @@ class AppDelegate: FlutterAppDelegate { override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { return true } + + // Handle opening the hidden window and restoring it upon dock icon click + override func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + if !flag { + for window in NSApp.windows { + if !window.isVisible { + window.setIsVisible(true) + } + window.makeKeyAndOrderFront(self) + NSApp.activate(ignoringOtherApps: true) + } + } + return true + } } diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index c84218f..33af3b3 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -7,6 +7,13 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { + HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"scrcpy_buddy"); + if (hwnd != NULL) { + ::ShowWindow(hwnd, SW_NORMAL); + ::SetForegroundWindow(hwnd); + return EXIT_FAILURE; + } + // Attach to console when present (e.g., 'flutter run') or create a // new console when running with a debugger. if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {