├── .clang-format ├── .github ├── FUNDING.yml └── workflows │ ├── build.yml │ ├── lint.yml │ └── test.yml ├── .gitignore ├── LICENSE ├── README-ZH.md ├── README.md ├── melos.yaml ├── packages ├── hotkey_manager │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README-ZH.md │ ├── README.md │ ├── analysis_options.yaml │ ├── dart_dependency_validator.yaml │ ├── example │ │ ├── .gitignore │ │ ├── .metadata │ │ ├── README.md │ │ ├── analysis_options.yaml │ │ ├── lib │ │ │ ├── main.dart │ │ │ ├── pages │ │ │ │ └── home.dart │ │ │ └── widgets │ │ │ │ └── record_hotkey_dialog.dart │ │ ├── linux │ │ │ ├── .gitignore │ │ │ ├── CMakeLists.txt │ │ │ ├── flutter │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── generated_plugin_registrant.cc │ │ │ │ ├── generated_plugin_registrant.h │ │ │ │ └── generated_plugins.cmake │ │ │ ├── main.cc │ │ │ ├── my_application.cc │ │ │ └── my_application.h │ │ ├── macos │ │ │ ├── .gitignore │ │ │ ├── Flutter │ │ │ │ ├── Flutter-Debug.xcconfig │ │ │ │ ├── Flutter-Release.xcconfig │ │ │ │ └── GeneratedPluginRegistrant.swift │ │ │ ├── Podfile │ │ │ ├── Podfile.lock │ │ │ ├── Runner.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ ├── project.xcworkspace │ │ │ │ │ └── xcshareddata │ │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ │ └── xcshareddata │ │ │ │ │ └── xcschemes │ │ │ │ │ └── Runner.xcscheme │ │ │ ├── Runner.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ ├── Runner │ │ │ │ ├── AppDelegate.swift │ │ │ │ ├── Assets.xcassets │ │ │ │ │ └── AppIcon.appiconset │ │ │ │ │ │ ├── Contents.json │ │ │ │ │ │ ├── app_icon_1024.png │ │ │ │ │ │ ├── app_icon_128.png │ │ │ │ │ │ ├── app_icon_16.png │ │ │ │ │ │ ├── app_icon_256.png │ │ │ │ │ │ ├── app_icon_32.png │ │ │ │ │ │ ├── app_icon_512.png │ │ │ │ │ │ └── app_icon_64.png │ │ │ │ ├── Base.lproj │ │ │ │ │ └── MainMenu.xib │ │ │ │ ├── Configs │ │ │ │ │ ├── AppInfo.xcconfig │ │ │ │ │ ├── Debug.xcconfig │ │ │ │ │ ├── Release.xcconfig │ │ │ │ │ └── Warnings.xcconfig │ │ │ │ ├── DebugProfile.entitlements │ │ │ │ ├── Info.plist │ │ │ │ ├── MainFlutterWindow.swift │ │ │ │ └── Release.entitlements │ │ │ └── RunnerTests │ │ │ │ └── RunnerTests.swift │ │ ├── pubspec.yaml │ │ ├── web │ │ │ ├── favicon.png │ │ │ ├── icons │ │ │ │ ├── Icon-192.png │ │ │ │ ├── Icon-512.png │ │ │ │ ├── Icon-maskable-192.png │ │ │ │ └── Icon-maskable-512.png │ │ │ ├── index.html │ │ │ └── manifest.json │ │ └── windows │ │ │ ├── .gitignore │ │ │ ├── CMakeLists.txt │ │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ ├── generated_plugin_registrant.cc │ │ │ ├── generated_plugin_registrant.h │ │ │ └── generated_plugins.cmake │ │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── Runner.rc │ │ │ ├── flutter_window.cpp │ │ │ ├── flutter_window.h │ │ │ ├── main.cpp │ │ │ ├── resource.h │ │ │ ├── resources │ │ │ └── app_icon.ico │ │ │ ├── runner.exe.manifest │ │ │ ├── utils.cpp │ │ │ ├── utils.h │ │ │ ├── win32_window.cpp │ │ │ └── win32_window.h │ ├── lib │ │ ├── hotkey_manager.dart │ │ └── src │ │ │ ├── hotkey_manager.dart │ │ │ └── widgets │ │ │ ├── global_shortcuts.dart │ │ │ ├── hotkey_recorder.dart │ │ │ └── hotkey_virtual_view.dart │ └── pubspec.yaml ├── hotkey_manager_linux │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── linux │ │ ├── CMakeLists.txt │ │ ├── hotkey_manager_linux_plugin.cc │ │ ├── hotkey_manager_linux_plugin_private.h │ │ ├── include │ │ │ └── hotkey_manager_linux │ │ │ │ └── hotkey_manager_linux_plugin.h │ │ └── test │ │ │ └── hotkey_manager_linux_plugin_test.cc │ └── pubspec.yaml ├── hotkey_manager_macos │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── macos │ │ ├── Classes │ │ │ ├── HotKeyExtension+NSEventModifierFlags.swift │ │ │ └── HotkeyManagerMacosPlugin.swift │ │ └── hotkey_manager_macos.podspec │ └── pubspec.yaml ├── hotkey_manager_platform_interface │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ ├── hotkey_manager_platform_interface.dart │ │ └── src │ │ │ ├── enums │ │ │ ├── key_code.dart │ │ │ └── key_modifier.dart │ │ │ ├── extensions │ │ │ └── keyboard_key.dart │ │ │ ├── hotkey.dart │ │ │ ├── hotkey.g.dart │ │ │ ├── hotkey_manager_method_channel.dart │ │ │ └── hotkey_manager_platform_interface.dart │ ├── pubspec.yaml │ └── test │ │ └── src │ │ ├── hotkey_manager_method_channel_test.dart │ │ └── hotkey_test.dart └── hotkey_manager_windows │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── pubspec.yaml │ └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── hotkey_manager_windows_plugin.cpp │ ├── hotkey_manager_windows_plugin.h │ ├── hotkey_manager_windows_plugin_c_api.cpp │ ├── include │ └── hotkey_manager_windows │ │ └── hotkey_manager_windows_plugin_c_api.h │ └── test │ └── hotkey_manager_windows_plugin_test.cpp └── pubspec.yaml /.clang-format: -------------------------------------------------------------------------------- 1 | # Defines the Chromium style for automatic reformatting. 2 | # http://clang.llvm.org/docs/ClangFormatStyleOptions.html 3 | BasedOnStyle: Chromium 4 | # This defaults to 'Auto'. Explicitly set it for a while, so that 5 | # 'vector >' in existing files gets formatted to 6 | # 'vector>'. ('Auto' means that clang-format will only use 7 | # 'int>>' if the file already contains at least one such instance.) 8 | Standard: Cpp11 9 | SortIncludes: true 10 | --- 11 | Language: ObjC 12 | ColumnLimit: 100 13 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | liberapay: lijy91 2 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [main, dev] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | build-linux: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: subosito/flutter-action@v2 15 | with: 16 | flutter-version: "3.19.2" 17 | channel: "stable" 18 | - run: | 19 | sudo apt-get update 20 | sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev 21 | sudo apt-get install -y keybinder-3.0 22 | - uses: bluefireteam/melos-action@v3 23 | - working-directory: ./packages/hotkey_manager/example 24 | run: | 25 | flutter build linux --release 26 | 27 | build-macos: 28 | runs-on: macos-latest 29 | steps: 30 | - uses: actions/checkout@v3 31 | - uses: subosito/flutter-action@v2 32 | with: 33 | flutter-version: "3.19.2" 34 | channel: "stable" 35 | - uses: bluefireteam/melos-action@v3 36 | - working-directory: ./packages/hotkey_manager/example 37 | run: | 38 | flutter build macos --release 39 | 40 | build-web: 41 | runs-on: macos-latest 42 | steps: 43 | - uses: actions/checkout@v3 44 | - uses: subosito/flutter-action@v2 45 | with: 46 | flutter-version: "3.19.2" 47 | channel: "stable" 48 | - uses: bluefireteam/melos-action@v3 49 | - working-directory: ./packages/hotkey_manager/example 50 | run: | 51 | flutter build web --release 52 | 53 | build-windows: 54 | runs-on: windows-latest 55 | steps: 56 | - uses: actions/checkout@v3 57 | - uses: subosito/flutter-action@v2 58 | with: 59 | flutter-version: "3.19.2" 60 | channel: "stable" 61 | - uses: bluefireteam/melos-action@v3 62 | - working-directory: ./packages/hotkey_manager/example 63 | run: | 64 | flutter build windows --release 65 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | push: 5 | branches: [main, dev] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | analyze: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: subosito/flutter-action@v2 15 | with: 16 | flutter-version: "3.19.2" 17 | channel: "stable" 18 | - uses: bluefireteam/melos-action@v3 19 | - run: melos run analyze 20 | 21 | format: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v3 25 | - uses: subosito/flutter-action@v2 26 | with: 27 | flutter-version: "3.19.2" 28 | channel: "stable" 29 | cache: true 30 | - uses: bluefireteam/melos-action@v3 31 | - run: melos run format-check 32 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: [main, dev] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: subosito/flutter-action@v2 15 | with: 16 | flutter-version: "3.19.2" 17 | channel: "stable" 18 | cache: true 19 | - uses: bluefireteam/melos-action@v3 20 | - run: melos run test --no-select 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .idea/ 3 | 4 | *.iml 5 | pubspec_overrides.yaml 6 | pubspec.lock 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README-ZH.md: -------------------------------------------------------------------------------- 1 | > **🚀 快速发布您的应用**: 试试 [Fastforge](https://fastforge.dev) - 构建、打包和分发您的 Flutter 应用最简单的方式。 2 | 3 | # hotkey_manager 4 | 5 | [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager.svg 8 | [pub-url]: https://pub.dev/packages/hotkey_manager 9 | 10 | [discord-image]: https://img.shields.io/discord/884679008049037342.svg 11 | [discord-url]: https://discord.gg/zPa6EZ2jqb 12 | 13 | [visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.hotkey_manager/visits 14 | 15 | 这个插件允许 Flutter 桌面应用定义系统/应用范围内的热键(即快捷键)。 16 | 17 | --- 18 | 19 | [English](./README.md) | 简体中文 20 | 21 | --- 22 | 23 | 24 | 25 | 26 | - [hotkey_manager](#hotkey_manager) 27 | - [平台支持](#平台支持) 28 | - [快速开始](#快速开始) 29 | - [安装](#安装) 30 | - [Linux requirements](#linux-requirements) 31 | - [用法](#用法) 32 | - [谁在用使用它?](#谁在用使用它) 33 | - [API](#api) 34 | - [HotKeyManager](#hotkeymanager) 35 | - [相关链接](#相关链接) 36 | - [许可证](#许可证) 37 | 38 | 39 | 40 | ## 平台支持 41 | 42 | | Linux | macOS | Windows | 43 | | :---: | :---: | :-----: | 44 | | ✔️ | ✔️ | ✔️ | 45 | 46 | ## 快速开始 47 | 48 | ### 安装 49 | 50 | 将此添加到你的软件包的 pubspec.yaml 文件: 51 | 52 | ```yaml 53 | dependencies: 54 | hotkey_manager: ^0.2.3 55 | ``` 56 | 57 | 或 58 | 59 | ```yaml 60 | dependencies: 61 | hotkey_manager: 62 | git: 63 | path: packages/hotkey_manager 64 | url: https://github.com/leanflutter/hotkey_manager.git 65 | ref: main 66 | ``` 67 | 68 | #### Linux requirements 69 | 70 | - [`keybinder-3.0`](https://github.com/kupferlauncher/keybinder) 71 | 72 | 运行以下命令 73 | 74 | ``` 75 | sudo apt-get install keybinder-3.0 76 | ``` 77 | 78 | ### 用法 79 | 80 | ```dart 81 | import 'package:hotkey_manager/hotkey_manager.dart'; 82 | 83 | void main() async { 84 | // 必须加上这一行。 85 | WidgetsFlutterBinding.ensureInitialized(); 86 | // 对于热重载,`unregisterAll()` 需要被调用。 87 | await hotKeyManager.unregisterAll(); 88 | 89 | runApp(MyApp()); 90 | } 91 | ``` 92 | 93 | 注册/卸载一个系统/应用范围的热键。 94 | 95 | ```dart 96 | // ⌥ + Q 97 | HotKey _hotKey = HotKey( 98 | key: PhysicalKeyboardKey.keyQ, 99 | modifiers: [HotKeyModifier.alt], 100 | // 设置热键范围(默认为 HotKeyScope.system) 101 | scope: HotKeyScope.inapp, // 设置为应用范围的热键。 102 | ); 103 | await hotKeyManager.register( 104 | _hotKey, 105 | keyDownHandler: (hotKey) { 106 | print('onKeyDown+${hotKey.toJson()}'); 107 | }, 108 | // 只在 macOS 上工作。 109 | keyUpHandler: (hotKey){ 110 | print('onKeyUp+${hotKey.toJson()}'); 111 | } , 112 | ); 113 | 114 | await hotKeyManager.unregister(_hotKey); 115 | 116 | await hotKeyManager.unregisterAll(); 117 | ``` 118 | 119 | 使用 `HotKeyRecorder` 小部件帮助您录制一个热键。 120 | 121 | ```dart 122 | HotKeyRecorder( 123 | onHotKeyRecorded: (hotKey) { 124 | _hotKey = hotKey; 125 | setState(() {}); 126 | }, 127 | ), 128 | ``` 129 | 130 | > 请看这个插件的示例应用,以了解完整的例子。 131 | 132 | ## 谁在用使用它? 133 | 134 | - [Airclap](https://airclap.app/) - 任何文件,任意设备,随意发送。简单好用的跨平台高速文件传输APP。 135 | - [AuthPass](https://authpass.app/) - 基于Flutter的密码管理器,适用于所有平台。兼容Keepass 2.x(kdbx 3.x)。 136 | - [Biyi (比译)](https://biyidev.com/) - 一个便捷的翻译和词典应用程序。 137 | 138 | ## API 139 | 140 | ### HotKeyManager 141 | 142 | | Method | Description | Linux | macOS | Windows | 143 | | ------------- | --------------------------------- | ----- | ----- | ------- | 144 | | register | 注册一个系统/应用范围的热键。 | ✔️ | ✔️ | ✔️ | 145 | | unregister | 取消注册一个系统/应用范围的热键。 | ✔️ | ✔️ | ✔️ | 146 | | unregisterAll | 取消注册全部系统/应用范围的热键。 | ✔️ | ✔️ | ✔️ | 147 | 148 | ## 相关链接 149 | 150 | - https://github.com/soffes/HotKey 151 | - https://github.com/kupferlauncher/keybinder 152 | 153 | ## 许可证 154 | 155 | [MIT](./LICENSE) 156 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **🚀 Ship Your App Faster**: Try [Fastforge](https://fastforge.dev) - The simplest way to build, package and distribute your Flutter apps. 2 | 3 | # hotkey_manager 4 | 5 | [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager.svg 8 | [pub-url]: https://pub.dev/packages/hotkey_manager 9 | 10 | [discord-image]: https://img.shields.io/discord/884679008049037342.svg 11 | [discord-url]: https://discord.gg/zPa6EZ2jqb 12 | 13 | [visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.hotkey_manager/visits 14 | 15 | This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut). 16 | 17 | --- 18 | 19 | English | [简体中文](./README-ZH.md) 20 | 21 | --- 22 | 23 | 24 | 25 | 26 | - [hotkey_manager](#hotkey_manager) 27 | - [Platform Support](#platform-support) 28 | - [Quick Start](#quick-start) 29 | - [Installation](#installation) 30 | - [Linux requirements](#linux-requirements) 31 | - [Usage](#usage) 32 | - [Who's using it?](#whos-using-it) 33 | - [API](#api) 34 | - [HotKeyManager](#hotkeymanager) 35 | - [Related Links](#related-links) 36 | - [License](#license) 37 | 38 | 39 | 40 | ## Platform Support 41 | 42 | | Linux | macOS | Windows | 43 | | :---: | :---: | :-----: | 44 | | ✔️ | ✔️ | ✔️ | 45 | 46 | ## Quick Start 47 | 48 | ### Installation 49 | 50 | Add this to your package's pubspec.yaml file: 51 | 52 | ```yaml 53 | dependencies: 54 | hotkey_manager: ^0.2.3 55 | ``` 56 | 57 | Or 58 | 59 | ```yaml 60 | dependencies: 61 | hotkey_manager: 62 | git: 63 | path: packages/hotkey_manager 64 | url: https://github.com/leanflutter/hotkey_manager.git 65 | ref: main 66 | ``` 67 | 68 | #### Linux requirements 69 | 70 | - [`keybinder-3.0`](https://github.com/kupferlauncher/keybinder) 71 | 72 | Run the following command 73 | 74 | ``` 75 | sudo apt-get install keybinder-3.0 76 | ``` 77 | 78 | ### Usage 79 | 80 | ```dart 81 | import 'package:hotkey_manager/hotkey_manager.dart'; 82 | 83 | void main() async { 84 | // Must add this line. 85 | WidgetsFlutterBinding.ensureInitialized(); 86 | // For hot reload, `unregisterAll()` needs to be called. 87 | await hotKeyManager.unregisterAll(); 88 | 89 | runApp(MyApp()); 90 | } 91 | ``` 92 | 93 | Register/Unregsiter a system/inapp wide hotkey. 94 | 95 | ```dart 96 | // ⌥ + Q 97 | HotKey _hotKey = HotKey( 98 | key: PhysicalKeyboardKey.keyQ, 99 | modifiers: [HotKeyModifier.alt], 100 | // Set hotkey scope (default is HotKeyScope.system) 101 | scope: HotKeyScope.inapp, // Set as inapp-wide hotkey. 102 | ); 103 | await hotKeyManager.register( 104 | _hotKey, 105 | keyDownHandler: (hotKey) { 106 | print('onKeyDown+${hotKey.toJson()}'); 107 | }, 108 | // Only works on macOS. 109 | keyUpHandler: (hotKey){ 110 | print('onKeyUp+${hotKey.toJson()}'); 111 | } , 112 | ); 113 | 114 | await hotKeyManager.unregister(_hotKey); 115 | 116 | await hotKeyManager.unregisterAll(); 117 | ``` 118 | 119 | Use `HotKeyRecorder` widget to help you record a hotkey. 120 | 121 | ```dart 122 | HotKeyRecorder( 123 | onHotKeyRecorded: (hotKey) { 124 | _hotKey = hotKey; 125 | setState(() {}); 126 | }, 127 | ), 128 | ``` 129 | 130 | > Please see the example app of this plugin for a full example. 131 | 132 | ## Who's using it? 133 | 134 | - [Airclap](https://airclap.app/) - Send any file to any device. cross platform, ultra fast and easy to use. 135 | - [AuthPass](https://authpass.app/) - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible. 136 | - [Biyi (比译)](https://biyidev.com/) - A convenient translation and dictionary app. 137 | 138 | ## API 139 | 140 | ### HotKeyManager 141 | 142 | | Method | Description | Linux | macOS | Windows | 143 | | ------------- | ----------------------------------------- | ----- | ----- | ------- | 144 | | register | register an system/inapp wide hotkey. | ✔️ | ✔️ | ✔️ | 145 | | unregister | unregister an system/inapp wide hotkey. | ✔️ | ✔️ | ✔️ | 146 | | unregisterAll | unregister all system/inapp wide hotkeys. | ✔️ | ✔️ | ✔️ | 147 | 148 | ## Related Links 149 | 150 | - https://github.com/soffes/HotKey 151 | - https://github.com/kupferlauncher/keybinder 152 | 153 | ## License 154 | 155 | [MIT](./LICENSE) 156 | -------------------------------------------------------------------------------- /melos.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_workspace 2 | repository: https://github.com/leanflutter/hotkey_manager 3 | 4 | packages: 5 | - examples/** 6 | - packages/** 7 | 8 | command: 9 | bootstrap: 10 | # Uses the pubspec_overrides.yaml instead of having Melos modifying the lock file. 11 | usePubspecOverrides: true 12 | 13 | scripts: 14 | analyze: 15 | exec: flutter analyze --fatal-infos 16 | description: Run `flutter analyze` for all packages. 17 | 18 | test: 19 | exec: flutter test 20 | description: Run `flutter test` for a specific package. 21 | packageFilters: 22 | dirExists: 23 | - test 24 | 25 | format: 26 | exec: dart format . --fix 27 | description: Run `dart format` for all packages. 28 | 29 | format-check: 30 | exec: dart format . --fix --set-exit-if-changed 31 | description: Run `dart format` checks for all packages. 32 | 33 | fix: 34 | exec: dart fix . --apply 35 | description: Run `dart fix` for all packages. 36 | -------------------------------------------------------------------------------- /packages/hotkey_manager/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | .packages 30 | build/ 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: f4abaa0735eba4dfd8f33f73363911d63931fe03 8 | channel: stable 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /packages/hotkey_manager/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.3 2 | 3 | * bug fix that multi eventHandler does not fire (#53) 4 | 5 | ## 0.2.2 6 | 7 | * feat: Add `CallbackGlobalShortcuts` and `GlobalShortcuts` Widgets. 8 | 9 | ## 0.2.1 10 | 11 | * Fixed issue where modifiers do not work #50 12 | 13 | ## 0.2.0 14 | 15 | * feat: Convert to federated plugin 16 | * feat: Use flutter built-in keymap (provided through the `uni_platform` package) 17 | * chore: Use `HardwareKeyboard` to replace the `RawKeyboard` api 18 | * bump flutter to 3.19.2 19 | * fix: crash if toString called with null modifiers (#25) 20 | * Update dependencies & add three keys (#28) 21 | 22 | ## 0.1.7 23 | 24 | * Fixed inapp hotkeys key down event repeat triggering #9 25 | * Fixed inapp hotkeys not matching correctly #11 26 | 27 | ## 0.1.6 28 | 29 | * Fixed `KeyModifierParser.fromModifierKey` Return type. 30 | 31 | ## 0.1.5 32 | 33 | * [windows] Fix escape key mapping error 34 | * [linux] Supplemental key map 35 | 36 | ## 0.1.4 37 | 38 | * export `hotKeyManager`. 39 | 40 | ## 0.1.3 41 | 42 | * `HotKeyVirtualView` Support dark Theme Mode. 43 | 44 | ## 0.1.2 45 | 46 | * Remove web platform implementation 47 | 48 | ## 0.1.1 49 | 50 | * Add `unregisterAll` Method. 51 | 52 | ## 0.1.0 53 | 54 | * Supported Hot Reload. 55 | * #2 Fixed `No element` error. 56 | 57 | ## 0.0.6 58 | 59 | * [linux] Add #include to hotkey_manager_plugin.cc 60 | 61 | ## 0.0.5 62 | 63 | * Supported `linux` platform. 64 | 65 | ## 0.0.4 66 | 67 | * Supported `web` platform, Embed via iframe. 68 | * Adapt flutter master channel. 69 | 70 | ## 0.0.3 71 | 72 | * Supported `windows` platform. 73 | 74 | ## 0.0.2 75 | 76 | * Supported inapp-wide hotkey. 77 | * Add `HotKeyVirtualView`, `HotKeyRecorder` Widgets. 78 | 79 | ## 0.0.1 80 | 81 | * first release. 82 | -------------------------------------------------------------------------------- /packages/hotkey_manager/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/hotkey_manager/README-ZH.md: -------------------------------------------------------------------------------- 1 | ../../README-ZH.md -------------------------------------------------------------------------------- /packages/hotkey_manager/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /packages/hotkey_manager/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager/dart_dependency_validator.yaml: -------------------------------------------------------------------------------- 1 | exclude: 2 | - "example/**" 3 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .build/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | .swiftpm/ 13 | migrate_working_dir/ 14 | 15 | # IntelliJ related 16 | *.iml 17 | *.ipr 18 | *.iws 19 | .idea/ 20 | 21 | # The .vscode folder contains launch configuration and tasks you configure in 22 | # VS Code which you may wish to be included in version control, so this line 23 | # is commented out by default. 24 | #.vscode/ 25 | 26 | # Flutter/Dart/Pub related 27 | **/doc/api/ 28 | **/ios/Flutter/.last_build_id 29 | .dart_tool/ 30 | .flutter-plugins 31 | .flutter-plugins-dependencies 32 | .packages 33 | .pub-cache/ 34 | .pub/ 35 | /build/ 36 | 37 | # Web related 38 | 39 | # Symbolication related 40 | app.*.symbols 41 | 42 | # Obfuscation related 43 | app.*.map.json 44 | 45 | # Android Studio will place build artifacts here 46 | /android/app/debug 47 | /android/app/profile 48 | /android/app/release 49 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4" 8 | channel: "stable" 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 17 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 18 | - platform: windows 19 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 20 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/README.md: -------------------------------------------------------------------------------- 1 | # hotkey_manager_example 2 | 3 | Demonstrates how to use the hotkey_manager plugin. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:bot_toast/bot_toast.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:hotkey_manager/hotkey_manager.dart'; 4 | import 'package:hotkey_manager_example/pages/home.dart'; 5 | 6 | void main() async { 7 | WidgetsFlutterBinding.ensureInitialized(); 8 | 9 | await hotKeyManager.unregisterAll(); 10 | 11 | runApp(const MyApp()); 12 | } 13 | 14 | class MyApp extends StatefulWidget { 15 | const MyApp({super.key}); 16 | 17 | @override 18 | State createState() => _MyAppState(); 19 | } 20 | 21 | class _MyAppState extends State { 22 | @override 23 | Widget build(BuildContext context) { 24 | return MaterialApp( 25 | theme: ThemeData( 26 | primaryColor: const Color(0xff416ff4), 27 | canvasColor: Colors.white, 28 | scaffoldBackgroundColor: const Color(0xffF7F9FB), 29 | dividerColor: Colors.grey.withOpacity(0.3), 30 | ), 31 | builder: BotToastInit(), 32 | navigatorObservers: [BotToastNavigatorObserver()], 33 | home: const HomePage(), 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/lib/pages/home.dart: -------------------------------------------------------------------------------- 1 | import 'package:bot_toast/bot_toast.dart'; 2 | import 'package:flutter/cupertino.dart'; 3 | import 'package:flutter/foundation.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter/services.dart'; 6 | import 'package:hotkey_manager/hotkey_manager.dart'; 7 | import 'package:hotkey_manager_example/widgets/record_hotkey_dialog.dart'; 8 | 9 | class ExampleIntent extends Intent {} 10 | 11 | class ExampleAction extends Action { 12 | @override 13 | void invoke(covariant ExampleIntent intent) { 14 | BotToast.showText(text: 'ExampleAction invoked'); 15 | } 16 | } 17 | 18 | class HomePage extends StatefulWidget { 19 | const HomePage({super.key}); 20 | 21 | @override 22 | State createState() => _HomePageState(); 23 | } 24 | 25 | class _HomePageState extends State { 26 | List _registeredHotKeyList = []; 27 | 28 | void _keyDownHandler(HotKey hotKey) { 29 | String log = 'keyDown ${hotKey.debugName} (${hotKey.scope})'; 30 | BotToast.showText(text: log); 31 | if (kDebugMode) { 32 | print(log); 33 | } 34 | } 35 | 36 | void _keyUpHandler(HotKey hotKey) { 37 | String log = 'keyUp ${hotKey.debugName} (${hotKey.scope})'; 38 | BotToast.showText(text: log); 39 | if (kDebugMode) { 40 | print(log); 41 | } 42 | } 43 | 44 | Future _handleHotKeyRegister(HotKey hotKey) async { 45 | await hotKeyManager.register( 46 | hotKey, 47 | keyDownHandler: _keyDownHandler, 48 | keyUpHandler: _keyUpHandler, 49 | ); 50 | setState(() { 51 | _registeredHotKeyList = hotKeyManager.registeredHotKeyList; 52 | }); 53 | } 54 | 55 | Future _handleHotKeyUnregister(HotKey hotKey) async { 56 | await hotKeyManager.unregister(hotKey); 57 | setState(() { 58 | _registeredHotKeyList = hotKeyManager.registeredHotKeyList; 59 | }); 60 | } 61 | 62 | Future _handleClickRegisterNewHotKey() async { 63 | return showDialog( 64 | context: context, 65 | barrierDismissible: false, 66 | builder: (BuildContext context) { 67 | return RecordHotKeyDialog( 68 | onHotKeyRecorded: (newHotKey) => _handleHotKeyRegister(newHotKey), 69 | ); 70 | }, 71 | ); 72 | } 73 | 74 | Widget _buildBody(BuildContext context) { 75 | return ListView( 76 | children: [ 77 | const Text('REGISTERED HOTKEY LIST'), 78 | for (var registeredHotKey in _registeredHotKeyList) 79 | ListTile( 80 | title: Row( 81 | mainAxisSize: MainAxisSize.min, 82 | children: [ 83 | HotKeyVirtualView(hotKey: registeredHotKey), 84 | const SizedBox(width: 10), 85 | Text( 86 | registeredHotKey.scope.toString(), 87 | style: const TextStyle( 88 | color: Colors.grey, 89 | fontSize: 12, 90 | ), 91 | ), 92 | ], 93 | ), 94 | trailing: SizedBox( 95 | width: 40, 96 | height: 40, 97 | child: CupertinoButton( 98 | padding: EdgeInsets.zero, 99 | child: const Stack( 100 | alignment: Alignment.center, 101 | children: [ 102 | Icon( 103 | CupertinoIcons.delete, 104 | size: 18, 105 | color: Colors.red, 106 | ), 107 | ], 108 | ), 109 | onPressed: () => _handleHotKeyUnregister(registeredHotKey), 110 | ), 111 | ), 112 | ), 113 | ListTile( 114 | title: const Text( 115 | 'Register a new HotKey', 116 | ), 117 | onTap: () { 118 | _handleClickRegisterNewHotKey(); 119 | }, 120 | ), 121 | ListTile( 122 | title: const Text( 123 | 'Unregister all HotKeys', 124 | ), 125 | onTap: () async { 126 | await hotKeyManager.unregisterAll(); 127 | _registeredHotKeyList = hotKeyManager.registeredHotKeyList; 128 | setState(() {}); 129 | }, 130 | ), 131 | ], 132 | ); 133 | } 134 | 135 | Widget _build(BuildContext context) { 136 | return Scaffold( 137 | appBar: AppBar( 138 | title: const Text('Example'), 139 | ), 140 | body: Column( 141 | children: [ 142 | Expanded( 143 | child: _buildBody(context), 144 | ), 145 | ], 146 | ), 147 | ); 148 | } 149 | 150 | @override 151 | Widget build(BuildContext context) { 152 | return Actions( 153 | actions: >{ 154 | ExampleIntent: ExampleAction(), 155 | }, 156 | child: GlobalShortcuts( 157 | shortcuts: { 158 | const SingleActivator(LogicalKeyboardKey.keyA, alt: true): 159 | ExampleIntent(), 160 | }, 161 | child: _build(context), 162 | ), 163 | ); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/lib/widgets/record_hotkey_dialog.dart: -------------------------------------------------------------------------------- 1 | import 'package:bot_toast/bot_toast.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:hotkey_manager/hotkey_manager.dart'; 4 | 5 | class RecordHotKeyDialog extends StatefulWidget { 6 | const RecordHotKeyDialog({ 7 | super.key, 8 | required this.onHotKeyRecorded, 9 | }); 10 | 11 | final ValueChanged onHotKeyRecorded; 12 | 13 | @override 14 | State createState() => _RecordHotKeyDialogState(); 15 | } 16 | 17 | class _RecordHotKeyDialogState extends State { 18 | HotKey? _hotKey; 19 | 20 | void _handleSetAsInappWideChanged(bool newValue) { 21 | if (_hotKey == null) { 22 | BotToast.showText(text: 'Please record a hotkey first.'); 23 | return; 24 | } 25 | _hotKey = HotKey( 26 | key: _hotKey!.key, 27 | modifiers: _hotKey?.modifiers, 28 | scope: newValue ? HotKeyScope.inapp : HotKeyScope.system, 29 | ); 30 | setState(() {}); 31 | } 32 | 33 | @override 34 | Widget build(BuildContext context) { 35 | return AlertDialog( 36 | content: SingleChildScrollView( 37 | child: ListBody( 38 | children: [ 39 | const Text('The `HotKeyRecorder` widget will record your hotkey.'), 40 | Container( 41 | width: 100, 42 | height: 60, 43 | margin: const EdgeInsets.only(top: 20), 44 | decoration: BoxDecoration( 45 | border: Border.all( 46 | color: Theme.of(context).primaryColor, 47 | ), 48 | ), 49 | child: Stack( 50 | alignment: Alignment.center, 51 | children: [ 52 | HotKeyRecorder( 53 | onHotKeyRecorded: (hotKey) { 54 | _hotKey = hotKey; 55 | setState(() {}); 56 | }, 57 | ), 58 | ], 59 | ), 60 | ), 61 | GestureDetector( 62 | onTap: () { 63 | _handleSetAsInappWideChanged( 64 | _hotKey?.scope != HotKeyScope.inapp, 65 | ); 66 | }, 67 | child: Row( 68 | children: [ 69 | Checkbox( 70 | value: _hotKey?.scope == HotKeyScope.inapp, 71 | onChanged: (newValue) { 72 | _handleSetAsInappWideChanged(newValue!); 73 | }, 74 | ), 75 | const Text( 76 | 'Set as inapp-wide hotkey. (default is system-wide)', 77 | ), 78 | ], 79 | ), 80 | ), 81 | ], 82 | ), 83 | ), 84 | actions: [ 85 | TextButton( 86 | child: const Text('Cancel'), 87 | onPressed: () { 88 | Navigator.of(context).pop(); 89 | }, 90 | ), 91 | TextButton( 92 | onPressed: _hotKey == null 93 | ? null 94 | : () { 95 | widget.onHotKeyRecorded(_hotKey!); 96 | Navigator.of(context).pop(); 97 | }, 98 | child: const Text('OK'), 99 | ), 100 | ], 101 | ); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(runner LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "hotkey_manager_example") 5 | set(APPLICATION_ID "com.example.hotkey_manager") 6 | 7 | cmake_policy(SET CMP0063 NEW) 8 | 9 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 10 | 11 | # Root filesystem for cross-building. 12 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 13 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 14 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 19 | endif() 20 | 21 | # Configure build options. 22 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 23 | set(CMAKE_BUILD_TYPE "Debug" CACHE 24 | STRING "Flutter build mode" FORCE) 25 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 26 | "Debug" "Profile" "Release") 27 | endif() 28 | 29 | # Compilation settings that should be applied to most targets. 30 | function(APPLY_STANDARD_SETTINGS TARGET) 31 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 32 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 33 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 34 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 35 | endfunction() 36 | 37 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 38 | 39 | # Flutter library and tool build rules. 40 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 41 | 42 | # System-level dependencies. 43 | find_package(PkgConfig REQUIRED) 44 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 45 | 46 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 47 | 48 | # Application build 49 | add_executable(${BINARY_NAME} 50 | "main.cc" 51 | "my_application.cc" 52 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 53 | ) 54 | apply_standard_settings(${BINARY_NAME}) 55 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 56 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 57 | add_dependencies(${BINARY_NAME} flutter_assemble) 58 | # Only the install-generated bundle's copy of the executable will launch 59 | # correctly, since the resources must in the right relative locations. To avoid 60 | # people trying to run the unbundled copy, put it in a subdirectory instead of 61 | # the default top-level location. 62 | set_target_properties(${BINARY_NAME} 63 | PROPERTIES 64 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 65 | ) 66 | 67 | # Generated plugin build rules, which manage building the plugins and adding 68 | # them to the application. 69 | include(flutter/generated_plugins.cmake) 70 | 71 | 72 | # === Installation === 73 | # By default, "installing" just makes a relocatable bundle in the build 74 | # directory. 75 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 76 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 77 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 78 | endif() 79 | 80 | # Start with a clean build bundle directory every time. 81 | install(CODE " 82 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 83 | " COMPONENT Runtime) 84 | 85 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 86 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 87 | 88 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 89 | COMPONENT Runtime) 90 | 91 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 92 | COMPONENT Runtime) 93 | 94 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 95 | COMPONENT Runtime) 96 | 97 | if(PLUGIN_BUNDLED_LIBRARIES) 98 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 99 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 100 | COMPONENT Runtime) 101 | endif() 102 | 103 | # Fully re-copy the assets directory on each build to avoid having stale files 104 | # from a previous install. 105 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 106 | install(CODE " 107 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 108 | " COMPONENT Runtime) 109 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 110 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 111 | 112 | # Install the AOT library on non-Debug builds only. 113 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 114 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 115 | COMPONENT Runtime) 116 | endif() 117 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 4 | 5 | # Configuration provided via flutter tool. 6 | include(${EPHEMERAL_DIR}/generated_config.cmake) 7 | 8 | # TODO: Move the rest of this into files in ephemeral. See 9 | # https://github.com/flutter/flutter/issues/57146. 10 | 11 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 12 | # which isn't available in 3.10. 13 | function(list_prepend LIST_NAME PREFIX) 14 | set(NEW_LIST "") 15 | foreach(element ${${LIST_NAME}}) 16 | list(APPEND NEW_LIST "${PREFIX}${element}") 17 | endforeach(element) 18 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 19 | endfunction() 20 | 21 | # === Flutter Library === 22 | # System-level dependencies. 23 | find_package(PkgConfig REQUIRED) 24 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 25 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 26 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 27 | 28 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 29 | 30 | # Published to parent scope for install step. 31 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 32 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 33 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 34 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 35 | 36 | list(APPEND FLUTTER_LIBRARY_HEADERS 37 | "fl_basic_message_channel.h" 38 | "fl_binary_codec.h" 39 | "fl_binary_messenger.h" 40 | "fl_dart_project.h" 41 | "fl_engine.h" 42 | "fl_json_message_codec.h" 43 | "fl_json_method_codec.h" 44 | "fl_message_codec.h" 45 | "fl_method_call.h" 46 | "fl_method_channel.h" 47 | "fl_method_codec.h" 48 | "fl_method_response.h" 49 | "fl_plugin_registrar.h" 50 | "fl_plugin_registry.h" 51 | "fl_standard_message_codec.h" 52 | "fl_standard_method_codec.h" 53 | "fl_string_codec.h" 54 | "fl_value.h" 55 | "fl_view.h" 56 | "flutter_linux.h" 57 | ) 58 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 59 | add_library(flutter INTERFACE) 60 | target_include_directories(flutter INTERFACE 61 | "${EPHEMERAL_DIR}" 62 | ) 63 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 64 | target_link_libraries(flutter INTERFACE 65 | PkgConfig::GTK 66 | PkgConfig::GLIB 67 | PkgConfig::GIO 68 | ) 69 | add_dependencies(flutter flutter_assemble) 70 | 71 | # === Flutter tool backend === 72 | # _phony_ is a non-existent file to force this command to run every time, 73 | # since currently there's no way to get a full input/output list from the 74 | # flutter tool. 75 | add_custom_command( 76 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 77 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 78 | COMMAND ${CMAKE_COMMAND} -E env 79 | ${FLUTTER_TOOL_ENVIRONMENT} 80 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 81 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 82 | VERBATIM 83 | ) 84 | add_custom_target(flutter_assemble DEPENDS 85 | "${FLUTTER_LIBRARY}" 86 | ${FLUTTER_LIBRARY_HEADERS} 87 | ) 88 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void fl_register_plugins(FlPluginRegistry* registry) { 12 | g_autoptr(FlPluginRegistrar) hotkey_manager_linux_registrar = 13 | fl_plugin_registry_get_registrar_for_plugin(registry, "HotkeyManagerLinuxPlugin"); 14 | hotkey_manager_linux_plugin_register_with_registrar(hotkey_manager_linux_registrar); 15 | } 16 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | hotkey_manager_linux 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "hotkey_manager_example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "hotkey_manager_example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import hotkey_manager_macos 9 | 10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 11 | HotkeyManagerMacosPlugin.register(with: registry.registrar(forPlugin: "HotkeyManagerMacosPlugin")) 12 | } 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.15' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | target 'RunnerTests' do 35 | inherit! :search_paths 36 | end 37 | end 38 | 39 | post_install do |installer| 40 | installer.pods_project.targets.each do |target| 41 | flutter_additional_macos_build_settings(target) 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FlutterMacOS (1.0.0) 3 | - HotKey (0.2.0) 4 | - hotkey_manager_macos (0.0.1): 5 | - FlutterMacOS 6 | - HotKey 7 | 8 | DEPENDENCIES: 9 | - FlutterMacOS (from `Flutter/ephemeral`) 10 | - hotkey_manager_macos (from `Flutter/ephemeral/.symlinks/plugins/hotkey_manager_macos/macos`) 11 | 12 | SPEC REPOS: 13 | trunk: 14 | - HotKey 15 | 16 | EXTERNAL SOURCES: 17 | FlutterMacOS: 18 | :path: Flutter/ephemeral 19 | hotkey_manager_macos: 20 | :path: Flutter/ephemeral/.symlinks/plugins/hotkey_manager_macos/macos 21 | 22 | SPEC CHECKSUMS: 23 | FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1 24 | HotKey: e96d8a2ddbf4591131e2bb3f54e69554d90cdca6 25 | hotkey_manager_macos: a4317849af96d2430fa89944d3c58977ca089fbe 26 | 27 | PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3 28 | 29 | COCOAPODS: 1.16.2 30 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 64 | 66 | 72 | 73 | 74 | 75 | 81 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | 10 | override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = hotkey_manager_example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = org.leanflutter.plugins.hotkeymanagerexample 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2021-2024 LiJianying . All rights reserved. 15 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/macos/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import FlutterMacOS 2 | import Cocoa 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_example 2 | description: Demonstrates how to use the hotkey_manager plugin. 3 | publish_to: "none" 4 | 5 | environment: 6 | sdk: ">=2.18.0 <4.0.0" 7 | 8 | dependencies: 9 | bot_toast: ^4.1.3 10 | cupertino_icons: ^1.0.2 11 | flutter: 12 | sdk: flutter 13 | hotkey_manager: 14 | path: ../ 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | mostly_reasonable_lints: ^0.1.1 20 | 21 | flutter: 22 | uses-material-design: true 23 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/web/favicon.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(hotkey_manager_example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "hotkey_manager_example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(VERSION 3.14...3.25) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | 56 | # Generated plugin build rules, which manage building the plugins and adding 57 | # them to the application. 58 | include(flutter/generated_plugins.cmake) 59 | 60 | 61 | # === Installation === 62 | # Support files are copied into place next to the executable, so that it can 63 | # run in place. This is done instead of making a separate bundle (as on Linux) 64 | # so that building and running from within Visual Studio will work. 65 | set(BUILD_BUNDLE_DIR "$") 66 | # Make the "install" step default, as it's required to run. 67 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 68 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 69 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 70 | endif() 71 | 72 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 73 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 74 | 75 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 76 | COMPONENT Runtime) 77 | 78 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 79 | COMPONENT Runtime) 80 | 81 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 82 | COMPONENT Runtime) 83 | 84 | if(PLUGIN_BUNDLED_LIBRARIES) 85 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 86 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 87 | COMPONENT Runtime) 88 | endif() 89 | 90 | # Copy the native assets provided by the build.dart from all packages. 91 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") 92 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 93 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 94 | COMPONENT Runtime) 95 | 96 | # Fully re-copy the assets directory on each build to avoid having stale files 97 | # from a previous install. 98 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 99 | install(CODE " 100 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 101 | " COMPONENT Runtime) 102 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 103 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 104 | 105 | # Install the AOT library on non-Debug builds only. 106 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 107 | CONFIGURATIONS Profile;Release 108 | COMPONENT Runtime) 109 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | HotkeyManagerWindowsPluginCApiRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("HotkeyManagerWindowsPluginCApi")); 14 | } 15 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | hotkey_manager_windows 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "hotkey_manager_example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "hotkey_manager_example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2021-2024 LiJianying . All rights reserved." "\0" 97 | VALUE "OriginalFilename", "hotkey_manager_example.exe" "\0" 98 | VALUE "ProductName", "hotkey_manager_example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"hotkey_manager_example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanflutter/hotkey_manager/ddbb7bf7f6db9d40bcd0cd1c98d32f631b5ba2ed/packages/hotkey_manager/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr) 51 | -1; // remove the trailing null character 52 | int input_length = (int)wcslen(utf16_string); 53 | std::string utf8_string; 54 | if (target_length <= 0 || target_length > utf8_string.max_size()) { 55 | return utf8_string; 56 | } 57 | utf8_string.resize(target_length); 58 | int converted_length = ::WideCharToMultiByte( 59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 60 | input_length, utf8_string.data(), target_length, nullptr, nullptr); 61 | if (converted_length == 0) { 62 | return std::string(); 63 | } 64 | return utf8_string; 65 | } 66 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "resource.h" 7 | 8 | namespace { 9 | 10 | /// Window attribute that enables dark mode window decorations. 11 | /// 12 | /// Redefined in case the developer's machine has a Windows SDK older than 13 | /// version 10.0.22000.0. 14 | /// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute 15 | #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE 16 | #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 17 | #endif 18 | 19 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 20 | 21 | /// Registry key for app theme preference. 22 | /// 23 | /// A value of 0 indicates apps should use dark mode. A non-zero or missing 24 | /// value indicates apps should use light mode. 25 | constexpr const wchar_t kGetPreferredBrightnessRegKey[] = 26 | L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; 27 | constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; 28 | 29 | // The number of Win32Window objects that currently exist. 30 | static int g_active_window_count = 0; 31 | 32 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 33 | 34 | // Scale helper to convert logical scaler values to physical using passed in 35 | // scale factor 36 | int Scale(int source, double scale_factor) { 37 | return static_cast(source * scale_factor); 38 | } 39 | 40 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 41 | // This API is only needed for PerMonitor V1 awareness mode. 42 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 43 | HMODULE user32_module = LoadLibraryA("User32.dll"); 44 | if (!user32_module) { 45 | return; 46 | } 47 | auto enable_non_client_dpi_scaling = 48 | reinterpret_cast( 49 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 50 | if (enable_non_client_dpi_scaling != nullptr) { 51 | enable_non_client_dpi_scaling(hwnd); 52 | } 53 | FreeLibrary(user32_module); 54 | } 55 | 56 | } // namespace 57 | 58 | // Manages the Win32Window's window class registration. 59 | class WindowClassRegistrar { 60 | public: 61 | ~WindowClassRegistrar() = default; 62 | 63 | // Returns the singleton registrar instance. 64 | static WindowClassRegistrar* GetInstance() { 65 | if (!instance_) { 66 | instance_ = new WindowClassRegistrar(); 67 | } 68 | return instance_; 69 | } 70 | 71 | // Returns the name of the window class, registering the class if it hasn't 72 | // previously been registered. 73 | const wchar_t* GetWindowClass(); 74 | 75 | // Unregisters the window class. Should only be called if there are no 76 | // instances of the window. 77 | void UnregisterWindowClass(); 78 | 79 | private: 80 | WindowClassRegistrar() = default; 81 | 82 | static WindowClassRegistrar* instance_; 83 | 84 | bool class_registered_ = false; 85 | }; 86 | 87 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 88 | 89 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 90 | if (!class_registered_) { 91 | WNDCLASS window_class{}; 92 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 93 | window_class.lpszClassName = kWindowClassName; 94 | window_class.style = CS_HREDRAW | CS_VREDRAW; 95 | window_class.cbClsExtra = 0; 96 | window_class.cbWndExtra = 0; 97 | window_class.hInstance = GetModuleHandle(nullptr); 98 | window_class.hIcon = 99 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 100 | window_class.hbrBackground = 0; 101 | window_class.lpszMenuName = nullptr; 102 | window_class.lpfnWndProc = Win32Window::WndProc; 103 | RegisterClass(&window_class); 104 | class_registered_ = true; 105 | } 106 | return kWindowClassName; 107 | } 108 | 109 | void WindowClassRegistrar::UnregisterWindowClass() { 110 | UnregisterClass(kWindowClassName, nullptr); 111 | class_registered_ = false; 112 | } 113 | 114 | Win32Window::Win32Window() { 115 | ++g_active_window_count; 116 | } 117 | 118 | Win32Window::~Win32Window() { 119 | --g_active_window_count; 120 | Destroy(); 121 | } 122 | 123 | bool Win32Window::Create(const std::wstring& title, 124 | const Point& origin, 125 | const Size& size) { 126 | Destroy(); 127 | 128 | const wchar_t* window_class = 129 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 130 | 131 | const POINT target_point = {static_cast(origin.x), 132 | static_cast(origin.y)}; 133 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 134 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 135 | double scale_factor = dpi / 96.0; 136 | 137 | HWND window = CreateWindow( 138 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW, 139 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 140 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 141 | nullptr, nullptr, GetModuleHandle(nullptr), this); 142 | 143 | if (!window) { 144 | return false; 145 | } 146 | 147 | UpdateTheme(window); 148 | 149 | return OnCreate(); 150 | } 151 | 152 | bool Win32Window::Show() { 153 | return ShowWindow(window_handle_, SW_SHOWNORMAL); 154 | } 155 | 156 | // static 157 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 158 | UINT const message, 159 | WPARAM const wparam, 160 | LPARAM const lparam) noexcept { 161 | if (message == WM_NCCREATE) { 162 | auto window_struct = reinterpret_cast(lparam); 163 | SetWindowLongPtr(window, GWLP_USERDATA, 164 | reinterpret_cast(window_struct->lpCreateParams)); 165 | 166 | auto that = static_cast(window_struct->lpCreateParams); 167 | EnableFullDpiSupportIfAvailable(window); 168 | that->window_handle_ = window; 169 | } else if (Win32Window* that = GetThisFromHandle(window)) { 170 | return that->MessageHandler(window, message, wparam, lparam); 171 | } 172 | 173 | return DefWindowProc(window, message, wparam, lparam); 174 | } 175 | 176 | LRESULT 177 | Win32Window::MessageHandler(HWND hwnd, 178 | UINT const message, 179 | WPARAM const wparam, 180 | LPARAM const lparam) noexcept { 181 | switch (message) { 182 | case WM_DESTROY: 183 | window_handle_ = nullptr; 184 | Destroy(); 185 | if (quit_on_close_) { 186 | PostQuitMessage(0); 187 | } 188 | return 0; 189 | 190 | case WM_DPICHANGED: { 191 | auto newRectSize = reinterpret_cast(lparam); 192 | LONG newWidth = newRectSize->right - newRectSize->left; 193 | LONG newHeight = newRectSize->bottom - newRectSize->top; 194 | 195 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 196 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 197 | 198 | return 0; 199 | } 200 | case WM_SIZE: { 201 | RECT rect = GetClientArea(); 202 | if (child_content_ != nullptr) { 203 | // Size and position the child window. 204 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 205 | rect.bottom - rect.top, TRUE); 206 | } 207 | return 0; 208 | } 209 | 210 | case WM_ACTIVATE: 211 | if (child_content_ != nullptr) { 212 | SetFocus(child_content_); 213 | } 214 | return 0; 215 | 216 | case WM_DWMCOLORIZATIONCOLORCHANGED: 217 | UpdateTheme(hwnd); 218 | return 0; 219 | } 220 | 221 | return DefWindowProc(window_handle_, message, wparam, lparam); 222 | } 223 | 224 | void Win32Window::Destroy() { 225 | OnDestroy(); 226 | 227 | if (window_handle_) { 228 | DestroyWindow(window_handle_); 229 | window_handle_ = nullptr; 230 | } 231 | if (g_active_window_count == 0) { 232 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 233 | } 234 | } 235 | 236 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 237 | return reinterpret_cast( 238 | GetWindowLongPtr(window, GWLP_USERDATA)); 239 | } 240 | 241 | void Win32Window::SetChildContent(HWND content) { 242 | child_content_ = content; 243 | SetParent(content, window_handle_); 244 | RECT frame = GetClientArea(); 245 | 246 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 247 | frame.bottom - frame.top, true); 248 | 249 | SetFocus(child_content_); 250 | } 251 | 252 | RECT Win32Window::GetClientArea() { 253 | RECT frame; 254 | GetClientRect(window_handle_, &frame); 255 | return frame; 256 | } 257 | 258 | HWND Win32Window::GetHandle() { 259 | return window_handle_; 260 | } 261 | 262 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 263 | quit_on_close_ = quit_on_close; 264 | } 265 | 266 | bool Win32Window::OnCreate() { 267 | // No-op; provided for subclasses. 268 | return true; 269 | } 270 | 271 | void Win32Window::OnDestroy() { 272 | // No-op; provided for subclasses. 273 | } 274 | 275 | void Win32Window::UpdateTheme(HWND const window) { 276 | DWORD light_mode; 277 | DWORD light_mode_size = sizeof(light_mode); 278 | LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, 279 | kGetPreferredBrightnessRegValue, 280 | RRF_RT_REG_DWORD, nullptr, &light_mode, 281 | &light_mode_size); 282 | 283 | if (result == ERROR_SUCCESS) { 284 | BOOL enable_dark_mode = light_mode == 0; 285 | DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, 286 | &enable_dark_mode, sizeof(enable_dark_mode)); 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /packages/hotkey_manager/example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | -------------------------------------------------------------------------------- /packages/hotkey_manager/lib/hotkey_manager.dart: -------------------------------------------------------------------------------- 1 | export 'package:hotkey_manager/src/hotkey_manager.dart'; 2 | export 'package:hotkey_manager/src/widgets/global_shortcuts.dart'; 3 | export 'package:hotkey_manager/src/widgets/hotkey_recorder.dart'; 4 | export 'package:hotkey_manager/src/widgets/hotkey_virtual_view.dart'; 5 | export 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 6 | -------------------------------------------------------------------------------- /packages/hotkey_manager/lib/src/hotkey_manager.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'package:collection/collection.dart'; 3 | import 'package:flutter/services.dart'; 4 | import 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 5 | 6 | class HotKeyManager { 7 | HotKeyManager._() { 8 | _platform.onKeyEventReceiver.listen(_handleSystemHotKeyEvent); 9 | HardwareKeyboard.instance.addHandler(_handleInAppHotKeyEvent); 10 | } 11 | 12 | /// The shared instance of [HotKeyManager]. 13 | static final HotKeyManager instance = HotKeyManager._(); 14 | 15 | HotKeyManagerPlatform get _platform => HotKeyManagerPlatform.instance; 16 | 17 | final List _hotKeyList = []; 18 | final Map _keyDownHandlerMap = {}; 19 | final Map _keyUpHandlerMap = {}; 20 | 21 | HotKey? _lastPressedHotKey; 22 | 23 | /// Handle system hot key event. 24 | void _handleSystemHotKeyEvent(event) { 25 | String type = event['type'] as String; 26 | Map data = event['data'] as Map; 27 | String identifier = data['identifier'] as String; 28 | HotKey? hotKey = _hotKeyList.firstWhereOrNull( 29 | (e) => e.identifier == identifier, 30 | ); 31 | if (hotKey != null) { 32 | switch (type) { 33 | case 'onKeyDown': 34 | if (_keyDownHandlerMap.containsKey(identifier)) { 35 | _keyDownHandlerMap[identifier]!(hotKey); 36 | } 37 | break; 38 | case 'onKeyUp': 39 | if (_keyUpHandlerMap.containsKey(identifier)) { 40 | _keyUpHandlerMap[identifier]!(hotKey); 41 | } 42 | break; 43 | default: 44 | UnimplementedError(); 45 | } 46 | } 47 | } 48 | 49 | /// Handle in-app hot key event. 50 | bool _handleInAppHotKeyEvent(KeyEvent keyEvent) { 51 | if (_hotKeyList.where((e) => e.scope == HotKeyScope.inapp).isEmpty) { 52 | return false; 53 | } 54 | 55 | if (keyEvent is KeyUpEvent && _lastPressedHotKey != null) { 56 | HotKeyHandler? handler = _keyUpHandlerMap[_lastPressedHotKey!.identifier]; 57 | if (handler != null) handler(_lastPressedHotKey!); 58 | _lastPressedHotKey = null; 59 | return true; 60 | } 61 | 62 | if (keyEvent is KeyRepeatEvent && _lastPressedHotKey != null) { 63 | return true; 64 | } 65 | 66 | if (keyEvent is KeyDownEvent) { 67 | final physicalKeysPressed = HardwareKeyboard.instance.physicalKeysPressed; 68 | final hotKeys = _hotKeyList.where((e) { 69 | List modifiers = HotKeyModifier.values 70 | .where((e) => e.physicalKeys.any(physicalKeysPressed.contains)) 71 | .toList(); 72 | return e.scope == HotKeyScope.inapp && 73 | keyEvent.logicalKey == e.logicalKey && 74 | modifiers.length == (e.modifiers?.length ?? 0) && 75 | modifiers.every((e.modifiers ?? []).contains); 76 | }); 77 | if (hotKeys.isNotEmpty) { 78 | for (final hotKey in hotKeys) { 79 | HotKeyHandler? handler = _keyDownHandlerMap[hotKey.identifier]; 80 | if (handler != null) handler(hotKey); 81 | } 82 | _lastPressedHotKey = hotKeys.last; 83 | return true; 84 | } 85 | } 86 | return false; 87 | } 88 | 89 | List get registeredHotKeyList => _hotKeyList; 90 | 91 | /// Register a hot key. 92 | Future register( 93 | HotKey hotKey, { 94 | HotKeyHandler? keyDownHandler, 95 | HotKeyHandler? keyUpHandler, 96 | }) async { 97 | if (hotKey.scope == HotKeyScope.system) { 98 | await _platform.register(hotKey); 99 | } 100 | if (keyDownHandler != null) { 101 | _keyDownHandlerMap.update( 102 | hotKey.identifier, 103 | (_) => keyDownHandler, 104 | ifAbsent: () => keyDownHandler, 105 | ); 106 | } 107 | if (keyUpHandler != null) { 108 | _keyUpHandlerMap.update( 109 | hotKey.identifier, 110 | (_) => keyUpHandler, 111 | ifAbsent: () => keyUpHandler, 112 | ); 113 | } 114 | _hotKeyList.add(hotKey); 115 | } 116 | 117 | /// Unregister a hot key. 118 | Future unregister(HotKey hotKey) async { 119 | if (hotKey.scope == HotKeyScope.system) { 120 | await _platform.unregister(hotKey); 121 | } 122 | if (_keyDownHandlerMap.containsKey(hotKey.identifier)) { 123 | _keyDownHandlerMap.remove(hotKey.identifier); 124 | } 125 | if (_keyUpHandlerMap.containsKey(hotKey.identifier)) { 126 | _keyUpHandlerMap.remove(hotKey.identifier); 127 | } 128 | _hotKeyList.removeWhere((e) => e.identifier == hotKey.identifier); 129 | } 130 | 131 | /// Unregister all hot keys. 132 | Future unregisterAll() async { 133 | await _platform.unregisterAll(); 134 | _keyDownHandlerMap.clear(); 135 | _keyUpHandlerMap.clear(); 136 | _hotKeyList.clear(); 137 | } 138 | } 139 | 140 | final hotKeyManager = HotKeyManager.instance; 141 | -------------------------------------------------------------------------------- /packages/hotkey_manager/lib/src/widgets/global_shortcuts.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:hotkey_manager/hotkey_manager.dart'; 3 | 4 | extension _SingleActivatorExtension on SingleActivator { 5 | HotKey _toHotKey() { 6 | List modifiers = [ 7 | if (control) HotKeyModifier.control, 8 | if (shift) HotKeyModifier.shift, 9 | if (alt) HotKeyModifier.alt, 10 | if (meta) HotKeyModifier.meta, 11 | ]; 12 | return HotKey( 13 | identifier: [ 14 | ...modifiers.map((m) => m.name), 15 | '${trigger.keyId}', 16 | ].join('+'), 17 | key: trigger, 18 | modifiers: modifiers, 19 | scope: HotKeyScope.system, 20 | ); 21 | } 22 | } 23 | 24 | class GlobalShortcuts extends StatefulWidget { 25 | const GlobalShortcuts({ 26 | super.key, 27 | required this.shortcuts, 28 | required this.child, 29 | }); 30 | 31 | final Map shortcuts; 32 | 33 | final Widget child; 34 | 35 | @override 36 | State createState() => _GlobalShortcutsState(); 37 | } 38 | 39 | class _GlobalShortcutsState extends State { 40 | final List _registeredHotKeys = []; 41 | 42 | @override 43 | void initState() { 44 | super.initState(); 45 | for (final entry in widget.shortcuts.entries) { 46 | final hotKey = entry.key._toHotKey(); 47 | hotKeyManager.register(hotKey, keyDownHandler: _onKeyDown); 48 | _registeredHotKeys.add(hotKey); 49 | } 50 | } 51 | 52 | @override 53 | void dispose() { 54 | super.dispose(); 55 | for (final hotKey in _registeredHotKeys) { 56 | hotKeyManager.unregister(hotKey); 57 | } 58 | _registeredHotKeys.clear(); 59 | } 60 | 61 | void _onKeyDown(HotKey hotKey) { 62 | final activator = widget.shortcuts.keys.firstWhere( 63 | (activator) => activator._toHotKey().identifier == hotKey.identifier, 64 | ); 65 | final Intent? matchedIntent = widget.shortcuts[activator]; 66 | if (matchedIntent != null) { 67 | final Action? action = Actions.maybeFind( 68 | context, 69 | intent: matchedIntent, 70 | ); 71 | if (action != null) { 72 | final (bool enabled, Object? invokeResult) = 73 | Actions.of(context).invokeActionIfEnabled( 74 | action, 75 | matchedIntent, 76 | context, 77 | ); 78 | if (enabled) { 79 | action.toKeyEventResult(matchedIntent, invokeResult); 80 | } 81 | } 82 | } 83 | } 84 | 85 | @override 86 | Widget build(BuildContext context) { 87 | return widget.child; 88 | } 89 | } 90 | 91 | class CallbackGlobalShortcuts extends StatefulWidget { 92 | const CallbackGlobalShortcuts({ 93 | super.key, 94 | required this.bindings, 95 | required this.child, 96 | }); 97 | 98 | final Map bindings; 99 | 100 | final Widget child; 101 | 102 | @override 103 | State createState() => 104 | _CallbackGlobalShortcutsState(); 105 | } 106 | 107 | class _CallbackGlobalShortcutsState extends State { 108 | final List _registeredHotKeys = []; 109 | 110 | Map get bindings => widget.bindings; 111 | 112 | @override 113 | void initState() { 114 | super.initState(); 115 | for (final entry in widget.bindings.entries) { 116 | final hotKey = entry.key._toHotKey(); 117 | hotKeyManager.register(hotKey, keyDownHandler: _onKeyDown); 118 | _registeredHotKeys.add(hotKey); 119 | } 120 | } 121 | 122 | @override 123 | void dispose() { 124 | super.dispose(); 125 | for (final hotKey in _registeredHotKeys) { 126 | hotKeyManager.unregister(hotKey); 127 | } 128 | _registeredHotKeys.clear(); 129 | } 130 | 131 | void _onKeyDown(HotKey hotKey) { 132 | final activator = bindings.keys.firstWhere( 133 | (activator) => activator._toHotKey().identifier == hotKey.identifier, 134 | ); 135 | bindings[activator]!.call(); 136 | } 137 | 138 | @override 139 | Widget build(BuildContext context) { 140 | return widget.child; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /packages/hotkey_manager/lib/src/widgets/hotkey_recorder.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:hotkey_manager/src/widgets/hotkey_virtual_view.dart'; 4 | import 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 5 | 6 | class HotKeyRecorder extends StatefulWidget { 7 | const HotKeyRecorder({ 8 | super.key, 9 | this.initalHotKey, 10 | required this.onHotKeyRecorded, 11 | }); 12 | 13 | final HotKey? initalHotKey; 14 | final ValueChanged onHotKeyRecorded; 15 | 16 | @override 17 | State createState() => _HotKeyRecorderState(); 18 | } 19 | 20 | class _HotKeyRecorderState extends State { 21 | HotKey? _hotKey; 22 | 23 | @override 24 | void initState() { 25 | if (widget.initalHotKey != null) { 26 | _hotKey = widget.initalHotKey!; 27 | } 28 | HardwareKeyboard.instance.addHandler(_handleKeyEvent); 29 | super.initState(); 30 | } 31 | 32 | @override 33 | void dispose() { 34 | HardwareKeyboard.instance.removeHandler(_handleKeyEvent); 35 | super.dispose(); 36 | } 37 | 38 | bool _handleKeyEvent(KeyEvent keyEvent) { 39 | if (keyEvent is KeyUpEvent) return false; 40 | final physicalKeysPressed = HardwareKeyboard.instance.physicalKeysPressed; 41 | PhysicalKeyboardKey? key = keyEvent.physicalKey; 42 | List? modifiers = HotKeyModifier.values 43 | .where((e) => e.physicalKeys.any(physicalKeysPressed.contains)) 44 | .toList(); 45 | if (modifiers.isNotEmpty) { 46 | // Remove the key from the modifiers list if it is a modifier 47 | modifiers = modifiers 48 | .where((e) => !e.physicalKeys.contains(key)) // linewrap 49 | .toList(); 50 | } 51 | _hotKey = HotKey( 52 | identifier: widget.initalHotKey?.identifier, 53 | key: key, 54 | modifiers: modifiers, 55 | scope: widget.initalHotKey?.scope ?? HotKeyScope.system, 56 | ); 57 | widget.onHotKeyRecorded(_hotKey!); 58 | setState(() {}); 59 | return true; 60 | } 61 | 62 | @override 63 | Widget build(BuildContext context) { 64 | if (_hotKey == null) { 65 | return Container(); 66 | } 67 | return HotKeyVirtualView(hotKey: _hotKey!); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /packages/hotkey_manager/lib/src/widgets/hotkey_virtual_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 3 | 4 | class _VirtualKeyView extends StatelessWidget { 5 | const _VirtualKeyView({ 6 | required this.keyLabel, 7 | }); 8 | 9 | final String keyLabel; 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return Container( 14 | padding: const EdgeInsets.only(left: 5, right: 5, top: 3, bottom: 3), 15 | decoration: BoxDecoration( 16 | color: Theme.of(context).canvasColor, 17 | border: Border.all( 18 | color: Theme.of(context).dividerColor, 19 | width: 1, 20 | ), 21 | borderRadius: BorderRadius.circular(3), 22 | boxShadow: [ 23 | BoxShadow( 24 | color: Colors.black.withOpacity(0.3), 25 | offset: const Offset(0.0, 1.0), 26 | ), 27 | ], 28 | ), 29 | child: Text( 30 | keyLabel, 31 | style: TextStyle( 32 | color: Theme.of(context).textTheme.bodyMedium?.color, 33 | fontSize: 12, 34 | ), 35 | ), 36 | ); 37 | } 38 | } 39 | 40 | class HotKeyVirtualView extends StatelessWidget { 41 | const HotKeyVirtualView({ 42 | super.key, 43 | required this.hotKey, 44 | }); 45 | 46 | final HotKey hotKey; 47 | 48 | @override 49 | Widget build(BuildContext context) { 50 | return Wrap( 51 | spacing: 8, 52 | children: [ 53 | for (HotKeyModifier modifier in hotKey.modifiers ?? []) 54 | _VirtualKeyView( 55 | keyLabel: modifier.physicalKeys.first.keyLabel, 56 | ), 57 | _VirtualKeyView( 58 | keyLabel: hotKey.physicalKey.keyLabel, 59 | ), 60 | ], 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/hotkey_manager/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager 2 | description: This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut). 3 | version: 0.2.3 4 | homepage: https://github.com/leanflutter/hotkey_manager 5 | 6 | platforms: 7 | linux: 8 | macos: 9 | windows: 10 | 11 | topics: 12 | - hotkey 13 | - shortcuts 14 | - global-hotkey 15 | - global-shortcuts 16 | 17 | environment: 18 | sdk: ">=3.0.0 <4.0.0" 19 | flutter: ">=3.3.0" 20 | 21 | dependencies: 22 | collection: ^1.17.1 23 | flutter: 24 | sdk: flutter 25 | hotkey_manager_linux: ^0.2.0 26 | hotkey_manager_macos: ^0.2.0 27 | hotkey_manager_platform_interface: ^0.2.0 28 | hotkey_manager_windows: ^0.2.0 29 | uuid: '>=3.0.7 <5.0.0' 30 | 31 | dev_dependencies: 32 | dependency_validator: ^3.0.0 33 | flutter_test: 34 | sdk: flutter 35 | mostly_reasonable_lints: ^0.1.2 36 | 37 | flutter: 38 | plugin: 39 | platforms: 40 | linux: 41 | default_package: hotkey_manager_linux 42 | macos: 43 | default_package: hotkey_manager_macos 44 | windows: 45 | default_package: hotkey_manager_windows 46 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | build/ 30 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "ef1af02aead6fe2414f3aafa5a61087b610e1332" 8 | channel: "stable" 9 | 10 | project_type: plugin 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: ef1af02aead6fe2414f3aafa5a61087b610e1332 17 | base_revision: ef1af02aead6fe2414f3aafa5a61087b610e1332 18 | - platform: linux 19 | create_revision: ef1af02aead6fe2414f3aafa5a61087b610e1332 20 | base_revision: ef1af02aead6fe2414f3aafa5a61087b610e1332 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 2 | 3 | * First release. 4 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/README.md: -------------------------------------------------------------------------------- 1 | # hotkey_manager_linux 2 | 3 | [![pub version][pub-image]][pub-url] 4 | 5 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager_linux.svg 6 | [pub-url]: https://pub.dev/packages/hotkey_manager_linux 7 | 8 | The Linux implementation of [hotkey_manager](https://pub.dev/packages/hotkey_manager). 9 | 10 | ## License 11 | 12 | [MIT](./LICENSE) 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The Flutter tooling requires that developers have CMake 3.10 or later 2 | # installed. You should not increase this version, as doing so will cause 3 | # the plugin to fail to compile for some customers of the plugin. 4 | cmake_minimum_required(VERSION 3.10) 5 | 6 | # Project-level configuration. 7 | set(PROJECT_NAME "hotkey_manager_linux") 8 | project(${PROJECT_NAME} LANGUAGES CXX) 9 | 10 | # This value is used when generating builds using this plugin, so it must 11 | # not be changed. 12 | set(PLUGIN_NAME "hotkey_manager_linux_plugin") 13 | 14 | # Any new source files that you add to the plugin should be added here. 15 | list(APPEND PLUGIN_SOURCES 16 | "hotkey_manager_linux_plugin.cc" 17 | ) 18 | 19 | # Define the plugin library target. Its name must not be changed (see comment 20 | # on PLUGIN_NAME above). 21 | add_library(${PLUGIN_NAME} SHARED 22 | ${PLUGIN_SOURCES} 23 | ) 24 | 25 | # Apply a standard set of build settings that are configured in the 26 | # application-level CMakeLists.txt. This can be removed for plugins that want 27 | # full control over build settings. 28 | apply_standard_settings(${PLUGIN_NAME}) 29 | 30 | # Symbols are hidden by default to reduce the chance of accidental conflicts 31 | # between plugins. This should not be removed; any symbols that should be 32 | # exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro. 33 | set_target_properties(${PLUGIN_NAME} PROPERTIES 34 | CXX_VISIBILITY_PRESET hidden) 35 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 36 | 37 | # Source include directories and library dependencies. Add any plugin-specific 38 | # dependencies here. 39 | target_include_directories(${PLUGIN_NAME} INTERFACE 40 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 41 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) 42 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) 43 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::KEYBINDER) 44 | 45 | pkg_check_modules(KEYBINDER IMPORTED_TARGET keybinder-3.0) 46 | if(KEYBINDER_FOUND) 47 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::KEYBINDER) 48 | else() 49 | message( 50 | FATAL_ERROR 51 | "\n" 52 | "The `hotkey_manager` package requires keybinder-3.0. See https://github.com/leanflutter/hotkey_manager#linux-requirements" 53 | ) 54 | endif() 55 | 56 | # List of absolute paths to libraries that should be bundled with the plugin. 57 | # This list could contain prebuilt libraries, or libraries created by an 58 | # external build triggered from this build file. 59 | set(hotkey_manager_linux_bundled_libraries 60 | "" 61 | PARENT_SCOPE 62 | ) 63 | 64 | # === Tests === 65 | # These unit tests can be run from a terminal after building the example. 66 | 67 | # Only enable test builds when building the example (which sets this variable) 68 | # so that plugin clients aren't building the tests. 69 | if (${include_${PROJECT_NAME}_tests}) 70 | if(${CMAKE_VERSION} VERSION_LESS "3.11.0") 71 | message("Unit tests require CMake 3.11.0 or later") 72 | else() 73 | set(TEST_RUNNER "${PROJECT_NAME}_test") 74 | enable_testing() 75 | 76 | # Add the Google Test dependency. 77 | include(FetchContent) 78 | FetchContent_Declare( 79 | googletest 80 | URL https://github.com/google/googletest/archive/release-1.11.0.zip 81 | ) 82 | # Prevent overriding the parent project's compiler/linker settings 83 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 84 | # Disable install commands for gtest so it doesn't end up in the bundle. 85 | set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) 86 | 87 | FetchContent_MakeAvailable(googletest) 88 | 89 | # The plugin's exported API is not very useful for unit testing, so build the 90 | # sources directly into the test binary rather than using the shared library. 91 | add_executable(${TEST_RUNNER} 92 | test/hotkey_manager_linux_plugin_test.cc 93 | ${PLUGIN_SOURCES} 94 | ) 95 | apply_standard_settings(${TEST_RUNNER}) 96 | target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") 97 | target_link_libraries(${TEST_RUNNER} PRIVATE flutter) 98 | target_link_libraries(${TEST_RUNNER} PRIVATE PkgConfig::GTK) 99 | target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) 100 | 101 | # Enable automatic test discovery. 102 | include(GoogleTest) 103 | gtest_discover_tests(${TEST_RUNNER}) 104 | 105 | endif() # CMake version check 106 | endif() # include_${PROJECT_NAME}_tests -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/linux/hotkey_manager_linux_plugin.cc: -------------------------------------------------------------------------------- 1 | #include "include/hotkey_manager_linux/hotkey_manager_linux_plugin.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "hotkey_manager_linux_plugin_private.h" 18 | 19 | #define HOTKEY_MANAGER_LINUX_PLUGIN(obj) \ 20 | (G_TYPE_CHECK_INSTANCE_CAST((obj), hotkey_manager_linux_plugin_get_type(), \ 21 | HotkeyManagerLinuxPlugin)) 22 | 23 | std::map hotkey_id_map; 24 | FlEventChannel* event_channel; 25 | 26 | struct _HotkeyManagerLinuxPlugin { 27 | GObject parent_instance; 28 | }; 29 | 30 | G_DEFINE_TYPE(HotkeyManagerLinuxPlugin, 31 | hotkey_manager_linux_plugin, 32 | g_object_get_type()) 33 | 34 | void handle_key_down(const char* keystring, void* user_data) { 35 | const char* identifier; 36 | 37 | std::string val = keystring; 38 | auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(), 39 | [val](const auto& e) { return e.second == val; }); 40 | 41 | if (result != hotkey_id_map.end()) 42 | identifier = result->first.c_str(); 43 | 44 | g_autoptr(FlValue) event_data = fl_value_new_map(); 45 | fl_value_set_string_take(event_data, "identifier", 46 | fl_value_new_string(identifier)); 47 | 48 | FlValue* event = fl_value_new_map(); 49 | fl_value_set_string_take(event, "type", fl_value_new_string("onKeyDown")); 50 | fl_value_set_string_take(event, "data", event_data); 51 | 52 | fl_event_channel_send(event_channel, event, nullptr, nullptr); 53 | } 54 | 55 | guint get_mods(const std::vector& modifiers) { 56 | guint mods = 0; 57 | for (int i = 0; i < modifiers.size(); i++) { 58 | guint mod = 0; 59 | if (modifiers[i] == "alt") 60 | mod = GDK_MOD1_MASK; 61 | else if (modifiers[i] == "capsLock") 62 | mod = GDK_LOCK_MASK; 63 | else if (modifiers[i] == "control") 64 | mod = GDK_CONTROL_MASK; 65 | else if (modifiers[i] == "meta") 66 | mod = GDK_META_MASK; 67 | else if (modifiers[i] == "shift") 68 | mod = GDK_SHIFT_MASK; 69 | mods = mods | mod; 70 | } 71 | return mods; 72 | } 73 | 74 | static FlMethodResponse* hkm_register(_HotkeyManagerLinuxPlugin* self, 75 | FlValue* args) { 76 | FlValue* modifiers_value = fl_value_lookup_string(args, "modifiers"); 77 | 78 | const char* identifier = 79 | fl_value_get_string(fl_value_lookup_string(args, "identifier")); 80 | const int key_code = 81 | fl_value_get_int(fl_value_lookup_string(args, "keyCode")); 82 | std::vector modifiers; 83 | for (gint i = 0; i < fl_value_get_length(modifiers_value); i++) { 84 | std::string keyModifier = 85 | fl_value_get_string(fl_value_get_list_value(modifiers_value, i)); 86 | modifiers.push_back(keyModifier); 87 | } 88 | 89 | const char* keystring = 90 | gtk_accelerator_name(key_code, (GdkModifierType)get_mods(modifiers)); 91 | 92 | hotkey_id_map.insert( 93 | std::pair(identifier, keystring)); 94 | 95 | keybinder_init(); 96 | keybinder_bind(keystring, handle_key_down, NULL); 97 | 98 | return FL_METHOD_RESPONSE( 99 | fl_method_success_response_new(fl_value_new_bool(true))); 100 | } 101 | 102 | static FlMethodResponse* hkm_unregister(_HotkeyManagerLinuxPlugin* self, 103 | FlValue* args) { 104 | const char* identifier = 105 | fl_value_get_string(fl_value_lookup_string(args, "identifier")); 106 | const char* keystring; 107 | 108 | std::string val = identifier; 109 | auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(), 110 | [val](const auto& e) { return e.first == val; }); 111 | 112 | if (result != hotkey_id_map.end()) 113 | keystring = result->second.c_str(); 114 | 115 | keybinder_unbind(keystring, handle_key_down); 116 | hotkey_id_map.erase(identifier); 117 | 118 | return FL_METHOD_RESPONSE( 119 | fl_method_success_response_new(fl_value_new_bool(true))); 120 | } 121 | 122 | static FlMethodResponse* hkm_unregister_all(_HotkeyManagerLinuxPlugin* self, 123 | FlValue* args) { 124 | for (std::map::iterator it = hotkey_id_map.begin(); 125 | it != hotkey_id_map.end(); ++it) { 126 | std::string identifier = it->first; 127 | const char* keystring = it->second.c_str(); 128 | keybinder_unbind(keystring, handle_key_down); 129 | } 130 | 131 | hotkey_id_map.clear(); 132 | 133 | return FL_METHOD_RESPONSE( 134 | fl_method_success_response_new(fl_value_new_bool(true))); 135 | } 136 | 137 | // Called when a method call is received from Flutter. 138 | static void hotkey_manager_linux_plugin_handle_method_call( 139 | HotkeyManagerLinuxPlugin* self, 140 | FlMethodCall* method_call) { 141 | g_autoptr(FlMethodResponse) response = nullptr; 142 | 143 | const gchar* method = fl_method_call_get_name(method_call); 144 | FlValue* args = fl_method_call_get_args(method_call); 145 | 146 | if (strcmp(method, "register") == 0) { 147 | response = hkm_register(self, args); 148 | } else if (strcmp(method, "unregister") == 0) { 149 | response = hkm_unregister(self, args); 150 | } else if (strcmp(method, "unregisterAll") == 0) { 151 | response = hkm_unregister_all(self, args); 152 | } else { 153 | response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); 154 | } 155 | 156 | fl_method_call_respond(method_call, response, nullptr); 157 | } 158 | 159 | FlMethodResponse* get_platform_version() { 160 | struct utsname uname_data = {}; 161 | uname(&uname_data); 162 | g_autofree gchar* version = g_strdup_printf("Linux %s", uname_data.version); 163 | g_autoptr(FlValue) result = fl_value_new_string(version); 164 | return FL_METHOD_RESPONSE(fl_method_success_response_new(result)); 165 | } 166 | 167 | static void hotkey_manager_linux_plugin_dispose(GObject* object) { 168 | g_clear_object(&event_channel); 169 | G_OBJECT_CLASS(hotkey_manager_linux_plugin_parent_class)->dispose(object); 170 | } 171 | 172 | static void hotkey_manager_linux_plugin_class_init( 173 | HotkeyManagerLinuxPluginClass* klass) { 174 | G_OBJECT_CLASS(klass)->dispose = hotkey_manager_linux_plugin_dispose; 175 | } 176 | 177 | static void hotkey_manager_linux_plugin_init(HotkeyManagerLinuxPlugin* self) {} 178 | 179 | static void method_call_cb(FlMethodChannel* channel, 180 | FlMethodCall* method_call, 181 | gpointer user_data) { 182 | HotkeyManagerLinuxPlugin* plugin = HOTKEY_MANAGER_LINUX_PLUGIN(user_data); 183 | hotkey_manager_linux_plugin_handle_method_call(plugin, method_call); 184 | } 185 | 186 | void hotkey_manager_linux_plugin_register_with_registrar( 187 | FlPluginRegistrar* registrar) { 188 | HotkeyManagerLinuxPlugin* plugin = HOTKEY_MANAGER_LINUX_PLUGIN( 189 | g_object_new(hotkey_manager_linux_plugin_get_type(), nullptr)); 190 | 191 | g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); 192 | g_autoptr(FlMethodChannel) channel = fl_method_channel_new( 193 | fl_plugin_registrar_get_messenger(registrar), 194 | "dev.leanflutter.plugins/hotkey_manager", FL_METHOD_CODEC(codec)); 195 | fl_method_channel_set_method_call_handler( 196 | channel, method_call_cb, g_object_ref(plugin), g_object_unref); 197 | 198 | g_autoptr(FlStandardMethodCodec) event_codec = fl_standard_method_codec_new(); 199 | event_channel = 200 | fl_event_channel_new(fl_plugin_registrar_get_messenger(registrar), 201 | "dev.leanflutter.plugins/hotkey_manager_event", 202 | FL_METHOD_CODEC(event_codec)); 203 | 204 | g_object_unref(plugin); 205 | } 206 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/linux/hotkey_manager_linux_plugin_private.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "include/hotkey_manager_linux/hotkey_manager_linux_plugin.h" 4 | 5 | // This file exposes some plugin internals for unit testing. See 6 | // https://github.com/flutter/flutter/issues/88724 for current limitations 7 | // in the unit-testable API. 8 | 9 | // Handles the getPlatformVersion method call. 10 | FlMethodResponse *get_platform_version(); 11 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/linux/include/hotkey_manager_linux/hotkey_manager_linux_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_HOTKEY_MANAGER_LINUX_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_HOTKEY_MANAGER_LINUX_PLUGIN_H_ 3 | 4 | #include 5 | 6 | G_BEGIN_DECLS 7 | 8 | #ifdef FLUTTER_PLUGIN_IMPL 9 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 10 | #else 11 | #define FLUTTER_PLUGIN_EXPORT 12 | #endif 13 | 14 | typedef struct _HotkeyManagerLinuxPlugin HotkeyManagerLinuxPlugin; 15 | typedef struct { 16 | GObjectClass parent_class; 17 | } HotkeyManagerLinuxPluginClass; 18 | 19 | FLUTTER_PLUGIN_EXPORT GType hotkey_manager_linux_plugin_get_type(); 20 | 21 | FLUTTER_PLUGIN_EXPORT void hotkey_manager_linux_plugin_register_with_registrar( 22 | FlPluginRegistrar* registrar); 23 | 24 | G_END_DECLS 25 | 26 | #endif // FLUTTER_PLUGIN_HOTKEY_MANAGER_LINUX_PLUGIN_H_ 27 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/linux/test/hotkey_manager_linux_plugin_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "include/hotkey_manager_linux/hotkey_manager_linux_plugin.h" 6 | #include "hotkey_manager_linux_plugin_private.h" 7 | 8 | // This demonstrates a simple unit test of the C portion of this plugin's 9 | // implementation. 10 | // 11 | // Once you have built the plugin's example app, you can run these tests 12 | // from the command line. For instance, for a plugin called my_plugin 13 | // built for x64 debug, run: 14 | // $ build/linux/x64/debug/plugins/my_plugin/my_plugin_test 15 | 16 | namespace hotkey_manager_linux { 17 | namespace test { 18 | 19 | TEST(HotkeyManagerLinuxPlugin, GetPlatformVersion) { 20 | g_autoptr(FlMethodResponse) response = get_platform_version(); 21 | ASSERT_NE(response, nullptr); 22 | ASSERT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response)); 23 | FlValue* result = fl_method_success_response_get_result( 24 | FL_METHOD_SUCCESS_RESPONSE(response)); 25 | ASSERT_EQ(fl_value_get_type(result), FL_VALUE_TYPE_STRING); 26 | // The full string varies, so just validate that it has the right format. 27 | EXPECT_THAT(fl_value_get_string(result), testing::StartsWith("Linux ")); 28 | } 29 | 30 | } // namespace test 31 | } // namespace hotkey_manager_linux 32 | -------------------------------------------------------------------------------- /packages/hotkey_manager_linux/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_linux 2 | description: Linux implementation of the hotkey_manager plugin. 3 | version: 0.2.0 4 | repository: https://github.com/leanflutter/hotkey_manager/tree/main/packages/hotkey_manager_linux 5 | 6 | environment: 7 | sdk: '>=3.0.0 <4.0.0' 8 | flutter: '>=3.3.0' 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | hotkey_manager_platform_interface: ^0.2.0 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | mostly_reasonable_lints: ^0.1.1 19 | 20 | flutter: 21 | plugin: 22 | implements: hotkey_manager 23 | platforms: 24 | linux: 25 | pluginClass: HotkeyManagerLinuxPlugin 26 | 27 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | build/ 30 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4" 8 | channel: "stable" 9 | 10 | project_type: plugin 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 17 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 18 | - platform: macos 19 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 20 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 2 | 3 | * First release. 4 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/README.md: -------------------------------------------------------------------------------- 1 | # hotkey_manager_macos 2 | 3 | [![pub version][pub-image]][pub-url] 4 | 5 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager_macos.svg 6 | [pub-url]: https://pub.dev/packages/hotkey_manager_macos 7 | 8 | The macOS implementation of [hotkey_manager](https://pub.dev/packages/hotkey_manager). 9 | 10 | ## License 11 | 12 | [MIT](./LICENSE) 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/macos/Classes/HotKeyExtension+NSEventModifierFlags.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HotKeyExtension+NSEventModifierFlags.swift 3 | // hotkey_manager 4 | // 5 | // Created by Lijy91 on 2021/7/23. 6 | // 7 | 8 | extension NSEvent.ModifierFlags { 9 | public init(pluginModifiers: Array) { 10 | self.init() 11 | if (pluginModifiers.contains("alt")) { 12 | insert(.option) 13 | } 14 | if (pluginModifiers.contains("capsLock")) { 15 | insert(.capsLock) 16 | } 17 | if (pluginModifiers.contains("control")) { 18 | insert(.control) 19 | } 20 | if (pluginModifiers.contains("fn")) { 21 | insert(.function) 22 | } 23 | if (pluginModifiers.contains("meta")) { 24 | insert(.command) 25 | } 26 | if (pluginModifiers.contains("shift")) { 27 | insert(.shift) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/macos/Classes/HotkeyManagerMacosPlugin.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | import HotKey 4 | import Carbon 5 | 6 | public class HotkeyManagerMacosPlugin: NSObject, FlutterPlugin, FlutterStreamHandler { 7 | private var _eventSink: FlutterEventSink? 8 | 9 | var hotKeyDict: Dictionary = [:] 10 | 11 | public static func register(with registrar: FlutterPluginRegistrar) { 12 | let channel = FlutterMethodChannel(name: "dev.leanflutter.plugins/hotkey_manager", binaryMessenger: registrar.messenger) 13 | let instance = HotkeyManagerMacosPlugin() 14 | registrar.addMethodCallDelegate(instance, channel: channel) 15 | let eventChannel = FlutterEventChannel(name: "dev.leanflutter.plugins/hotkey_manager_event", binaryMessenger: registrar.messenger) 16 | eventChannel.setStreamHandler(instance) 17 | } 18 | 19 | public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { 20 | self._eventSink = events 21 | return nil; 22 | } 23 | 24 | public func onCancel(withArguments arguments: Any?) -> FlutterError? { 25 | self._eventSink = nil 26 | return nil 27 | } 28 | 29 | public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { 30 | switch call.method { 31 | case "register": 32 | register(call, result: result) 33 | break 34 | case "unregister": 35 | unregister(call, result: result) 36 | break 37 | case "unregisterAll": 38 | unregisterAll(call, result: result) 39 | break 40 | default: 41 | result(FlutterMethodNotImplemented) 42 | } 43 | } 44 | 45 | public func register(_ call: FlutterMethodCall, result: @escaping FlutterResult) { 46 | let args:[String: Any] = call.arguments as! [String: Any] 47 | 48 | let keyCode = args["keyCode"] as! UInt32 49 | let modifiers = args["modifiers"] as! Array 50 | let identifier = args["identifier"] as! String 51 | 52 | let hotKey: HotKey = HotKey( 53 | key: Key(carbonKeyCode: keyCode)!, 54 | modifiers: NSEvent.ModifierFlags.init(pluginModifiers: modifiers) 55 | ) 56 | hotKey.keyDownHandler = { 57 | guard let eventSink = self._eventSink else { 58 | return 59 | } 60 | let event: NSDictionary = [ 61 | "type": "onKeyDown", 62 | "data": call.arguments as! NSDictionary, 63 | ] 64 | eventSink(event) 65 | } 66 | hotKey.keyUpHandler = { 67 | guard let eventSink = self._eventSink else { 68 | return 69 | } 70 | let event: NSDictionary = [ 71 | "type": "onKeyUp", 72 | "data": call.arguments as! NSDictionary, 73 | ] 74 | eventSink(event) 75 | } 76 | self.hotKeyDict[identifier] = hotKey 77 | result(true) 78 | } 79 | 80 | public func unregister(_ call: FlutterMethodCall, result: @escaping FlutterResult) { 81 | let args:[String: Any] = call.arguments as! [String: Any] 82 | 83 | let identifier = args["identifier"] as! String 84 | 85 | self.hotKeyDict[identifier] = nil; 86 | 87 | result(true) 88 | } 89 | 90 | public func unregisterAll(_ call: FlutterMethodCall, result: @escaping FlutterResult) { 91 | self.hotKeyDict.removeAll(); 92 | result(true) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/macos/hotkey_manager_macos.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. 3 | # Run `pod lib lint hotkey_manager_macos.podspec` to validate before publishing. 4 | # 5 | Pod::Spec.new do |s| 6 | s.name = 'hotkey_manager_macos' 7 | s.version = '0.0.1' 8 | s.summary = 'A new Flutter plugin project.' 9 | s.description = <<-DESC 10 | A new Flutter plugin project. 11 | DESC 12 | s.homepage = 'http://example.com' 13 | s.license = { :file => '../LICENSE' } 14 | s.author = { 'Your Company' => 'email@example.com' } 15 | 16 | s.source = { :path => '.' } 17 | s.source_files = 'Classes/**/*' 18 | s.dependency 'FlutterMacOS' 19 | s.dependency 'HotKey' 20 | 21 | s.platform = :osx, '10.11' 22 | s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } 23 | s.swift_version = '5.0' 24 | end 25 | -------------------------------------------------------------------------------- /packages/hotkey_manager_macos/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_macos 2 | description: macOS implementation of the hotkey_manager plugin. 3 | version: 0.2.0 4 | repository: https://github.com/leanflutter/hotkey_manager/tree/main/packages/hotkey_manager_macos 5 | 6 | environment: 7 | sdk: '>=3.0.0 <4.0.0' 8 | flutter: '>=3.3.0' 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | hotkey_manager_platform_interface: ^0.2.0 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | mostly_reasonable_lints: ^0.1.1 19 | 20 | flutter: 21 | plugin: 22 | implements: hotkey_manager 23 | platforms: 24 | macos: 25 | pluginClass: HotkeyManagerMacosPlugin 26 | 27 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | build/ 30 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4" 8 | channel: "stable" 9 | 10 | project_type: plugin 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 17 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 18 | 19 | # User provided section 20 | 21 | # List of Local paths (relative to this file) that should be 22 | # ignored by the migrate tool. 23 | # 24 | # Files that are not part of the templates will be ignored by default. 25 | unmanaged_files: 26 | - 'lib/main.dart' 27 | - 'ios/Runner.xcodeproj/project.pbxproj' 28 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 2 | 3 | * First release. 4 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/README.md: -------------------------------------------------------------------------------- 1 | # hotkey_manager_platform_interface 2 | 3 | [![pub version][pub-image]][pub-url] 4 | 5 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager_platform_interface.svg 6 | [pub-url]: https://pub.dev/packages/hotkey_manager_platform_interface 7 | 8 | A common platform interface for the [hotkey_manager](https://pub.dev/packages/hotkey_manager) plugin. 9 | 10 | ## Usage 11 | 12 | To implement a new platform-specific implementation of hotkey_manager, extend `HotKeyManagerPlatform` with an implementation that performs the platform-specific behavior, and when you register your plugin, set the default `HotKeyManagerPlatform` by calling `HotKeyManagerPlatform.instance = MyPlatformHotKeyManager()`. 13 | 14 | ## License 15 | 16 | [MIT](./LICENSE) 17 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/hotkey_manager_platform_interface.dart: -------------------------------------------------------------------------------- 1 | library hotkey_manager_platform_interface; 2 | 3 | export 'src/enums/key_code.dart'; 4 | export 'src/enums/key_modifier.dart'; 5 | export 'src/extensions/keyboard_key.dart'; 6 | export 'src/hotkey.dart'; 7 | export 'src/hotkey_manager_method_channel.dart'; 8 | export 'src/hotkey_manager_platform_interface.dart'; 9 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/enums/key_modifier.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package 2 | 3 | import 'dart:io'; 4 | 5 | import 'package:flutter/foundation.dart' show kIsWeb; 6 | import 'package:flutter/services.dart'; 7 | 8 | const Map> _knownLogicalKeys = 9 | >{ 10 | KeyModifier.capsLock: [ 11 | LogicalKeyboardKey.capsLock, 12 | ], 13 | KeyModifier.shift: [ 14 | LogicalKeyboardKey.shift, 15 | LogicalKeyboardKey.shiftLeft, 16 | LogicalKeyboardKey.shiftRight, 17 | ], 18 | KeyModifier.control: [ 19 | LogicalKeyboardKey.control, 20 | LogicalKeyboardKey.controlLeft, 21 | LogicalKeyboardKey.controlRight, 22 | ], 23 | KeyModifier.alt: [ 24 | LogicalKeyboardKey.alt, 25 | LogicalKeyboardKey.altLeft, 26 | LogicalKeyboardKey.altRight, 27 | ], 28 | KeyModifier.meta: [ 29 | LogicalKeyboardKey.meta, 30 | LogicalKeyboardKey.metaLeft, 31 | LogicalKeyboardKey.metaRight, 32 | ], 33 | KeyModifier.fn: [ 34 | LogicalKeyboardKey.fn, 35 | ], 36 | }; 37 | 38 | const Map _knownModifierKeys = 39 | { 40 | KeyModifier.capsLock: ModifierKey.capsLockModifier, 41 | KeyModifier.shift: ModifierKey.shiftModifier, 42 | KeyModifier.control: ModifierKey.controlModifier, 43 | KeyModifier.alt: ModifierKey.altModifier, 44 | KeyModifier.meta: ModifierKey.metaModifier, 45 | KeyModifier.fn: ModifierKey.functionModifier, 46 | }; 47 | 48 | final Map _knownKeyLabels = { 49 | KeyModifier.capsLock: '⇪', 50 | KeyModifier.shift: '⇧', 51 | KeyModifier.control: (!kIsWeb && Platform.isMacOS) ? '⌃' : 'Ctrl', 52 | KeyModifier.alt: (!kIsWeb && Platform.isMacOS) ? '⌥' : 'Alt', 53 | KeyModifier.meta: (!kIsWeb && Platform.isMacOS) ? '⌘' : '⊞', 54 | KeyModifier.fn: 'fn', 55 | }; 56 | 57 | @Deprecated( 58 | 'No longer supported, Use `HotKeyModifier` instead. ', 59 | ) 60 | enum KeyModifier { 61 | capsLock, 62 | shift, 63 | control, 64 | alt, // Alt / Option key 65 | meta, // Command / Win key 66 | fn, 67 | } 68 | 69 | extension KeyModifierParser on KeyModifier { 70 | static KeyModifier parse(String string) { 71 | return KeyModifier.values.firstWhere((e) => e.name == string); 72 | } 73 | 74 | static KeyModifier? fromModifierKey(ModifierKey modifierKey) { 75 | return _knownModifierKeys.entries 76 | .firstWhere((entry) => entry.value == modifierKey) 77 | .key; 78 | } 79 | 80 | ModifierKey get modifierKey { 81 | return _knownModifierKeys[this]!; 82 | } 83 | 84 | static KeyModifier? fromLogicalKey(LogicalKeyboardKey logicalKey) { 85 | List logicalKeyIdList = []; 86 | 87 | for (List item in _knownLogicalKeys.values) { 88 | logicalKeyIdList.addAll(item.map((e) => e.keyId).toList()); 89 | } 90 | if (!logicalKeyIdList.contains(logicalKey.keyId)) return null; 91 | 92 | return _knownLogicalKeys.entries 93 | .firstWhere( 94 | (entry) => entry.value.map((e) => e.keyId).contains(logicalKey.keyId), 95 | ) 96 | .key; 97 | } 98 | 99 | List get logicalKeys { 100 | return _knownLogicalKeys[this]!; 101 | } 102 | 103 | String get stringValue => name; 104 | 105 | String get keyLabel { 106 | return _knownKeyLabels[this] ?? name; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/extensions/keyboard_key.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter/foundation.dart'; 4 | import 'package:flutter/services.dart'; 5 | import 'package:uni_platform/uni_platform.dart'; 6 | 7 | final Map _knownKeyLabels = 8 | { 9 | PhysicalKeyboardKey.keyA: 'A', 10 | PhysicalKeyboardKey.keyB: 'B', 11 | PhysicalKeyboardKey.keyC: 'C', 12 | PhysicalKeyboardKey.keyD: 'D', 13 | PhysicalKeyboardKey.keyE: 'E', 14 | PhysicalKeyboardKey.keyF: 'F', 15 | PhysicalKeyboardKey.keyG: 'G', 16 | PhysicalKeyboardKey.keyH: 'H', 17 | PhysicalKeyboardKey.keyI: 'I', 18 | PhysicalKeyboardKey.keyJ: 'J', 19 | PhysicalKeyboardKey.keyK: 'K', 20 | PhysicalKeyboardKey.keyL: 'L', 21 | PhysicalKeyboardKey.keyM: 'M', 22 | PhysicalKeyboardKey.keyN: 'N', 23 | PhysicalKeyboardKey.keyO: 'O', 24 | PhysicalKeyboardKey.keyP: 'P', 25 | PhysicalKeyboardKey.keyQ: 'Q', 26 | PhysicalKeyboardKey.keyR: 'R', 27 | PhysicalKeyboardKey.keyS: 'S', 28 | PhysicalKeyboardKey.keyT: 'T', 29 | PhysicalKeyboardKey.keyU: 'U', 30 | PhysicalKeyboardKey.keyV: 'V', 31 | PhysicalKeyboardKey.keyW: 'W', 32 | PhysicalKeyboardKey.keyX: 'X', 33 | PhysicalKeyboardKey.keyY: 'Y', 34 | PhysicalKeyboardKey.keyZ: 'Z', 35 | PhysicalKeyboardKey.digit1: '1', 36 | PhysicalKeyboardKey.digit2: '2', 37 | PhysicalKeyboardKey.digit3: '3', 38 | PhysicalKeyboardKey.digit4: '4', 39 | PhysicalKeyboardKey.digit5: '5', 40 | PhysicalKeyboardKey.digit6: '6', 41 | PhysicalKeyboardKey.digit7: '7', 42 | PhysicalKeyboardKey.digit8: '8', 43 | PhysicalKeyboardKey.digit9: '9', 44 | PhysicalKeyboardKey.digit0: '0', 45 | PhysicalKeyboardKey.enter: '↩︎', 46 | PhysicalKeyboardKey.escape: '⎋', 47 | PhysicalKeyboardKey.backspace: '←', 48 | PhysicalKeyboardKey.tab: '⇥', 49 | PhysicalKeyboardKey.space: '␣', 50 | PhysicalKeyboardKey.minus: '-', 51 | PhysicalKeyboardKey.equal: '=', 52 | PhysicalKeyboardKey.bracketLeft: '[', 53 | PhysicalKeyboardKey.bracketRight: ']', 54 | PhysicalKeyboardKey.backslash: '\\', 55 | PhysicalKeyboardKey.semicolon: ';', 56 | PhysicalKeyboardKey.quote: '"', 57 | PhysicalKeyboardKey.backquote: '`', 58 | PhysicalKeyboardKey.comma: ',', 59 | PhysicalKeyboardKey.period: '.', 60 | PhysicalKeyboardKey.slash: '/', 61 | PhysicalKeyboardKey.capsLock: '⇪', 62 | PhysicalKeyboardKey.f1: 'F1', 63 | PhysicalKeyboardKey.f2: 'F2', 64 | PhysicalKeyboardKey.f3: 'F3', 65 | PhysicalKeyboardKey.f4: 'F4', 66 | PhysicalKeyboardKey.f5: 'F5', 67 | PhysicalKeyboardKey.f6: 'F6', 68 | PhysicalKeyboardKey.f7: 'F7', 69 | PhysicalKeyboardKey.f8: 'F8', 70 | PhysicalKeyboardKey.f9: 'F9', 71 | PhysicalKeyboardKey.f10: 'F10', 72 | PhysicalKeyboardKey.f11: 'F11', 73 | PhysicalKeyboardKey.f12: 'F12', 74 | PhysicalKeyboardKey.home: '↖', 75 | PhysicalKeyboardKey.pageUp: '⇞', 76 | PhysicalKeyboardKey.delete: '⌫', 77 | PhysicalKeyboardKey.end: '↘', 78 | PhysicalKeyboardKey.pageDown: '⇟', 79 | PhysicalKeyboardKey.arrowRight: '→', 80 | PhysicalKeyboardKey.arrowLeft: '←', 81 | PhysicalKeyboardKey.arrowDown: '↓', 82 | PhysicalKeyboardKey.arrowUp: '↑', 83 | PhysicalKeyboardKey.controlLeft: '⌃', 84 | PhysicalKeyboardKey.shiftLeft: '⇧', 85 | PhysicalKeyboardKey.altLeft: '⌥', 86 | PhysicalKeyboardKey.metaLeft: (!kIsWeb && Platform.isMacOS) ? '⌘' : '⊞', 87 | PhysicalKeyboardKey.controlRight: '⌃', 88 | PhysicalKeyboardKey.shiftRight: '⇧', 89 | PhysicalKeyboardKey.altRight: '⌥', 90 | PhysicalKeyboardKey.metaRight: (!kIsWeb && Platform.isMacOS) ? '⌘' : '⊞', 91 | PhysicalKeyboardKey.fn: 'fn', 92 | }; 93 | 94 | extension KeyboardKeyExt on KeyboardKey { 95 | String get keyLabel { 96 | PhysicalKeyboardKey? physicalKey; 97 | if (this is LogicalKeyboardKey) { 98 | physicalKey = (this as LogicalKeyboardKey).physicalKey; 99 | } else if (this is PhysicalKeyboardKey) { 100 | physicalKey = this as PhysicalKeyboardKey; 101 | } 102 | return _knownKeyLabels[physicalKey] ?? physicalKey?.debugName ?? 'Unknown'; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/hotkey.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 3 | import 'package:json_annotation/json_annotation.dart'; 4 | import 'package:uni_platform/uni_platform.dart'; 5 | import 'package:uuid/uuid.dart'; 6 | 7 | part 'hotkey.g.dart'; 8 | 9 | const _uuid = Uuid(); 10 | 11 | typedef HotKeyHandler = void Function(HotKey hotKey); 12 | 13 | enum HotKeyModifier { 14 | alt([ 15 | PhysicalKeyboardKey.altLeft, 16 | PhysicalKeyboardKey.altRight, 17 | ]), 18 | capsLock([ 19 | PhysicalKeyboardKey.capsLock, 20 | ]), 21 | control([ 22 | PhysicalKeyboardKey.controlLeft, 23 | PhysicalKeyboardKey.controlRight, 24 | ]), 25 | fn([ 26 | PhysicalKeyboardKey.fn, 27 | ]), 28 | meta([ 29 | PhysicalKeyboardKey.metaLeft, 30 | PhysicalKeyboardKey.metaRight, 31 | ]), 32 | shift([ 33 | PhysicalKeyboardKey.shiftLeft, 34 | PhysicalKeyboardKey.shiftRight, 35 | ]); 36 | 37 | const HotKeyModifier(this.physicalKeys); 38 | 39 | final List physicalKeys; 40 | 41 | bool get isModifierPressed { 42 | final physicalKeysPressed = HardwareKeyboard.instance.physicalKeysPressed; 43 | return physicalKeys.any(physicalKeysPressed.contains); 44 | } 45 | } 46 | 47 | enum HotKeyScope { 48 | system, 49 | inapp, 50 | } 51 | 52 | @JsonSerializable( 53 | converters: [_KeyboardKeyConverter()], 54 | ) 55 | class HotKey { 56 | HotKey({ 57 | String? identifier, 58 | required this.key, 59 | this.modifiers, 60 | this.scope = HotKeyScope.system, 61 | }) : identifier = identifier ?? _uuid.v4(); 62 | 63 | factory HotKey.fromJson(Map json) { 64 | if (json['keyCode'] is String) return _$HotKeyFromOldJson(json); 65 | return _$HotKeyFromJson(json); 66 | } 67 | 68 | final String identifier; 69 | final KeyboardKey key; 70 | final List? modifiers; 71 | final HotKeyScope scope; 72 | 73 | LogicalKeyboardKey get logicalKey { 74 | if (key is LogicalKeyboardKey) { 75 | return key as LogicalKeyboardKey; 76 | } else if (key is PhysicalKeyboardKey) { 77 | return (key as PhysicalKeyboardKey).logicalKey!; 78 | } 79 | throw PlatformException( 80 | code: 'invalid_keyboard_key', 81 | message: 'Invalid keyboard key', 82 | ); 83 | } 84 | 85 | PhysicalKeyboardKey get physicalKey { 86 | if (key is PhysicalKeyboardKey) { 87 | return key as PhysicalKeyboardKey; 88 | } else if (key is LogicalKeyboardKey) { 89 | return (key as LogicalKeyboardKey).physicalKey!; 90 | } 91 | throw PlatformException( 92 | code: 'invalid_keyboard_key', 93 | message: 'Invalid keyboard key', 94 | ); 95 | } 96 | 97 | String get debugName { 98 | return [ 99 | ...(modifiers ?? []).map((e) { 100 | final firstPhysicalKey = e.physicalKeys.first; 101 | return firstPhysicalKey.debugName; 102 | }), 103 | physicalKey.debugName, 104 | ].join(' + '); 105 | } 106 | 107 | Map toJson() => _$HotKeyToJson(this); 108 | } 109 | 110 | // Convert KeyboardKey to/from Map 111 | class _KeyboardKeyConverter 112 | extends JsonConverter> { 113 | const _KeyboardKeyConverter(); 114 | 115 | @override 116 | KeyboardKey fromJson(json) { 117 | final map = json.cast(); 118 | int? keyId = map['keyId']; 119 | int? usageCode = map['usageCode']; 120 | if (keyId != null) { 121 | final logicalKey = LogicalKeyboardKey.findKeyByKeyId(keyId); 122 | if (logicalKey != null) { 123 | return logicalKey; 124 | } 125 | } 126 | if (usageCode != null) { 127 | final physicalKey = PhysicalKeyboardKey.findKeyByCode(usageCode); 128 | if (physicalKey != null) { 129 | return physicalKey; 130 | } 131 | } 132 | throw PlatformException( 133 | code: 'invalid_keyboard_key', 134 | message: 'Invalid keyboard key', 135 | ); 136 | } 137 | 138 | @override 139 | Map toJson(KeyboardKey object) { 140 | int? keyId = object is LogicalKeyboardKey ? object.keyId : null; 141 | int? usageCode = object is PhysicalKeyboardKey ? object.usbHidUsage : null; 142 | return { 143 | 'keyId': keyId, 144 | 'usageCode': usageCode, 145 | }..removeWhere((key, value) => value == null); 146 | } 147 | } 148 | 149 | // Convert HotKey from old JSON format 150 | HotKey _$HotKeyFromOldJson(Map json) { 151 | LogicalKeyboardKey logicalKey = 152 | KeyCodeParser.parse(json['keyCode']).logicalKey; 153 | return HotKey( 154 | identifier: json['identifier'] as String, 155 | key: logicalKey.physicalKey!, 156 | modifiers: ((json['modifiers'] as List?) ?? []).map((modifier) { 157 | return HotKeyModifier.values.firstWhere((e) => e.name == modifier); 158 | }).toList(), 159 | scope: HotKeyScope.values.firstWhere( 160 | (e) => e.name == json['scope'] as String, 161 | orElse: () => HotKeyScope.system, 162 | ), 163 | ); 164 | } 165 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/hotkey.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'hotkey.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | HotKey _$HotKeyFromJson(Map json) => HotKey( 10 | identifier: json['identifier'] as String?, 11 | key: const _KeyboardKeyConverter().fromJson(json['key'] as Map), 12 | modifiers: (json['modifiers'] as List?) 13 | ?.map((e) => $enumDecode(_$HotKeyModifierEnumMap, e)) 14 | .toList(), 15 | scope: $enumDecodeNullable(_$HotKeyScopeEnumMap, json['scope']) ?? 16 | HotKeyScope.system, 17 | ); 18 | 19 | Map _$HotKeyToJson(HotKey instance) => { 20 | 'identifier': instance.identifier, 21 | 'key': const _KeyboardKeyConverter().toJson(instance.key), 22 | 'modifiers': 23 | instance.modifiers?.map((e) => _$HotKeyModifierEnumMap[e]!).toList(), 24 | 'scope': _$HotKeyScopeEnumMap[instance.scope]!, 25 | }; 26 | 27 | const _$HotKeyModifierEnumMap = { 28 | HotKeyModifier.alt: 'alt', 29 | HotKeyModifier.capsLock: 'capsLock', 30 | HotKeyModifier.control: 'control', 31 | HotKeyModifier.fn: 'fn', 32 | HotKeyModifier.meta: 'meta', 33 | HotKeyModifier.shift: 'shift', 34 | }; 35 | 36 | const _$HotKeyScopeEnumMap = { 37 | HotKeyScope.system: 'system', 38 | HotKeyScope.inapp: 'inapp', 39 | }; 40 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/hotkey_manager_method_channel.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:hotkey_manager_platform_interface/hotkey_manager_platform_interface.dart'; 4 | // ignore: implementation_imports 5 | import 'package:uni_platform/src/extensions/keyboard_key.dart'; 6 | 7 | /// An implementation of [HotKeyManagerPlatform] that uses method channels. 8 | class MethodChannelHotKeyManager extends HotKeyManagerPlatform { 9 | /// The method channel used to interact with the native platform. 10 | @visibleForTesting 11 | final methodChannel = const MethodChannel( 12 | 'dev.leanflutter.plugins/hotkey_manager', 13 | ); 14 | 15 | /// The event channel used to receive events from the native platform. 16 | @visibleForTesting 17 | final eventChannel = const EventChannel( 18 | 'dev.leanflutter.plugins/hotkey_manager_event', 19 | ); 20 | 21 | @override 22 | Stream> get onKeyEventReceiver { 23 | return eventChannel.receiveBroadcastStream().cast>(); 24 | } 25 | 26 | @override 27 | Future getPlatformVersion() async { 28 | final version = 29 | await methodChannel.invokeMethod('getPlatformVersion'); 30 | return version; 31 | } 32 | 33 | @override 34 | Future register(HotKey hotKey) async { 35 | await methodChannel.invokeMethod('register', { 36 | 'keyCode': hotKey.physicalKey.keyCode, 37 | ...hotKey.toJson(), 38 | }); 39 | } 40 | 41 | @override 42 | Future unregister(HotKey hotKey) async { 43 | await methodChannel.invokeMethod('unregister', { 44 | 'keyCode': hotKey.physicalKey.keyCode, 45 | ...hotKey.toJson(), 46 | }); 47 | } 48 | 49 | @override 50 | Future unregisterAll() async { 51 | await methodChannel.invokeMethod('unregisterAll'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/lib/src/hotkey_manager_platform_interface.dart: -------------------------------------------------------------------------------- 1 | import 'package:hotkey_manager_platform_interface/src/hotkey.dart'; 2 | import 'package:hotkey_manager_platform_interface/src/hotkey_manager_method_channel.dart'; 3 | import 'package:plugin_platform_interface/plugin_platform_interface.dart'; 4 | 5 | abstract class HotKeyManagerPlatform extends PlatformInterface { 6 | /// Constructs a HotKeyManagerPlatform. 7 | HotKeyManagerPlatform() : super(token: _token); 8 | 9 | static final Object _token = Object(); 10 | 11 | static HotKeyManagerPlatform _instance = MethodChannelHotKeyManager(); 12 | 13 | /// The default instance of [HotKeyManagerPlatform] to use. 14 | /// 15 | /// Defaults to [MethodChannelHotKeyManager]. 16 | static HotKeyManagerPlatform get instance => _instance; 17 | 18 | /// Platform-specific implementations should set this with their own 19 | /// platform-specific class that extends [HotKeyManagerPlatform] when 20 | /// they register themselves. 21 | static set instance(HotKeyManagerPlatform instance) { 22 | PlatformInterface.verifyToken(instance, _token); 23 | _instance = instance; 24 | } 25 | 26 | Future getPlatformVersion() { 27 | throw UnimplementedError('platformVersion() has not been implemented.'); 28 | } 29 | 30 | Stream> get onKeyEventReceiver { 31 | throw UnimplementedError('onKeyEventReceiver() has not been implemented.'); 32 | } 33 | 34 | Future register(HotKey hotKey) async { 35 | throw UnimplementedError('register() has not been implemented.'); 36 | } 37 | 38 | Future unregister(HotKey hotKey) { 39 | throw UnimplementedError('unregister() has not been implemented.'); 40 | } 41 | 42 | Future unregisterAll() async { 43 | throw UnimplementedError('unregisterAll() has not been implemented.'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_platform_interface 2 | description: A common platform interface for the hotkey_manager plugin. 3 | version: 0.2.0 4 | homepage: https://github.com/leanflutter/hotkey_manager/blob/main/packages/hotkey_manager_platform_interface 5 | 6 | environment: 7 | sdk: '>=3.0.0 <4.0.0' 8 | flutter: '>=3.3.0' 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | json_annotation: ^4.8.1 14 | plugin_platform_interface: ^2.1.8 15 | uni_platform: ^0.1.3 16 | uuid: '>=3.0.7 <5.0.0' 17 | 18 | dev_dependencies: 19 | build_runner: ^2.3.3 20 | flutter_test: 21 | sdk: flutter 22 | json_serializable: ^6.6.0 23 | mostly_reasonable_lints: ^0.1.1 24 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/test/src/hotkey_manager_method_channel_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:hotkey_manager_platform_interface/src/hotkey_manager_method_channel.dart'; 4 | 5 | void main() { 6 | TestWidgetsFlutterBinding.ensureInitialized(); 7 | 8 | MethodChannelHotKeyManager platform = MethodChannelHotKeyManager(); 9 | const MethodChannel channel = MethodChannel( 10 | 'dev.leanflutter.plugins/hotkey_manager', 11 | ); 12 | 13 | setUp(() { 14 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger 15 | .setMockMethodCallHandler( 16 | channel, 17 | (MethodCall methodCall) async { 18 | return '42'; 19 | }, 20 | ); 21 | }); 22 | 23 | tearDown(() { 24 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger 25 | .setMockMethodCallHandler(channel, null); 26 | }); 27 | 28 | test('getPlatformVersion', () async { 29 | expect(await platform.getPlatformVersion(), '42'); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /packages/hotkey_manager_platform_interface/test/src/hotkey_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter/services.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:hotkey_manager_platform_interface/src/hotkey.dart'; 6 | 7 | String oldHotKeyJson1 = 8 | '{"keyCode":"keyZ","modifiers":["meta","shift"],"identifier":"01","scope":"system"}'; 9 | String oldHotKeyJson2 = 10 | '{"keyCode":"keyA","modifiers":["alt","shift"],"identifier":"02","scope":"system"}'; 11 | String newHotKeyJson1 = 12 | '{"identifier":"01","key":{"usageCode":458781},"modifiers":["meta","shift"],"scope":"system"}'; 13 | String newHotKeyJson2 = 14 | '{"identifier":"02","key":{"usageCode":458756},"modifiers":["alt","shift"],"scope":"system"}'; 15 | 16 | void main() { 17 | test('should be compatible with old JSON', () async { 18 | final hotKey1 = HotKey.fromJson(json.decode(oldHotKeyJson1)); 19 | expect(hotKey1.key, PhysicalKeyboardKey.keyZ); 20 | expect(hotKey1.modifiers?.first, HotKeyModifier.meta); 21 | expect(hotKey1.modifiers?.last, HotKeyModifier.shift); 22 | final hotKey2 = HotKey.fromJson(json.decode(oldHotKeyJson2)); 23 | expect(hotKey2.key, PhysicalKeyboardKey.keyA); 24 | expect(hotKey2.modifiers?.first, HotKeyModifier.alt); 25 | expect(hotKey2.modifiers?.last, HotKeyModifier.shift); 26 | final newHotKey1 = HotKey.fromJson(json.decode(newHotKeyJson1)); 27 | expect(newHotKey1.key, PhysicalKeyboardKey.keyZ); 28 | expect(newHotKey1.modifiers?.first, HotKeyModifier.meta); 29 | expect(newHotKey1.modifiers?.last, HotKeyModifier.shift); 30 | final newHotKey2 = HotKey.fromJson(json.decode(newHotKeyJson2)); 31 | expect(newHotKey2.key, PhysicalKeyboardKey.keyA); 32 | expect(newHotKey2.modifiers?.first, HotKeyModifier.alt); 33 | expect(newHotKey2.modifiers?.last, HotKeyModifier.shift); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | build/ 30 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4" 8 | channel: "stable" 9 | 10 | project_type: plugin 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 17 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 18 | - platform: windows 19 | create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 20 | base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 2 | 3 | * First release. 4 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/README.md: -------------------------------------------------------------------------------- 1 | # hotkey_manager_windows 2 | 3 | [![pub version][pub-image]][pub-url] 4 | 5 | [pub-image]: https://img.shields.io/pub/v/hotkey_manager_windows.svg 6 | [pub-url]: https://pub.dev/packages/hotkey_manager_windows 7 | 8 | The Windows implementation of [hotkey_manager](https://pub.dev/packages/hotkey_manager). 9 | 10 | ## License 11 | 12 | [MIT](./LICENSE) 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/flutter.yaml 2 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_windows 2 | description: Windows implementation of the hotkey_manager plugin. 3 | version: 0.2.0 4 | repository: https://github.com/leanflutter/hotkey_manager/tree/main/packages/hotkey_manager_windows 5 | 6 | environment: 7 | sdk: '>=3.0.0 <4.0.0' 8 | flutter: '>=3.3.0' 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | hotkey_manager_platform_interface: ^0.2.0 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | mostly_reasonable_lints: ^0.1.1 19 | 20 | flutter: 21 | plugin: 22 | implements: hotkey_manager 23 | platforms: 24 | windows: 25 | pluginClass: HotkeyManagerWindowsPluginCApi 26 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The Flutter tooling requires that developers have a version of Visual Studio 2 | # installed that includes CMake 3.14 or later. You should not increase this 3 | # version, as doing so will cause the plugin to fail to compile for some 4 | # customers of the plugin. 5 | cmake_minimum_required(VERSION 3.14) 6 | 7 | # Project-level configuration. 8 | set(PROJECT_NAME "hotkey_manager_windows") 9 | project(${PROJECT_NAME} LANGUAGES CXX) 10 | 11 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 12 | # versions of CMake. 13 | cmake_policy(VERSION 3.14...3.25) 14 | 15 | # This value is used when generating builds using this plugin, so it must 16 | # not be changed 17 | set(PLUGIN_NAME "hotkey_manager_windows_plugin") 18 | 19 | # Any new source files that you add to the plugin should be added here. 20 | list(APPEND PLUGIN_SOURCES 21 | "hotkey_manager_windows_plugin.cpp" 22 | "hotkey_manager_windows_plugin.h" 23 | ) 24 | 25 | # Define the plugin library target. Its name must not be changed (see comment 26 | # on PLUGIN_NAME above). 27 | add_library(${PLUGIN_NAME} SHARED 28 | "include/hotkey_manager_windows/hotkey_manager_windows_plugin_c_api.h" 29 | "hotkey_manager_windows_plugin_c_api.cpp" 30 | ${PLUGIN_SOURCES} 31 | ) 32 | 33 | # Apply a standard set of build settings that are configured in the 34 | # application-level CMakeLists.txt. This can be removed for plugins that want 35 | # full control over build settings. 36 | apply_standard_settings(${PLUGIN_NAME}) 37 | 38 | # Symbols are hidden by default to reduce the chance of accidental conflicts 39 | # between plugins. This should not be removed; any symbols that should be 40 | # exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro. 41 | set_target_properties(${PLUGIN_NAME} PROPERTIES 42 | CXX_VISIBILITY_PRESET hidden) 43 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 44 | 45 | # Source include directories and library dependencies. Add any plugin-specific 46 | # dependencies here. 47 | target_include_directories(${PLUGIN_NAME} INTERFACE 48 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 49 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 50 | 51 | # List of absolute paths to libraries that should be bundled with the plugin. 52 | # This list could contain prebuilt libraries, or libraries created by an 53 | # external build triggered from this build file. 54 | set(hotkey_manager_windows_bundled_libraries 55 | "" 56 | PARENT_SCOPE 57 | ) 58 | 59 | # === Tests === 60 | # These unit tests can be run from a terminal after building the example, or 61 | # from Visual Studio after opening the generated solution file. 62 | 63 | # Only enable test builds when building the example (which sets this variable) 64 | # so that plugin clients aren't building the tests. 65 | if (${include_${PROJECT_NAME}_tests}) 66 | set(TEST_RUNNER "${PROJECT_NAME}_test") 67 | enable_testing() 68 | 69 | # Add the Google Test dependency. 70 | include(FetchContent) 71 | FetchContent_Declare( 72 | googletest 73 | URL https://github.com/google/googletest/archive/release-1.11.0.zip 74 | ) 75 | # Prevent overriding the parent project's compiler/linker settings 76 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 77 | # Disable install commands for gtest so it doesn't end up in the bundle. 78 | set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) 79 | FetchContent_MakeAvailable(googletest) 80 | 81 | # The plugin's C API is not very useful for unit testing, so build the sources 82 | # directly into the test binary rather than using the DLL. 83 | add_executable(${TEST_RUNNER} 84 | test/hotkey_manager_windows_plugin_test.cpp 85 | ${PLUGIN_SOURCES} 86 | ) 87 | apply_standard_settings(${TEST_RUNNER}) 88 | target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") 89 | target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin) 90 | target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) 91 | # flutter_wrapper_plugin has link dependencies on the Flutter DLL. 92 | add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD 93 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 94 | "${FLUTTER_LIBRARY}" $ 95 | ) 96 | 97 | # Enable automatic test discovery. 98 | include(GoogleTest) 99 | gtest_discover_tests(${TEST_RUNNER}) 100 | endif() 101 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/hotkey_manager_windows_plugin.cpp: -------------------------------------------------------------------------------- 1 | #include "hotkey_manager_windows_plugin.h" 2 | 3 | // This must be included before many other Windows headers. 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace hotkey_manager_windows { 14 | 15 | // static 16 | void HotkeyManagerWindowsPlugin::RegisterWithRegistrar( 17 | flutter::PluginRegistrarWindows* registrar) { 18 | auto channel = 19 | std::make_unique>( 20 | registrar->messenger(), "dev.leanflutter.plugins/hotkey_manager", 21 | &flutter::StandardMethodCodec::GetInstance()); 22 | 23 | auto plugin = std::make_unique(registrar); 24 | 25 | channel->SetMethodCallHandler( 26 | [plugin_pointer = plugin.get()](const auto& call, auto result) { 27 | plugin_pointer->HandleMethodCall(call, std::move(result)); 28 | }); 29 | 30 | auto event_channel = 31 | std::make_unique>( 32 | registrar->messenger(), 33 | "dev.leanflutter.plugins/hotkey_manager_event", 34 | &flutter::StandardMethodCodec::GetInstance()); 35 | auto streamHandler = std::make_unique>( 36 | [plugin_pointer = plugin.get()]( 37 | const flutter::EncodableValue* arguments, 38 | std::unique_ptr>&& events) 39 | -> std::unique_ptr> { 40 | return plugin_pointer->OnListen(arguments, std::move(events)); 41 | }, 42 | [plugin_pointer = plugin.get()](const flutter::EncodableValue* arguments) 43 | -> std::unique_ptr> { 44 | return plugin_pointer->OnCancel(arguments); 45 | }); 46 | event_channel->SetStreamHandler(std::move(streamHandler)); 47 | 48 | registrar->AddPlugin(std::move(plugin)); 49 | } 50 | 51 | HotkeyManagerWindowsPlugin::HotkeyManagerWindowsPlugin( 52 | flutter::PluginRegistrarWindows* registrar) { 53 | registrar_ = registrar; 54 | window_proc_id_ = registrar->RegisterTopLevelWindowProcDelegate( 55 | [this](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 56 | return HandleWindowProc(hwnd, message, wparam, lparam); 57 | }); 58 | } 59 | 60 | HotkeyManagerWindowsPlugin::~HotkeyManagerWindowsPlugin() {} 61 | 62 | std::optional HotkeyManagerWindowsPlugin::HandleWindowProc( 63 | HWND hwnd, 64 | UINT message, 65 | WPARAM wparam, 66 | LPARAM lparam) { 67 | switch (message) { 68 | case WM_HOTKEY: { 69 | int32_t hotkey_id = static_cast(wparam); 70 | for (const auto& [identifier, id] : hotkey_id_map_) { 71 | if (id == hotkey_id) { 72 | flutter::EncodableMap args = flutter::EncodableMap(); 73 | args[flutter::EncodableValue("type")] = "onKeyDown"; 74 | args[flutter::EncodableValue("data")] = 75 | flutter::EncodableMap({{"identifier", identifier}}); 76 | if (event_sink_) { 77 | event_sink_->Success(flutter::EncodableValue(args)); 78 | } 79 | break; 80 | } 81 | } 82 | } 83 | } 84 | return std::nullopt; 85 | } 86 | 87 | void HotkeyManagerWindowsPlugin::Register( 88 | const flutter::MethodCall& method_call, 89 | std::unique_ptr> result) { 90 | const flutter::EncodableMap& args = 91 | std::get(*method_call.arguments()); 92 | int key_code = std::get(args.at(flutter::EncodableValue("keyCode"))); 93 | std::vector modifiers; 94 | std::string identifier = 95 | std::get(args.at(flutter::EncodableValue("identifier"))); 96 | flutter::EncodableList key_modifier_list = std::get( 97 | args.at(flutter::EncodableValue("modifiers"))); 98 | for (flutter::EncodableValue key_modifier_value : key_modifier_list) { 99 | std::string key_modifier = std::get(key_modifier_value); 100 | modifiers.push_back(key_modifier); 101 | } 102 | int32_t hotkey_id = ++last_registered_hotkey_id_; 103 | UINT fs_modifiers = GetFsModifiersFromString(modifiers); 104 | ::RegisterHotKey( 105 | ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT), 106 | hotkey_id, fs_modifiers, key_code); 107 | hotkey_id_map_.insert(std::make_pair(identifier, hotkey_id)); 108 | result->Success(flutter::EncodableValue(true)); 109 | } 110 | 111 | void HotkeyManagerWindowsPlugin::Unregister( 112 | const flutter::MethodCall& method_call, 113 | std::unique_ptr> result) { 114 | const flutter::EncodableMap& args = 115 | std::get(*method_call.arguments()); 116 | std::string identifier = 117 | std::get(args.at(flutter::EncodableValue("identifier"))); 118 | int32_t hotkey_id = hotkey_id_map_.at(identifier); 119 | ::UnregisterHotKey( 120 | ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT), 121 | hotkey_id); 122 | hotkey_id_map_.erase(identifier); 123 | result->Success(flutter::EncodableValue(true)); 124 | } 125 | 126 | void HotkeyManagerWindowsPlugin::UnregisterAll( 127 | const flutter::MethodCall& method_call, 128 | std::unique_ptr> result) { 129 | for (auto it = hotkey_id_map_.begin(); it != hotkey_id_map_.end(); ++it) { 130 | std::string identifier = it->first; 131 | int32_t hotkey_id = it->second; 132 | ::UnregisterHotKey( 133 | ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT), 134 | hotkey_id); 135 | } 136 | hotkey_id_map_.clear(); 137 | result->Success(flutter::EncodableValue(true)); 138 | } 139 | 140 | UINT HotkeyManagerWindowsPlugin::GetFsModifiersFromString( 141 | const std::vector& modifiers) { 142 | UINT fs_modifiers = 0x0000; 143 | for (int32_t i = 0; i < modifiers.size(); i++) { 144 | UINT fs_modifier = 0x0000; 145 | if (modifiers[i] == "alt") { 146 | fs_modifier = MOD_ALT; 147 | } else if (modifiers[i] == "control") { 148 | fs_modifier = MOD_CONTROL; 149 | } else if (modifiers[i] == "meta") { 150 | fs_modifier = MOD_WIN; 151 | } else if (modifiers[i] == "shift") { 152 | fs_modifier = MOD_SHIFT; 153 | } 154 | fs_modifiers = fs_modifiers | fs_modifier; 155 | } 156 | return fs_modifiers; 157 | } 158 | 159 | void HotkeyManagerWindowsPlugin::HandleMethodCall( 160 | const flutter::MethodCall& method_call, 161 | std::unique_ptr> result) { 162 | if (method_call.method_name().compare("register") == 0) { 163 | Register(method_call, std::move(result)); 164 | } else if (method_call.method_name().compare("unregister") == 0) { 165 | Unregister(method_call, std::move(result)); 166 | } else if (method_call.method_name().compare("unregisterAll") == 0) { 167 | UnregisterAll(method_call, std::move(result)); 168 | } else { 169 | result->NotImplemented(); 170 | } 171 | } 172 | 173 | std::unique_ptr> 174 | HotkeyManagerWindowsPlugin::OnListenInternal( 175 | const flutter::EncodableValue* arguments, 176 | std::unique_ptr>&& events) { 177 | event_sink_ = std::move(events); 178 | return nullptr; 179 | } 180 | 181 | std::unique_ptr> 182 | HotkeyManagerWindowsPlugin::OnCancelInternal( 183 | const flutter::EncodableValue* arguments) { 184 | event_sink_ = nullptr; 185 | return nullptr; 186 | } 187 | 188 | } // namespace hotkey_manager_windows 189 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/hotkey_manager_windows_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace hotkey_manager_windows { 12 | 13 | class HotkeyManagerWindowsPlugin 14 | : public flutter::Plugin, 15 | flutter::StreamHandler { 16 | private: 17 | flutter::PluginRegistrarWindows* registrar_; 18 | std::unique_ptr> event_sink_; 19 | 20 | std::unordered_map hotkey_id_map_ = {}; 21 | int32_t last_registered_hotkey_id_ = 0; 22 | int32_t window_proc_id_ = -1; 23 | std::optional HandleWindowProc(HWND hwnd, 24 | UINT message, 25 | WPARAM wparam, 26 | LPARAM lparam); 27 | 28 | public: 29 | static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar); 30 | 31 | HotkeyManagerWindowsPlugin(flutter::PluginRegistrarWindows* registrar); 32 | 33 | virtual ~HotkeyManagerWindowsPlugin(); 34 | 35 | // Disallow copy and assign. 36 | HotkeyManagerWindowsPlugin(const HotkeyManagerWindowsPlugin&) = delete; 37 | HotkeyManagerWindowsPlugin& operator=(const HotkeyManagerWindowsPlugin&) = 38 | delete; 39 | 40 | void Register( 41 | const flutter::MethodCall& method_call, 42 | std::unique_ptr> result); 43 | void Unregister( 44 | const flutter::MethodCall& method_call, 45 | std::unique_ptr> result); 46 | void UnregisterAll( 47 | const flutter::MethodCall& method_call, 48 | std::unique_ptr> result); 49 | UINT GetVirtualKeyCodeFromString(const std::string key_code); 50 | UINT GetFsModifiersFromString(const std::vector& modifiers); 51 | 52 | // Called when a method is called on this plugin's channel from Dart. 53 | void HandleMethodCall( 54 | const flutter::MethodCall& method_call, 55 | std::unique_ptr> result); 56 | 57 | std::unique_ptr> OnListenInternal( 58 | const flutter::EncodableValue* arguments, 59 | std::unique_ptr>&& events) override; 60 | 61 | std::unique_ptr> OnCancelInternal( 62 | const flutter::EncodableValue* arguments) override; 63 | }; 64 | 65 | } // namespace hotkey_manager_windows 66 | 67 | #endif // FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_H_ 68 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/hotkey_manager_windows_plugin_c_api.cpp: -------------------------------------------------------------------------------- 1 | #include "include/hotkey_manager_windows/hotkey_manager_windows_plugin_c_api.h" 2 | 3 | #include 4 | 5 | #include "hotkey_manager_windows_plugin.h" 6 | 7 | void HotkeyManagerWindowsPluginCApiRegisterWithRegistrar( 8 | FlutterDesktopPluginRegistrarRef registrar) { 9 | hotkey_manager_windows::HotkeyManagerWindowsPlugin::RegisterWithRegistrar( 10 | flutter::PluginRegistrarManager::GetInstance() 11 | ->GetRegistrar(registrar)); 12 | } 13 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/include/hotkey_manager_windows/hotkey_manager_windows_plugin_c_api.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_C_API_H_ 2 | #define FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_C_API_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void HotkeyManagerWindowsPluginCApiRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_HOTKEY_MANAGER_WINDOWS_PLUGIN_C_API_H_ 24 | -------------------------------------------------------------------------------- /packages/hotkey_manager_windows/windows/test/hotkey_manager_windows_plugin_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "hotkey_manager_windows_plugin.h" 12 | 13 | namespace hotkey_manager_windows { 14 | namespace test { 15 | 16 | namespace { 17 | 18 | using flutter::EncodableMap; 19 | using flutter::EncodableValue; 20 | using flutter::MethodCall; 21 | using flutter::MethodResultFunctions; 22 | 23 | } // namespace 24 | 25 | TEST(HotkeyManagerWindowsPlugin, GetPlatformVersion) { 26 | HotkeyManagerWindowsPlugin plugin; 27 | // Save the reply value from the success callback. 28 | std::string result_string; 29 | plugin.HandleMethodCall( 30 | MethodCall("getPlatformVersion", std::make_unique()), 31 | std::make_unique>( 32 | [&result_string](const EncodableValue* result) { 33 | result_string = std::get(*result); 34 | }, 35 | nullptr, nullptr)); 36 | 37 | // Since the exact string varies by host, just ensure that it's a string 38 | // with the expected format. 39 | EXPECT_TRUE(result_string.rfind("Windows ", 0) == 0); 40 | } 41 | 42 | } // namespace test 43 | } // namespace hotkey_manager_windows 44 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hotkey_manager_workspace 2 | homepage: https://github.com/leanflutter/hotkey_manager 3 | publish_to: none 4 | 5 | environment: 6 | sdk: ">=3.0.0 <4.0.0" 7 | 8 | dev_dependencies: 9 | melos: ^6.2.0 10 | --------------------------------------------------------------------------------