From e315bda9201af9d7c0fe1576abe3577ddf3fe78e Mon Sep 17 00:00:00 2001 From: LiJianying Date: Sun, 31 Mar 2024 17:49:30 +0800 Subject: [PATCH] chore(example): Update example for close app --- README-ZH.md | 57 ++++++++++--------- README.md | 57 ++++++++++--------- packages/auto_updater/example/lib/main.dart | 1 + .../auto_updater/example/lib/pages/home.dart | 2 + .../example/windows/runner/main.cpp | 6 ++ 5 files changed, 67 insertions(+), 56 deletions(-) diff --git a/README-ZH.md b/README-ZH.md index ab70caa..9d13b50 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -9,7 +9,7 @@ 这个插件允许 Flutter **桌面** 应用自动更新自己 (基于 [sparkle](https://sparkle-project.org/) 和 [winsparkle](https://winsparkle.com))。 - + --- @@ -20,33 +20,34 @@ -- [平台支持](#%E5%B9%B3%E5%8F%B0%E6%94%AF%E6%8C%81) -- [快速开始](#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) - - [安装](#%E5%AE%89%E8%A3%85) - - [⚠️ Windows requirements](#-windows-requirements) - - [用法](#%E7%94%A8%E6%B3%95) - - [发布你的应用](#%E5%8F%91%E5%B8%83%E4%BD%A0%E7%9A%84%E5%BA%94%E7%94%A8) - - [生成私钥](#%E7%94%9F%E6%88%90%E7%A7%81%E9%92%A5) - - [macOS](#macos) - - [Windows](#windows) - - [打包应用](#%E6%89%93%E5%8C%85%E5%BA%94%E7%94%A8) - - [macOS](#macos-1) - - [Windows](#windows-1) - - [获取签名](#%E8%8E%B7%E5%8F%96%E7%AD%BE%E5%90%8D) - - [macOS](#macos-2) - - [Windows](#windows-2) - - [分发应用](#%E5%88%86%E5%8F%91%E5%BA%94%E7%94%A8) -- [故障排除](#%E6%95%85%E9%9A%9C%E6%8E%92%E9%99%A4) - - [macOS](#macos-3) -- [谁在用使用它?](#%E8%B0%81%E5%9C%A8%E7%94%A8%E4%BD%BF%E7%94%A8%E5%AE%83) -- [API](#api) - - [AutoUpdater](#autoupdater) - - [Methods](#methods) - - [setFeedURL](#setfeedurl) - - [checkForUpdates](#checkforupdates) - - [setScheduledCheckInterval](#setscheduledcheckinterval) -- [相关链接](#%E7%9B%B8%E5%85%B3%E9%93%BE%E6%8E%A5) -- [许可证](#%E8%AE%B8%E5%8F%AF%E8%AF%81) +- [auto\_updater](#auto_updater) + - [平台支持](#平台支持) + - [快速开始](#快速开始) + - [安装](#安装) + - [⚠️ Windows requirements](#️-windows-requirements) + - [用法](#用法) + - [发布你的应用](#发布你的应用) + - [生成私钥](#生成私钥) + - [macOS](#macos) + - [Windows](#windows) + - [打包应用](#打包应用) + - [macOS](#macos-1) + - [Windows](#windows-1) + - [获取签名](#获取签名) + - [macOS](#macos-2) + - [Windows](#windows-2) + - [分发应用](#分发应用) + - [故障排除](#故障排除) + - [macOS](#macos-3) + - [谁在用使用它?](#谁在用使用它) + - [API](#api) + - [AutoUpdater](#autoupdater) + - [Methods](#methods) + - [setFeedURL](#setfeedurl) + - [checkForUpdates](#checkforupdates) + - [setScheduledCheckInterval](#setscheduledcheckinterval) + - [相关链接](#相关链接) + - [许可证](#许可证) diff --git a/README.md b/README.md index 731981e..8f7081b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This plugin allows Flutter **desktop** apps to automatically update themselves (based on [sparkle](https://sparkle-project.org/) and [winsparkle](https://winsparkle.com)). - + --- @@ -20,33 +20,34 @@ English | [简体中文](./README-ZH.md) -- [Platform Support](#platform-support) -- [Quick Start](#quick-start) - - [Installation](#installation) - - [⚠️ Windows requirements](#-windows-requirements) - - [Usage](#usage) - - [Publish your app](#publish-your-app) - - [Generate private key](#generate-private-key) - - [macOS](#macos) - - [Windows](#windows) - - [Packaging](#packaging) - - [macOS](#macos-1) - - [Windows](#windows-1) - - [Get signature](#get-signature) - - [macOS](#macos-2) - - [Windows](#windows-2) - - [Distributing](#distributing) -- [Troubleshooting](#troubleshooting) - - [macOS](#macos-3) -- [Who's using it?](#whos-using-it) -- [API](#api) - - [AutoUpdater](#autoupdater) - - [Methods](#methods) - - [setFeedURL](#setfeedurl) - - [checkForUpdates](#checkforupdates) - - [setScheduledCheckInterval](#setscheduledcheckinterval) -- [Related Links](#related-links) -- [License](#license) +- [auto\_updater](#auto_updater) + - [Platform Support](#platform-support) + - [Quick Start](#quick-start) + - [Installation](#installation) + - [⚠️ Windows requirements](#️-windows-requirements) + - [Usage](#usage) + - [Publish your app](#publish-your-app) + - [Generate private key](#generate-private-key) + - [macOS](#macos) + - [Windows](#windows) + - [Packaging](#packaging) + - [macOS](#macos-1) + - [Windows](#windows-1) + - [Get signature](#get-signature) + - [macOS](#macos-2) + - [Windows](#windows-2) + - [Distributing](#distributing) + - [Troubleshooting](#troubleshooting) + - [macOS](#macos-3) + - [Who's using it?](#whos-using-it) + - [API](#api) + - [AutoUpdater](#autoupdater) + - [Methods](#methods) + - [setFeedURL](#setfeedurl) + - [checkForUpdates](#checkforupdates) + - [setScheduledCheckInterval](#setscheduledcheckinterval) + - [Related Links](#related-links) + - [License](#license) diff --git a/packages/auto_updater/example/lib/main.dart b/packages/auto_updater/example/lib/main.dart index 98b658b..61e3d1b 100644 --- a/packages/auto_updater/example/lib/main.dart +++ b/packages/auto_updater/example/lib/main.dart @@ -8,6 +8,7 @@ void main() async { await windowManager.ensureInitialized(); windowManager.waitUntilReadyToShow(null, () async { + await windowManager.setPreventClose(true); await windowManager.show(); await windowManager.focus(); }); diff --git a/packages/auto_updater/example/lib/pages/home.dart b/packages/auto_updater/example/lib/pages/home.dart index 11ab9f6..820b940 100644 --- a/packages/auto_updater/example/lib/pages/home.dart +++ b/packages/auto_updater/example/lib/pages/home.dart @@ -3,6 +3,7 @@ import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:preference_list/preference_list.dart'; +import 'package:window_manager/window_manager.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -136,5 +137,6 @@ class _HomePageState extends State with UpdaterListener { if (kDebugMode) { print('onUpdaterBeforeQuitForUpdate: ${item?.toJson()}'); } + windowManager.setPreventClose(false); } } diff --git a/packages/auto_updater/example/windows/runner/main.cpp b/packages/auto_updater/example/windows/runner/main.cpp index 2ecd404..69fdfb3 100644 --- a/packages/auto_updater/example/windows/runner/main.cpp +++ b/packages/auto_updater/example/windows/runner/main.cpp @@ -7,6 +7,12 @@ 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"auto_updater_example"); + 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()) {