搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.0

windows_single_instance

強制您的 Windows 應用程式僅有一個實例,當開啟新實例時,將現有視窗置於最前面。

Windows
近 30 天下載
2.2萬
喜歡數
54
Pub 分數
150

安裝套件

flutter pub add windows_single_instance

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

windows_single_instance 套件確保在 Windows 上同時只有一個 Flutter 應用程式實例運行。當啟動第二個實例時,它會偵測到現有的進程,並將原始視窗置於最前,而不是建立新的視窗。這種行為透過防止重複應用視窗並維持對活躍實例的焦點,改善了使用者體驗。該套件與 Flutter 的桌面平台無縫整合,除了新增相依性外,不需要額外設定。

適用情境

  • 防止重複的應用視窗
  • 改進 Windows 上的使用者工作流程
  • 確保單個活動實例
  • 處理從捷徑啟動應用
  • 管理後台進程

主要特色

  • 重新啟動時自動聚焦視窗
  • 跨進程檢測
  • 最小設定
  • 僅支援 Windows
  • 無外部依賴

適合對象

  • 桌面 Windows 應用
  • 單窗口應用程式
  • 面向使用者的工具
  • 需要專注互動的工具
  • 具有持久狀態的應用程式

使用建議

  • 僅限 Windows 平台
  • 需要正確初始化
  • 可能與其他單實例解決方案衝突
  • 不適用於多實例工作流程
  • 未妥善處理應用關閉

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Windows Single Instance

Restrict a Windows app to only be able to open one instance at a time.

Installing

  1. Add WidgetsFlutterBinding.ensureInitialized(); to the start of your apps main function.
  2. Add the async modifier to your apps main function.
  3. Add a call to WindowsSingleInstance.ensureSingleInstance(), passing the apps startup args, a custom app string unique to your app (a-z, 0-9, _ and - only), and an optional callback function.

Example

void main(List<String> args) async {
    WidgetsFlutterBinding.ensureInitialized();
    await WindowsSingleInstance.ensureSingleInstance(
        args,
        "custom_identifier",
        onSecondWindow: (args) {
            print(args);
        });
    runApp(const MyApp());
}

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案