├── .gitignore ├── README.md ├── assets └── img │ └── logo.jpg ├── usb_device ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example │ ├── .gitignore │ ├── .metadata │ ├── README.md │ ├── android │ │ ├── .gitignore │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ │ ├── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── kotlin │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── res │ │ │ │ │ ├── drawable-v21 │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── drawable │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── values-night │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values │ │ │ │ │ └── styles.xml │ │ │ │ └── profile │ │ │ │ └── AndroidManifest.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ └── gradle-wrapper.properties │ │ └── settings.gradle │ ├── ios │ │ ├── .gitignore │ │ ├── Flutter │ │ │ ├── AppFrameworkInfo.plist │ │ │ ├── Debug.xcconfig │ │ │ └── Release.xcconfig │ │ ├── Podfile │ │ ├── Runner.xcodeproj │ │ │ ├── project.pbxproj │ │ │ ├── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ │ └── WorkspaceSettings.xcsettings │ │ │ └── xcshareddata │ │ │ │ └── xcschemes │ │ │ │ └── Runner.xcscheme │ │ ├── Runner.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── Runner │ │ │ ├── AppDelegate.swift │ │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ │ └── LaunchImage.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ └── README.md │ │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ │ ├── Info.plist │ │ │ └── Runner-Bridging-Header.h │ ├── lib │ │ ├── main.dart │ │ ├── main_presenter.dart │ │ └── main_viewmodel.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 │ ├── pubspec.yaml │ ├── test │ │ └── widget_test.dart │ ├── web │ │ ├── favicon.png │ │ ├── icons │ │ │ ├── Icon-192.png │ │ │ └── Icon-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 │ │ ├── run_loop.cpp │ │ ├── run_loop.h │ │ ├── runner.exe.manifest │ │ ├── utils.cpp │ │ ├── utils.h │ │ ├── win32_window.cpp │ │ └── win32_window.h ├── lib │ └── usb_device.dart ├── pubspec.lock ├── pubspec.yaml └── test │ └── usb_device_test.dart ├── usb_device_platform_interface ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── lib │ ├── method_channel_usb_device.dart │ ├── models │ │ ├── configurations │ │ │ ├── usb_alternate_interface.dart │ │ │ ├── usb_configuration.dart │ │ │ ├── usb_device_info.dart │ │ │ ├── usb_endpoint.dart │ │ │ └── usb_interface.dart │ │ ├── param │ │ │ ├── device_filter.dart │ │ │ └── setup_param.dart │ │ └── transfer │ │ │ ├── response │ │ │ └── status_response.dart │ │ │ ├── usb_in_transfer_result.dart │ │ │ ├── usb_isochronous_in_transfer_result.dart │ │ │ ├── usb_isochronous_out_transfer_result.dart │ │ │ └── usb_out_transfer_result.dart │ └── usb_device_platform_interface.dart ├── pubspec.lock ├── pubspec.yaml └── test │ └── usb_device_platform_interface_test.dart └── usb_device_web ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── assets └── webusb.js ├── lib ├── import_js │ ├── import_js_library.dart │ └── import_js_library_web.dart └── usb_device_web.dart ├── pubspec.lock ├── pubspec.yaml └── test └── usb_device_web_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/ephemeral 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | web usb logo 3 |

4 |

5 | 6 |

7 | License: MIT 8 | pub dev usb_device 9 |

10 |
11 |
12 |
13 | 14 | ## 🚀  Overview 15 | 16 | **WebUSB** plugin provide access to USB devices from Flutter Web 💙 by using [**web usb official API**](https://wicg.github.io/webusb/). 17 | 18 | - 📱 Get device info with configuration. 19 | - 🔌 Pair a device with filter. 20 | - 📤 Send data to USB device. 21 | - 📥 Receive data from USB device. 22 | - 🎛️ Change USB device configuration. 23 | 24 | ## 💻  Platform Support 25 | 26 | | Android | iOS | MacOS | Web | Linux | Windows | 27 | | :-----: | :-: | :---: | :-: | :---: | :----: | 28 | | ➖ | ➖ | ➖ | ✔️ | ➖ | ➖ | 29 | 30 | ## 📖  Installation 31 | 32 | ### Install the package 33 | 34 | ```sh 35 | flutter pub add usb_device 36 | ``` 37 | 38 | ### Import the package 39 | 40 | ```dart 41 | import 'package:usb_device/usb_device.dart'; 42 | ``` 43 | 44 | ## 🚀  Get started 45 | 46 | - Import & instanciate the plugin. 47 | 48 | ```dart 49 | import 'package:usb_device/usb_device.dart'; 50 | 51 | final UsbDevice usbDevice = UsbDevice(); 52 | ``` 53 | 54 | - Common used methods. 55 | 56 | ```dart 57 | 58 | // get paired devices 59 | final pairedDevices = await usbDevice.pairedDevices; 60 | 61 | // pair a device 62 | final pairedDevice = await usbDevice.requestDevices([DeviceFilter(vendorId : 0x00, productId: 0x00)]); 63 | 64 | // get device's configurations 65 | List availableConfigurations = await usbDevice.getAvailableConfigurations(pairedDevice); 66 | 67 | // get device's info 68 | USBDeviceInfo deviceInfo = await usbDevice.getPairedDeviceInfo(pairedDevice); 69 | 70 | // start session 71 | await usbDevice.open(pairedDevice); 72 | 73 | // close session 74 | await usbDevice.close(pairedDevice); 75 | ``` 76 | 77 | ## 📚  Methods 78 | 79 | ## USB 80 | 81 | | Name | Description | Returned value | 82 | | ------------------------------------------ | ---------------------------------------------------- | ------------------------------ | 83 | | `pairedDevices` | Get paired attached devices | `Future>` | 84 | | `requestDevice(List filters)` | Pair a device with filter or not | `Future` | 85 | | `isSupported()` | Pair a device with filter or not | `Future` | 86 | | `open()` | Start a session | `Future` | 87 | | `close()` | Close a session | `Future` | 88 | | `claimInterface(dynamic device, int interfaceNumber)` | Claim an interface for exclusive access | `Future` | 89 | | `releaseInterface(dynamic device, int interfaceNumber)` | Release a claimed interface | `Future` | 90 | | `reset(dynamic device)` | Reset device | `Future` | 91 | | `selectConfiguration(dynamic device, int configurationValue)` | Select a specified configuration | `Future` | 92 | | `clearHalt(dynamic device, String direction, int endpointNumber)` | Returns a promise that resolves when a halt condition is cleared | `Future` | 93 | | `controlTransferIn(dynamic device, SetupParam setup, {int? length})` | Return result of a command | `Future` | 94 | | `controlTransferOut(dynamic device, SetupParam setup, {dynamic data})` | Send a command to device | `Future` | 95 | | `transferIn(dynamic device, int endpointNumber, int length)` | Return data from device | `Future` | 96 | | `transferOut(dynamic device, int endpointNumber, dynamic data)` | Send data to device | `Future` | 97 | | `isochronousTransferIn(dynamic device, int endpointNumber, List packetLengths)` | Resolves with a USBIsochronousInTransferResult when time sensitive information has been transmitted to (received by) the USB device | `Future` | 98 | | `isochronousTransferOut(dynamic device, int endpointNumber, List packetLengths)` | Resolves with a USBIsochronousOutTransferResult when time sensitive information has been transmitted from the USB device | `Future` | 99 | | `setOnConnectCallback(Function(dynamic) onConnect)` | Connect callback | `Future` | 100 | | `setOnDisconnectCallback(Function(dynamic) onDisconnect)` | Disconnect callback | `Future` | 101 | | `getSelectedConfiguration(dynamic pairedDevice)` | Get the selected configuration | `Future` | 102 | | `getAvailableConfigurations(dynamic pairedDevice)` | Get available device's configurations | `Future>` | 103 | | `getPairedDeviceInfo(dynamic pairedDevice)` | Get info of paired device | `Future` | 104 | 105 | ## 📣  Sponsor 106 | 107 | logo apparence io 108 |
109 |
110 | 111 | [Initiated and sponsored by Apparence.io.](https://apparence.io) 112 | 113 | ## 👥  Contribution 114 | 115 | Contributions are welcome. 116 | Contribute by creating a PR or create an issue 🎉. -------------------------------------------------------------------------------- /assets/img/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/assets/img/logo.jpg -------------------------------------------------------------------------------- /usb_device/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/ephemeral 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /usb_device/.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: package 11 | -------------------------------------------------------------------------------- /usb_device/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.2 2 | 3 | - Improve pub points 4 | 5 | ## 1.0.1 6 | 7 | - Improve readme 8 | 9 | ## 1.0.0 10 | 11 | - Improve readme 12 | - Update dependencies 13 | 14 | ## 0.0.7 15 | 16 | - fix bug JS 17 | 18 | ## 0.0.6 19 | 20 | - fix bug JS / dart mapping in release mode 21 | - Change version usb device web 22 | 23 | ## 0.0.5 24 | 25 | - fix bug onConnect/onDisconnect 26 | - Change version usb device web 27 | 28 | ## 0.0.4 29 | 30 | - Change version usb device web 31 | 32 | ## 0.0.3 33 | 34 | - Change readme 35 | 36 | ## 0.0.2 37 | 38 | - Add readme 39 | 40 | ## 0.0.1 41 | 42 | - First Release 43 | -------------------------------------------------------------------------------- /usb_device/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2021 Apparence 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /usb_device/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /usb_device/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: f4abaa0735eba4dfd8f33f73363911d63931fe03 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /usb_device/example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 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 | -------------------------------------------------------------------------------- /usb_device/example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | -------------------------------------------------------------------------------- /usb_device/example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 30 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | defaultConfig { 36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 37 | applicationId "com.example.example" 38 | minSdkVersion 16 39 | targetSdkVersion 30 40 | versionCode flutterVersionCode.toInteger() 41 | versionName flutterVersionName 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 59 | } 60 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 13 | 17 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /usb_device/example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /usb_device/example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /usb_device/example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /usb_device/example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip 7 | -------------------------------------------------------------------------------- /usb_device/example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /usb_device/example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/ephemeral/ 22 | Flutter/app.flx 23 | Flutter/app.zip 24 | Flutter/flutter_assets/ 25 | Flutter/flutter_export_environment.sh 26 | ServiceDefinitions.json 27 | Runner/GeneratedPluginRegistrant.* 28 | 29 | # Exceptions to above rules. 30 | !default.mode1v3 31 | !default.mode2v3 32 | !default.pbxuser 33 | !default.perspectivev3 34 | -------------------------------------------------------------------------------- /usb_device/example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /usb_device/example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /usb_device/example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /usb_device/example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /usb_device/example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /usb_device/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'main_presenter.dart'; 3 | import 'main_viewmodel.dart'; 4 | 5 | void main() { 6 | runApp(MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | // This widget is the root of your application. 11 | @override 12 | Widget build(BuildContext context) { 13 | return MaterialApp( 14 | title: 'Flutter Demo', 15 | theme: ThemeData( 16 | primarySwatch: Colors.blue, 17 | ), 18 | home: MainPage(), 19 | ); 20 | } 21 | } 22 | 23 | abstract class MainView { 24 | void refresh() {} 25 | 26 | void showToast(String message) {} 27 | } 28 | 29 | class MainPage extends StatefulWidget { 30 | MainPage({ 31 | Key? key, 32 | }); 33 | 34 | @override 35 | _MainPageState createState() => _MainPageState(); 36 | } 37 | 38 | class _MainPageState extends State implements MainView { 39 | bool _didInitState = false; 40 | late MainPresenter presenter; 41 | late MainViewModel? model; 42 | 43 | @override 44 | @mustCallSuper 45 | void didChangeDependencies() { 46 | if (!_didInitState) { 47 | afterViewInit(); 48 | _didInitState = true; 49 | } 50 | super.didChangeDependencies(); 51 | } 52 | 53 | @override 54 | void dispose() { 55 | this.presenter.dispose(); 56 | super.dispose(); 57 | } 58 | 59 | void initState() { 60 | super.initState(); 61 | this.presenter = MainPresenter( 62 | MainViewModel(), 63 | this, 64 | ).init(); 65 | this.model = this.presenter.viewModel; 66 | } 67 | 68 | void afterViewInit() { 69 | this.presenter.initServices(); 70 | this.presenter.loadData(); 71 | } 72 | 73 | @override 74 | Widget build(BuildContext context) { 75 | return Scaffold( 76 | appBar: AppBar( 77 | title: Text("WebUSB"), 78 | ), 79 | body: this.model!.isLoading 80 | ? Center(child: CircularProgressIndicator()) 81 | : Padding( 82 | padding: const EdgeInsets.all(10.0), 83 | child: Column( 84 | crossAxisAlignment: CrossAxisAlignment.start, 85 | mainAxisAlignment: MainAxisAlignment.start, 86 | children: [ 87 | Center( 88 | child: Text("Web USB supported: " + 89 | this.model!.isSupported.toString()), 90 | ), 91 | SizedBox(height: 20.0), 92 | if (this.model!.pairedDevice != null) 93 | this._buildPairedDeviceInfo() 94 | else 95 | this._buildRequestDeviceButton() 96 | ], 97 | ), 98 | ), 99 | floatingActionButton: AnimatedOpacity( 100 | child: FloatingActionButton( 101 | child: this.presenter.isDeviceOpen() 102 | ? Icon(Icons.close) 103 | : Icon(Icons.usb), 104 | tooltip: "Start session", 105 | onPressed: () { 106 | if (this.presenter.isDeviceOpen()) { 107 | this.presenter.closeSession(); 108 | } else { 109 | this.presenter.startSession(); 110 | } 111 | }, 112 | ), 113 | duration: Duration(milliseconds: 100), 114 | opacity: this.model!.fabIsVisible ? 1 : 0, 115 | ), 116 | ); 117 | } 118 | 119 | Widget _buildPairedDeviceInfo() { 120 | Map _deviceInfos = this.presenter.getPairedDeviceInfo(); 121 | return Expanded( 122 | child: Row( 123 | children: [ 124 | Container( 125 | width: 400, 126 | child: ListView( 127 | shrinkWrap: true, 128 | children: _deviceInfos.keys.map( 129 | (String property) { 130 | return Row( 131 | children: [ 132 | Container( 133 | padding: const EdgeInsets.only(right: 10.0), 134 | child: Text( 135 | property, 136 | style: const TextStyle( 137 | fontWeight: FontWeight.bold, 138 | ), 139 | ), 140 | ), 141 | Expanded( 142 | child: Container( 143 | padding: 144 | const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0), 145 | child: Text( 146 | '${_deviceInfos[property]}', 147 | maxLines: 10, 148 | overflow: TextOverflow.ellipsis, 149 | ), 150 | )), 151 | ], 152 | ); 153 | }, 154 | ).toList()), 155 | ), 156 | ], 157 | ), 158 | ); 159 | } 160 | 161 | Widget _buildRequestDeviceButton() { 162 | return ElevatedButton( 163 | onPressed: () { 164 | return this.model!.isLoading ? null : this.presenter.requestDevices(); 165 | }, 166 | child: const Text('Request Device'), 167 | ); 168 | } 169 | 170 | @override 171 | void refresh() => this.setState(() {}); 172 | 173 | @override 174 | void showToast(String message) { 175 | final scaffold = ScaffoldMessenger.of(context); 176 | scaffold.showSnackBar( 177 | SnackBar( 178 | content: Text(message), 179 | ), 180 | ); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /usb_device/example/lib/main_presenter.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'package:usb_device/usb_device.dart'; 4 | 5 | import 'main.dart'; 6 | import 'main_viewmodel.dart'; 7 | 8 | class MainPresenter { 9 | final MainViewModel viewModel; 10 | final MainView viewInterface; 11 | final UsbDevice _usbDevice = UsbDevice(); 12 | 13 | MainPresenter( 14 | this.viewModel, 15 | this.viewInterface, 16 | ); 17 | 18 | MainPresenter init() { 19 | this.viewModel.isLoading = true; 20 | this.viewModel.fabIsVisible = false; 21 | return this; 22 | } 23 | 24 | void initServices() async {} 25 | 26 | void loadData() async { 27 | this.viewModel.isLoading = true; 28 | this.viewModel.isSupported = await this._usbDevice.isSupported(); 29 | await this.getPairedDevice(); 30 | this.viewModel.isLoading = false; 31 | this.viewInterface.refresh(); 32 | } 33 | 34 | Future getPairedDevice() async { 35 | final devices = await this._usbDevice.pairedDevices; 36 | if (devices.length > 0) { 37 | this.viewModel.fabIsVisible = true; 38 | this.viewModel.pairedDevice = devices.first; 39 | } 40 | } 41 | 42 | Future startSession() async { 43 | if (this.viewModel.pairedDevice != null) { 44 | await this._usbDevice.open(this.viewModel.pairedDevice!); 45 | this.viewInterface.refresh(); 46 | } 47 | } 48 | 49 | Future closeSession() async { 50 | if (this.viewModel.pairedDevice != null) { 51 | await this._usbDevice.close(this.viewModel.pairedDevice!); 52 | this.viewInterface.refresh(); 53 | } 54 | } 55 | 56 | void requestDevices() async { 57 | this.viewModel.pairedDevice = await this._usbDevice.requestDevices([]); 58 | this.viewModel.fabIsVisible = true; 59 | this.viewInterface.refresh(); 60 | } 61 | 62 | Map getPairedDeviceInfo() { 63 | var pairedDevice = this.viewModel.pairedDevice; 64 | final USBConfiguration? currentConfiguration = 65 | getProperty(pairedDevice, 'configuration') == null 66 | ? null 67 | : _getCurrentUSBConfigurationInfo( 68 | getProperty(pairedDevice, 'configuration')); 69 | final List configurations = 70 | _getAvailableUSBConfigurations( 71 | getProperty(pairedDevice, 'configurations')); 72 | 73 | try { 74 | return { 75 | 'usbVersionMajor': getProperty(pairedDevice, 'usbVersionMajor'), 76 | 'usbVersionMinor': getProperty(pairedDevice, 'usbVersionMinor'), 77 | 'usbVersionSubminor': getProperty(pairedDevice, 'usbVersionSubminor'), 78 | 'deviceClass': getProperty(pairedDevice, 'deviceClass'), 79 | 'deviceSubclass': getProperty(pairedDevice, 'deviceSubclass'), 80 | 'deviceProtocol': getProperty(pairedDevice, 'deviceProtocol'), 81 | 'vendorId': getProperty(pairedDevice, 'vendorId'), 82 | 'productId': getProperty(pairedDevice, 'productId'), 83 | 'deviceVersionMajor': getProperty(pairedDevice, 'deviceVersionMajor'), 84 | 'deviceVersionMinor': getProperty(pairedDevice, 'deviceVersionMinor'), 85 | 'deviceVersionSubminor': 86 | getProperty(pairedDevice, 'deviceVersionSubminor'), 87 | 'manufacturerName': getProperty(pairedDevice, 'manufacturerName'), 88 | 'productName': getProperty(pairedDevice, 'productName'), 89 | 'serialNumber': getProperty(pairedDevice, 'serialNumber'), 90 | 'opened': getProperty(pairedDevice, 'opened'), 91 | 'configurations': configurations, 92 | 'actualConfiguration': currentConfiguration.toString() 93 | }; 94 | } catch (e) { 95 | return {'Error:': 'Failed to get paired device info.'}; 96 | } 97 | } 98 | 99 | List _getAvailableUSBConfigurations( 100 | List configurations) { 101 | return configurations 102 | .map((e) => USBConfiguration.fromConfiguration(e)) 103 | .toList(); 104 | } 105 | 106 | USBConfiguration _getCurrentUSBConfigurationInfo(dynamic configuration) { 107 | return USBConfiguration.fromConfiguration(configuration); 108 | } 109 | 110 | bool isDeviceOpen() { 111 | var pairedDevice = this.viewModel.pairedDevice; 112 | if (pairedDevice != null) { 113 | return getProperty(pairedDevice, 'opened'); 114 | } 115 | return false; 116 | } 117 | 118 | void dispose() {} 119 | } 120 | -------------------------------------------------------------------------------- /usb_device/example/lib/main_viewmodel.dart: -------------------------------------------------------------------------------- 1 | class MainViewModel { 2 | late bool isLoading; 3 | late bool isSupported; 4 | late bool fabIsVisible; 5 | dynamic pairedDevice; 6 | MainViewModel(); 7 | } 8 | -------------------------------------------------------------------------------- /usb_device/example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /usb_device/example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(runner LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "example") 5 | set(APPLICATION_ID "com.example.example") 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 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } 47 | else { 48 | gtk_window_set_title(window, "example"); 49 | } 50 | 51 | gtk_window_set_default_size(window, 1280, 720); 52 | gtk_widget_show(GTK_WIDGET(window)); 53 | 54 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 55 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 56 | 57 | FlView* view = fl_view_new(project); 58 | gtk_widget_show(GTK_WIDGET(view)); 59 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 60 | 61 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 62 | 63 | gtk_widget_grab_focus(GTK_WIDGET(view)); 64 | } 65 | 66 | // Implements GApplication::local_command_line. 67 | static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) { 68 | MyApplication* self = MY_APPLICATION(application); 69 | // Strip out the first argument as it is the binary name. 70 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 71 | 72 | g_autoptr(GError) error = nullptr; 73 | if (!g_application_register(application, nullptr, &error)) { 74 | g_warning("Failed to register: %s", error->message); 75 | *exit_status = 1; 76 | return TRUE; 77 | } 78 | 79 | g_application_activate(application); 80 | *exit_status = 0; 81 | 82 | return TRUE; 83 | } 84 | 85 | // Implements GObject::dispose. 86 | static void my_application_dispose(GObject *object) { 87 | MyApplication* self = MY_APPLICATION(object); 88 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 89 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 90 | } 91 | 92 | static void my_application_class_init(MyApplicationClass* klass) { 93 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 94 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 95 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 96 | } 97 | 98 | static void my_application_init(MyApplication* self) {} 99 | 100 | MyApplication* my_application_new() { 101 | return MY_APPLICATION(g_object_new(my_application_get_type(), 102 | "application-id", APPLICATION_ID, 103 | "flags", G_APPLICATION_NON_UNIQUE, 104 | nullptr)); 105 | } 106 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/xcuserdata/ 7 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /usb_device/example/macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.11' 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 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /usb_device/example/macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FlutterMacOS (1.0.0) 3 | 4 | DEPENDENCIES: 5 | - FlutterMacOS (from `Flutter/ephemeral`) 6 | 7 | EXTERNAL SOURCES: 8 | FlutterMacOS: 9 | :path: Flutter/ephemeral 10 | 11 | SPEC CHECKSUMS: 12 | FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 13 | 14 | PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c 15 | 16 | COCOAPODS: 1.10.0.rc.1 17 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/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 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 64 | 65 | 71 | 73 | 79 | 80 | 81 | 82 | 84 | 85 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /usb_device/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 = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 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 | -------------------------------------------------------------------------------- /usb_device/example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /usb_device/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | publish_to: none 4 | 5 | # The following line prevents the package from being accidentally published to 6 | # pub.dev using `pub publish`. This is preferred for private packages. 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: ">=2.17.3 <3.0.0" 22 | 23 | dependencies: 24 | flutter: 25 | sdk: flutter 26 | usb_device: 27 | path: ../ 28 | 29 | 30 | # The following adds the Cupertino Icons font to your application. 31 | # Use with the CupertinoIcons class for iOS style icons. 32 | cupertino_icons: ^1.0.5 33 | 34 | dev_dependencies: 35 | flutter_test: 36 | sdk: flutter 37 | 38 | # For information on the generic Dart part of this file, see the 39 | # following page: https://dart.dev/tools/pub/pubspec 40 | 41 | # The following section is specific to Flutter. 42 | flutter: 43 | 44 | # The following line ensures that the Material Icons font is 45 | # included with your application, so that you can use the icons in 46 | # the material Icons class. 47 | uses-material-design: true 48 | 49 | # To add assets to your application, add an assets section, like this: 50 | # assets: 51 | # - images/a_dot_burr.jpeg 52 | # - images/a_dot_ham.jpeg 53 | 54 | # An image asset can refer to one or more resolution-specific "variants", see 55 | # https://flutter.dev/assets-and-images/#resolution-aware. 56 | 57 | # For details regarding adding assets from package dependencies, see 58 | # https://flutter.dev/assets-and-images/#from-packages 59 | 60 | # To add custom fonts to your application, add a fonts section here, 61 | # in this "flutter" section. Each entry in this list should have a 62 | # "family" key with the font family name, and a "fonts" key with a 63 | # list giving the asset and other descriptors for the font. For 64 | # example: 65 | # fonts: 66 | # - family: Schyler 67 | # fonts: 68 | # - asset: fonts/Schyler-Regular.ttf 69 | # - asset: fonts/Schyler-Italic.ttf 70 | # style: italic 71 | # - family: Trajan Pro 72 | # fonts: 73 | # - asset: fonts/TrajanPro.ttf 74 | # - asset: fonts/TrajanPro_Bold.ttf 75 | # weight: 700 76 | # 77 | # For details regarding fonts from package dependencies, 78 | # see https://flutter.dev/custom-fonts/#from-packages 79 | -------------------------------------------------------------------------------- /usb_device/example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:example/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /usb_device/example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/web/favicon.png -------------------------------------------------------------------------------- /usb_device/example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /usb_device/example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /usb_device/example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | example 27 | 28 | 29 | 30 | 31 | 32 | 35 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /usb_device/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 | } 24 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(example LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "example") 5 | 6 | cmake_policy(SET CMP0063 NEW) 7 | 8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 9 | 10 | # Configure build options. 11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 12 | if(IS_MULTICONFIG) 13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 14 | CACHE STRING "" FORCE) 15 | else() 16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 17 | set(CMAKE_BUILD_TYPE "Debug" CACHE 18 | STRING "Flutter build mode" FORCE) 19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 20 | "Debug" "Profile" "Release") 21 | endif() 22 | endif() 23 | 24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 28 | 29 | # Use Unicode for all projects. 30 | add_definitions(-DUNICODE -D_UNICODE) 31 | 32 | # Compilation settings that should be applied to most targets. 33 | function(APPLY_STANDARD_SETTINGS TARGET) 34 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 36 | target_compile_options(${TARGET} PRIVATE /EHsc) 37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 39 | endfunction() 40 | 41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 42 | 43 | # Flutter library and tool build rules. 44 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 45 | 46 | # Application build 47 | add_subdirectory("runner") 48 | 49 | # Generated plugin build rules, which manage building the plugins and adding 50 | # them to the application. 51 | include(flutter/generated_plugins.cmake) 52 | 53 | 54 | # === Installation === 55 | # Support files are copied into place next to the executable, so that it can 56 | # run in place. This is done instead of making a separate bundle (as on Linux) 57 | # so that building and running from within Visual Studio will work. 58 | set(BUILD_BUNDLE_DIR "$") 59 | # Make the "install" step default, as it's required to run. 60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 63 | endif() 64 | 65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 67 | 68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 69 | COMPONENT Runtime) 70 | 71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 72 | COMPONENT Runtime) 73 | 74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 75 | COMPONENT Runtime) 76 | 77 | if(PLUGIN_BUNDLED_LIBRARIES) 78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 80 | COMPONENT Runtime) 81 | endif() 82 | 83 | # Fully re-copy the assets directory on each build to avoid having stale files 84 | # from a previous install. 85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 86 | install(CODE " 87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 88 | " COMPONENT Runtime) 89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 91 | 92 | # Install the AOT library on non-Debug builds only. 93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 94 | CONFIGURATIONS Profile;Release 95 | COMPONENT Runtime) 96 | -------------------------------------------------------------------------------- /usb_device/example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 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 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 11 | 12 | # === Flutter Library === 13 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 14 | 15 | # Published to parent scope for install step. 16 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 17 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 18 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 19 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 20 | 21 | list(APPEND FLUTTER_LIBRARY_HEADERS 22 | "flutter_export.h" 23 | "flutter_windows.h" 24 | "flutter_messenger.h" 25 | "flutter_plugin_registrar.h" 26 | "flutter_texture_registrar.h" 27 | ) 28 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 29 | add_library(flutter INTERFACE) 30 | target_include_directories(flutter INTERFACE 31 | "${EPHEMERAL_DIR}" 32 | ) 33 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 34 | add_dependencies(flutter flutter_assemble) 35 | 36 | # === Wrapper === 37 | list(APPEND CPP_WRAPPER_SOURCES_CORE 38 | "core_implementations.cc" 39 | "standard_codec.cc" 40 | ) 41 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 42 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 43 | "plugin_registrar.cc" 44 | ) 45 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 46 | list(APPEND CPP_WRAPPER_SOURCES_APP 47 | "flutter_engine.cc" 48 | "flutter_view_controller.cc" 49 | ) 50 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 51 | 52 | # Wrapper sources needed for a plugin. 53 | add_library(flutter_wrapper_plugin STATIC 54 | ${CPP_WRAPPER_SOURCES_CORE} 55 | ${CPP_WRAPPER_SOURCES_PLUGIN} 56 | ) 57 | apply_standard_settings(flutter_wrapper_plugin) 58 | set_target_properties(flutter_wrapper_plugin PROPERTIES 59 | POSITION_INDEPENDENT_CODE ON) 60 | set_target_properties(flutter_wrapper_plugin PROPERTIES 61 | CXX_VISIBILITY_PRESET hidden) 62 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 63 | target_include_directories(flutter_wrapper_plugin PUBLIC 64 | "${WRAPPER_ROOT}/include" 65 | ) 66 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 67 | 68 | # Wrapper sources needed for the runner. 69 | add_library(flutter_wrapper_app STATIC 70 | ${CPP_WRAPPER_SOURCES_CORE} 71 | ${CPP_WRAPPER_SOURCES_APP} 72 | ) 73 | apply_standard_settings(flutter_wrapper_app) 74 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 75 | target_include_directories(flutter_wrapper_app PUBLIC 76 | "${WRAPPER_ROOT}/include" 77 | ) 78 | add_dependencies(flutter_wrapper_app flutter_assemble) 79 | 80 | # === Flutter tool backend === 81 | # _phony_ is a non-existent file to force this command to run every time, 82 | # since currently there's no way to get a full input/output list from the 83 | # flutter tool. 84 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 85 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 86 | add_custom_command( 87 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 88 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 89 | ${CPP_WRAPPER_SOURCES_APP} 90 | ${PHONY_OUTPUT} 91 | COMMAND ${CMAKE_COMMAND} -E env 92 | ${FLUTTER_TOOL_ENVIRONMENT} 93 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 94 | windows-x64 $ 95 | VERBATIM 96 | ) 97 | add_custom_target(flutter_assemble DEPENDS 98 | "${FLUTTER_LIBRARY}" 99 | ${FLUTTER_LIBRARY_HEADERS} 100 | ${CPP_WRAPPER_SOURCES_CORE} 101 | ${CPP_WRAPPER_SOURCES_PLUGIN} 102 | ${CPP_WRAPPER_SOURCES_APP} 103 | ) 104 | -------------------------------------------------------------------------------- /usb_device/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 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /usb_device/example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "run_loop.cpp" 8 | "utils.cpp" 9 | "win32_window.cpp" 10 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 11 | "Runner.rc" 12 | "runner.exe.manifest" 13 | ) 14 | apply_standard_settings(${BINARY_NAME}) 15 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 16 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 17 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 18 | add_dependencies(${BINARY_NAME} flutter_assemble) 19 | -------------------------------------------------------------------------------- /usb_device/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 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 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", "A new Flutter project." "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "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 | -------------------------------------------------------------------------------- /usb_device/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(RunLoop* run_loop, 8 | const flutter::DartProject& project) 9 | : run_loop_(run_loop), project_(project) {} 10 | 11 | FlutterWindow::~FlutterWindow() {} 12 | 13 | bool FlutterWindow::OnCreate() { 14 | if (!Win32Window::OnCreate()) { 15 | return false; 16 | } 17 | 18 | RECT frame = GetClientArea(); 19 | 20 | // The size here must match the window dimensions to avoid unnecessary surface 21 | // creation / destruction in the startup path. 22 | flutter_controller_ = std::make_unique( 23 | frame.right - frame.left, frame.bottom - frame.top, project_); 24 | // Ensure that basic setup of the controller was successful. 25 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 26 | return false; 27 | } 28 | RegisterPlugins(flutter_controller_->engine()); 29 | run_loop_->RegisterFlutterInstance(flutter_controller_->engine()); 30 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 31 | return true; 32 | } 33 | 34 | void FlutterWindow::OnDestroy() { 35 | if (flutter_controller_) { 36 | run_loop_->UnregisterFlutterInstance(flutter_controller_->engine()); 37 | flutter_controller_ = nullptr; 38 | } 39 | 40 | Win32Window::OnDestroy(); 41 | } 42 | 43 | LRESULT 44 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 45 | WPARAM const wparam, 46 | LPARAM const lparam) noexcept { 47 | // Give Flutter, including plugins, an opportunity to handle window messages. 48 | if (flutter_controller_) { 49 | std::optional result = 50 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 51 | lparam); 52 | if (result) { 53 | return *result; 54 | } 55 | } 56 | 57 | switch (message) { 58 | case WM_FONTCHANGE: 59 | flutter_controller_->engine()->ReloadSystemFonts(); 60 | break; 61 | } 62 | 63 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 64 | } 65 | -------------------------------------------------------------------------------- /usb_device/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 "run_loop.h" 10 | #include "win32_window.h" 11 | 12 | // A window that does nothing but host a Flutter view. 13 | class FlutterWindow : public Win32Window { 14 | public: 15 | // Creates a new FlutterWindow driven by the |run_loop|, hosting a 16 | // Flutter view running |project|. 17 | explicit FlutterWindow(RunLoop* run_loop, 18 | const flutter::DartProject& project); 19 | virtual ~FlutterWindow(); 20 | 21 | protected: 22 | // Win32Window: 23 | bool OnCreate() override; 24 | void OnDestroy() override; 25 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 26 | LPARAM const lparam) noexcept override; 27 | 28 | private: 29 | // The run loop driving events for this window. 30 | RunLoop* run_loop_; 31 | 32 | // The project to run. 33 | flutter::DartProject project_; 34 | 35 | // The Flutter instance hosted by this window. 36 | std::unique_ptr flutter_controller_; 37 | }; 38 | 39 | #endif // RUNNER_FLUTTER_WINDOW_H_ 40 | -------------------------------------------------------------------------------- /usb_device/example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "run_loop.h" 7 | #include "utils.h" 8 | 9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 10 | _In_ wchar_t *command_line, _In_ int show_command) { 11 | // Attach to console when present (e.g., 'flutter run') or create a 12 | // new console when running with a debugger. 13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 14 | CreateAndAttachConsole(); 15 | } 16 | 17 | // Initialize COM, so that it is available for use in the library and/or 18 | // plugins. 19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 20 | 21 | RunLoop run_loop; 22 | 23 | flutter::DartProject project(L"data"); 24 | 25 | std::vector command_line_arguments = 26 | GetCommandLineArguments(); 27 | 28 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 29 | 30 | FlutterWindow window(&run_loop, project); 31 | Win32Window::Point origin(10, 10); 32 | Win32Window::Size size(1280, 720); 33 | if (!window.CreateAndShow(L"example", origin, size)) { 34 | return EXIT_FAILURE; 35 | } 36 | window.SetQuitOnClose(true); 37 | 38 | run_loop.Run(); 39 | 40 | ::CoUninitialize(); 41 | return EXIT_SUCCESS; 42 | } 43 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apparence-io/webUSB_plugin/1b27233c7634ba0c69489459dd289f4ab2f5e106/usb_device/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /usb_device/example/windows/runner/run_loop.cpp: -------------------------------------------------------------------------------- 1 | #include "run_loop.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | RunLoop::RunLoop() {} 8 | 9 | RunLoop::~RunLoop() {} 10 | 11 | void RunLoop::Run() { 12 | bool keep_running = true; 13 | TimePoint next_flutter_event_time = TimePoint::clock::now(); 14 | while (keep_running) { 15 | std::chrono::nanoseconds wait_duration = 16 | std::max(std::chrono::nanoseconds(0), 17 | next_flutter_event_time - TimePoint::clock::now()); 18 | ::MsgWaitForMultipleObjects( 19 | 0, nullptr, FALSE, static_cast(wait_duration.count() / 1000), 20 | QS_ALLINPUT); 21 | bool processed_events = false; 22 | MSG message; 23 | // All pending Windows messages must be processed; MsgWaitForMultipleObjects 24 | // won't return again for items left in the queue after PeekMessage. 25 | while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) { 26 | processed_events = true; 27 | if (message.message == WM_QUIT) { 28 | keep_running = false; 29 | break; 30 | } 31 | ::TranslateMessage(&message); 32 | ::DispatchMessage(&message); 33 | // Allow Flutter to process messages each time a Windows message is 34 | // processed, to prevent starvation. 35 | next_flutter_event_time = 36 | std::min(next_flutter_event_time, ProcessFlutterMessages()); 37 | } 38 | // If the PeekMessage loop didn't run, process Flutter messages. 39 | if (!processed_events) { 40 | next_flutter_event_time = 41 | std::min(next_flutter_event_time, ProcessFlutterMessages()); 42 | } 43 | } 44 | } 45 | 46 | void RunLoop::RegisterFlutterInstance( 47 | flutter::FlutterEngine* flutter_instance) { 48 | flutter_instances_.insert(flutter_instance); 49 | } 50 | 51 | void RunLoop::UnregisterFlutterInstance( 52 | flutter::FlutterEngine* flutter_instance) { 53 | flutter_instances_.erase(flutter_instance); 54 | } 55 | 56 | RunLoop::TimePoint RunLoop::ProcessFlutterMessages() { 57 | TimePoint next_event_time = TimePoint::max(); 58 | for (auto instance : flutter_instances_) { 59 | std::chrono::nanoseconds wait_duration = instance->ProcessMessages(); 60 | if (wait_duration != std::chrono::nanoseconds::max()) { 61 | next_event_time = 62 | std::min(next_event_time, TimePoint::clock::now() + wait_duration); 63 | } 64 | } 65 | return next_event_time; 66 | } 67 | -------------------------------------------------------------------------------- /usb_device/example/windows/runner/run_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_RUN_LOOP_H_ 2 | #define RUNNER_RUN_LOOP_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | // A runloop that will service events for Flutter instances as well 10 | // as native messages. 11 | class RunLoop { 12 | public: 13 | RunLoop(); 14 | ~RunLoop(); 15 | 16 | // Prevent copying 17 | RunLoop(RunLoop const&) = delete; 18 | RunLoop& operator=(RunLoop const&) = delete; 19 | 20 | // Runs the run loop until the application quits. 21 | void Run(); 22 | 23 | // Registers the given Flutter instance for event servicing. 24 | void RegisterFlutterInstance( 25 | flutter::FlutterEngine* flutter_instance); 26 | 27 | // Unregisters the given Flutter instance from event servicing. 28 | void UnregisterFlutterInstance( 29 | flutter::FlutterEngine* flutter_instance); 30 | 31 | private: 32 | using TimePoint = std::chrono::steady_clock::time_point; 33 | 34 | // Processes all currently pending messages for registered Flutter instances. 35 | TimePoint ProcessFlutterMessages(); 36 | 37 | std::set flutter_instances_; 38 | }; 39 | 40 | #endif // RUNNER_RUN_LOOP_H_ 41 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/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 | if (target_length == 0) { 52 | return std::string(); 53 | } 54 | std::string utf8_string; 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /usb_device/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 | -------------------------------------------------------------------------------- /usb_device/example/windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | -------------------------------------------------------------------------------- /usb_device/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 and shows a win32 window with |title| and position and size 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 to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /usb_device/lib/usb_device.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:usb_device_platform_interface/usb_device_platform_interface.dart'; 4 | 5 | export 'package:usb_device_platform_interface/usb_device_platform_interface.dart'; 6 | 7 | class UsbDevice { 8 | /// Constructs a singleton instance of [UsbDeviceService]. 9 | /// 10 | /// [UsbDeviceService] is designed to work as a singleton. 11 | factory UsbDevice() { 12 | _singleton ??= UsbDevice._(); 13 | return _singleton!; 14 | } 15 | 16 | UsbDevice._(); 17 | 18 | static UsbDevice? _singleton; 19 | 20 | static UsbDevicePlatform get _platform { 21 | return UsbDevicePlatform.instance; 22 | } 23 | 24 | /// Get paired devices 25 | Future> get pairedDevices { 26 | return _platform.pairedDevices; 27 | } 28 | 29 | /// Return true if web usb supported 30 | Future isSupported() { 31 | return _platform.isSupported(); 32 | } 33 | 34 | /// Pair a device 35 | Future requestDevices(List filters) { 36 | return _platform.requestDevices(filters); 37 | } 38 | 39 | /// set on connect function callback 40 | Future setOnConnectionCallback(Function(dynamic) onConnect) async { 41 | return _platform.setOnConnectCallback((device) => onConnect(device)); 42 | } 43 | 44 | /// Set on disconnect function callback 45 | Future setOnDisconnectCallback(Function(dynamic) onDisconnect) async { 46 | return _platform.setOnDisconnectCallback((device) => onDisconnect(device)); 47 | } 48 | 49 | /// get device's info like productId, vendorId, USB version etc.. 50 | Future getPairedDeviceInfo(dynamic pairedDevice) { 51 | return _platform.getPairedDeviceInfo(pairedDevice); 52 | } 53 | 54 | /// Get available configuration in device 55 | Future> getAvailableConfigurations( 56 | dynamic pairedDevice) { 57 | return _platform.getAvailableConfigurations(pairedDevice); 58 | } 59 | 60 | /// get selected configuration of paired device 61 | Future getSelectedConfiguration(dynamic pairedDevice) { 62 | return _platform.getSelectedConfiguration(pairedDevice); 63 | } 64 | 65 | /// Start session with the device 66 | Future open(dynamic device) { 67 | return _platform.open(device); 68 | } 69 | 70 | /// close session with the device 71 | Future close(dynamic device) { 72 | return _platform.close(device); 73 | } 74 | 75 | /// Claims the interface of the device 76 | Future claimInterface(dynamic device, int interfaceNumber) { 77 | return _platform.claimInterface(device, interfaceNumber); 78 | } 79 | 80 | /// Release interface 81 | Future releaseInterface(dynamic device, int interfaceNumber) { 82 | return _platform.releaseInterface(device, interfaceNumber); 83 | } 84 | 85 | /// Reset device 86 | Future reset(dynamic device) { 87 | return _platform.reset(device); 88 | } 89 | 90 | /// Select the configuration of the device. 91 | Future selectConfiguration(dynamic device, int configurationValue) async { 92 | await _platform.selectConfiguration(device, configurationValue); 93 | } 94 | 95 | Future clearHalt(dynamic device, String direction, int endpointNumber) { 96 | return _platform.clearHalt(device, direction, endpointNumber); 97 | } 98 | 99 | /// Waits for a specified control transfer from the device 100 | Future controlTransferIn( 101 | dynamic device, SetupParam setup, 102 | {int? length}) { 103 | return _platform.controlTransferIn(device, setup, length: length); 104 | } 105 | 106 | /// Sends a specified control transfer to the device 107 | Future controlTransferOut( 108 | dynamic device, SetupParam setup, 109 | {dynamic data}) { 110 | return _platform.controlTransferOut(device, setup, data: data); 111 | } 112 | 113 | /// get data from usb device 114 | Future transferIn( 115 | dynamic device, int endpointNumber, int length) { 116 | return _platform.transferIn(device, endpointNumber, length); 117 | } 118 | 119 | /// send data to usb 120 | Future transferOut( 121 | dynamic device, endpointNumber, ByteBuffer data) { 122 | return _platform.transferOut(device, endpointNumber, data); 123 | } 124 | 125 | Future isochronousTransferOut( 126 | dynamic device, endpointNumber, ByteBuffer data) { 127 | return _platform.isochronousTransferOut(device, endpointNumber, data); 128 | } 129 | 130 | Future isochronousTransferIn( 131 | dynamic device, endpointNumber, List packetLengths) { 132 | return _platform.isochronousTransferIn( 133 | device, endpointNumber, packetLengths); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /usb_device/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 9 | url: "https://pub.dev" 10 | source: hosted 11 | version: "2.10.0" 12 | boolean_selector: 13 | dependency: transitive 14 | description: 15 | name: boolean_selector 16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" 17 | url: "https://pub.dev" 18 | source: hosted 19 | version: "2.1.1" 20 | characters: 21 | dependency: transitive 22 | description: 23 | name: characters 24 | sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c 25 | url: "https://pub.dev" 26 | source: hosted 27 | version: "1.2.1" 28 | clock: 29 | dependency: transitive 30 | description: 31 | name: clock 32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf 33 | url: "https://pub.dev" 34 | source: hosted 35 | version: "1.1.1" 36 | collection: 37 | dependency: transitive 38 | description: 39 | name: collection 40 | sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 41 | url: "https://pub.dev" 42 | source: hosted 43 | version: "1.17.0" 44 | fake_async: 45 | dependency: transitive 46 | description: 47 | name: fake_async 48 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" 49 | url: "https://pub.dev" 50 | source: hosted 51 | version: "1.3.1" 52 | flutter: 53 | dependency: "direct main" 54 | description: flutter 55 | source: sdk 56 | version: "0.0.0" 57 | flutter_test: 58 | dependency: "direct dev" 59 | description: flutter 60 | source: sdk 61 | version: "0.0.0" 62 | flutter_web_plugins: 63 | dependency: transitive 64 | description: flutter 65 | source: sdk 66 | version: "0.0.0" 67 | js: 68 | dependency: transitive 69 | description: 70 | name: js 71 | sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" 72 | url: "https://pub.dev" 73 | source: hosted 74 | version: "0.6.5" 75 | matcher: 76 | dependency: transitive 77 | description: 78 | name: matcher 79 | sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" 80 | url: "https://pub.dev" 81 | source: hosted 82 | version: "0.12.13" 83 | material_color_utilities: 84 | dependency: transitive 85 | description: 86 | name: material_color_utilities 87 | sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 88 | url: "https://pub.dev" 89 | source: hosted 90 | version: "0.2.0" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" 96 | url: "https://pub.dev" 97 | source: hosted 98 | version: "1.8.0" 99 | path: 100 | dependency: transitive 101 | description: 102 | name: path 103 | sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b 104 | url: "https://pub.dev" 105 | source: hosted 106 | version: "1.8.2" 107 | plugin_platform_interface: 108 | dependency: transitive 109 | description: 110 | name: plugin_platform_interface 111 | sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" 112 | url: "https://pub.dev" 113 | source: hosted 114 | version: "2.1.4" 115 | sky_engine: 116 | dependency: transitive 117 | description: flutter 118 | source: sdk 119 | version: "0.0.99" 120 | source_span: 121 | dependency: transitive 122 | description: 123 | name: source_span 124 | sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 125 | url: "https://pub.dev" 126 | source: hosted 127 | version: "1.9.1" 128 | stack_trace: 129 | dependency: transitive 130 | description: 131 | name: stack_trace 132 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 133 | url: "https://pub.dev" 134 | source: hosted 135 | version: "1.11.0" 136 | stream_channel: 137 | dependency: transitive 138 | description: 139 | name: stream_channel 140 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" 141 | url: "https://pub.dev" 142 | source: hosted 143 | version: "2.1.1" 144 | string_scanner: 145 | dependency: transitive 146 | description: 147 | name: string_scanner 148 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" 149 | url: "https://pub.dev" 150 | source: hosted 151 | version: "1.2.0" 152 | term_glyph: 153 | dependency: transitive 154 | description: 155 | name: term_glyph 156 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 157 | url: "https://pub.dev" 158 | source: hosted 159 | version: "1.2.1" 160 | test_api: 161 | dependency: transitive 162 | description: 163 | name: test_api 164 | sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 165 | url: "https://pub.dev" 166 | source: hosted 167 | version: "0.4.16" 168 | usb_device_platform_interface: 169 | dependency: "direct main" 170 | description: 171 | name: usb_device_platform_interface 172 | sha256: f289c75091376462b563fd94b74f60aa6447e6429a5a88bd70effc35c39c9570 173 | url: "https://pub.dev" 174 | source: hosted 175 | version: "1.0.0" 176 | usb_device_web: 177 | dependency: "direct main" 178 | description: 179 | name: usb_device_web 180 | sha256: "1a83133fa5a70ae8bd3cd1886579c322748d5c9765e61a2c1597353b21b082fc" 181 | url: "https://pub.dev" 182 | source: hosted 183 | version: "1.0.0" 184 | vector_math: 185 | dependency: transitive 186 | description: 187 | name: vector_math 188 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" 189 | url: "https://pub.dev" 190 | source: hosted 191 | version: "2.1.4" 192 | sdks: 193 | dart: ">=2.18.0 <3.0.0" 194 | flutter: ">=1.20.0" 195 | -------------------------------------------------------------------------------- /usb_device/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: usb_device 2 | description: Flutter plugin to communicate with usb device (start sessions, send datas, set configurations ...). 3 | version: 1.0.2 4 | repository: https://github.com/Apparence-io/webUSB_plugin/ 5 | 6 | 7 | environment: 8 | sdk: ">=2.17.3 <3.0.0" 9 | flutter: ">=1.20.0" 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | usb_device_web: ^1.0.0 15 | usb_device_platform_interface: ^1.0.0 16 | 17 | dev_dependencies: 18 | flutter_test: 19 | sdk: flutter 20 | 21 | # For information on the generic Dart part of this file, see the 22 | # following page: https://dart.dev/tools/pub/pubspec 23 | 24 | # The following section is specific to Flutter. 25 | flutter: 26 | plugin: 27 | platforms: 28 | web: 29 | default_package: usb_device_web 30 | -------------------------------------------------------------------------------- /usb_device/test/usb_device_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /usb_device_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 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/ephemeral 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /usb_device_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: f4abaa0735eba4dfd8f33f73363911d63931fe03 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /usb_device_platform_interface/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.2 2 | 3 | * Change readme + format 4 | ## 0.0.1 5 | 6 | * First Releasee 7 | -------------------------------------------------------------------------------- /usb_device_platform_interface/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2021 Apparence 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /usb_device_platform_interface/README.md: -------------------------------------------------------------------------------- 1 | # usb_device_platform_interface 2 | 3 | A common platform interface for usb_device plugin. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Dart 8 | [package](https://flutter.dev/developing-packages/), 9 | a library module containing code that can be shared easily across 10 | multiple Flutter or Dart projects. 11 | 12 | For help getting started with Flutter, view our 13 | [online documentation](https://flutter.dev/docs), which offers tutorials, 14 | samples, guidance on mobile development, and a full API reference. 15 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/method_channel_usb_device.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:usb_device_platform_interface/usb_device_platform_interface.dart'; 4 | 5 | /// An implementation of [UsbDevicePlatform] that uses method channels. 6 | class MethodChannelUsbDevice extends UsbDevicePlatform { 7 | /// The method channel used to interact with the native platform. 8 | @visibleForTesting 9 | MethodChannel methodChannel = MethodChannel('apparence.io/usbdevice'); 10 | 11 | @override 12 | Future> get pairedDevices => methodChannel 13 | .invokeMethod('getDevices') 14 | .then>((dynamic result) => result); 15 | 16 | @override 17 | Future isSupported() { 18 | return methodChannel 19 | .invokeMethod('isSupported') 20 | .then((dynamic result) => result); 21 | } 22 | 23 | @override 24 | Future requestDevices(List filters) { 25 | return methodChannel 26 | .invokeMethod('requestDevices', filters) 27 | .then((dynamic result) => result); 28 | } 29 | 30 | @override 31 | Future setOnConnectCallback(Function(dynamic) onConnect) { 32 | return methodChannel 33 | .invokeMethod('setOnConnectCallback', onConnect) 34 | .then((dynamic result) => result); 35 | } 36 | 37 | @override 38 | Future setOnDisconnectCallback(Function(dynamic) onDisconnect) { 39 | return methodChannel 40 | .invokeMethod('setOnDisconnectCallback', onDisconnect) 41 | .then((dynamic result) => result); 42 | } 43 | 44 | @override 45 | Future> getAvailableConfigurations( 46 | dynamic pairedDevice) { 47 | return methodChannel 48 | .invokeMethod('getAvailableConfigurations', pairedDevice) 49 | .then>((dynamic result) => result); 50 | } 51 | 52 | @override 53 | Future getSelectedConfiguration(dynamic pairedDevice) { 54 | return methodChannel 55 | .invokeMethod('getSelectedConfiguration', pairedDevice) 56 | .then((dynamic result) => result); 57 | } 58 | 59 | @override 60 | Future getPairedDeviceInfo(dynamic pairedDevice) async { 61 | return methodChannel 62 | .invokeMethod('getPairedDeviceInfo', pairedDevice) 63 | .then((dynamic result) => result); 64 | } 65 | 66 | @override 67 | Future open(dynamic device) { 68 | return methodChannel 69 | .invokeMethod('open') 70 | .then((dynamic result) => result); 71 | } 72 | 73 | @override 74 | Future close(dynamic device) { 75 | return methodChannel 76 | .invokeMethod('close', device) 77 | .then((dynamic result) => result); 78 | } 79 | 80 | @override 81 | Future claimInterface(dynamic device, int interfaceNumber) { 82 | return methodChannel.invokeMethod('claimInterface', 83 | [device, interfaceNumber]).then((dynamic result) => result); 84 | } 85 | 86 | @override 87 | Future releaseInterface(dynamic device, int interfaceNumber) { 88 | return methodChannel.invokeMethod('releaseInterface', 89 | [device, interfaceNumber]).then((dynamic result) => result); 90 | } 91 | 92 | @override 93 | Future reset(dynamic device) { 94 | return methodChannel 95 | .invokeMethod('reset', device) 96 | .then((dynamic result) => result); 97 | } 98 | 99 | @override 100 | Future selectConfiguration(dynamic device, int configurationValue) { 101 | return methodChannel.invokeMethod('selectConfiguration', 102 | [device, configurationValue]).then((dynamic result) => result); 103 | } 104 | 105 | @override 106 | Future clearHalt(dynamic device, String direction, int endpointNumber) { 107 | return methodChannel.invokeMethod('clearHalt', [ 108 | device, 109 | direction, 110 | endpointNumber 111 | ]).then((dynamic result) => result); 112 | } 113 | 114 | @override 115 | Future controlTransferIn( 116 | dynamic device, SetupParam setup, 117 | {int? length}) { 118 | return methodChannel.invokeMethod('controlTransferIn', [ 119 | device, 120 | setup, 121 | length 122 | ]).then((dynamic result) => result); 123 | } 124 | 125 | @override 126 | Future controlTransferOut( 127 | dynamic device, SetupParam setup, 128 | {dynamic data}) { 129 | return methodChannel.invokeMethod('controlTransferOut', [ 130 | device, 131 | setup, 132 | data 133 | ]).then((dynamic result) => result); 134 | } 135 | 136 | @override 137 | Future transferIn( 138 | dynamic device, int endpointNumber, int length) { 139 | return methodChannel.invokeMethod('transferIn', [ 140 | device, 141 | endpointNumber, 142 | length 143 | ]).then((dynamic result) => result); 144 | } 145 | 146 | @override 147 | Future transferOut( 148 | dynamic device, int endpointNumber, dynamic data) { 149 | return methodChannel.invokeMethod('transferOut', [ 150 | device, 151 | endpointNumber, 152 | data 153 | ]).then((dynamic result) => result); 154 | } 155 | 156 | @override 157 | Future isochronousTransferIn( 158 | dynamic device, int endpointNumber, List packetLengths) { 159 | return methodChannel.invokeMethod('isochronousTransferIn', [ 160 | device, 161 | endpointNumber, 162 | packetLengths 163 | ]).then((dynamic result) => result); 164 | } 165 | 166 | @override 167 | Future isochronousTransferOut( 168 | dynamic device, int endpointNumber, dynamic data) { 169 | return methodChannel.invokeMethod('isochronousTransferOut', [ 170 | device, 171 | endpointNumber, 172 | data 173 | ]).then((dynamic result) => result); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/configurations/usb_alternate_interface.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'package:usb_device_platform_interface/models/configurations/usb_endpoint.dart'; 4 | 5 | class USBAlternateInterface { 6 | final int alternateSetting; 7 | final List? endpoints; 8 | 9 | USBAlternateInterface( 10 | {required this.alternateSetting, required this.endpoints}); 11 | 12 | static List fromAlternateInterfaces( 13 | List alternateInterfaces) { 14 | return alternateInterfaces 15 | .map((e) => USBAlternateInterface( 16 | alternateSetting: getProperty(e, "alternateSetting"), 17 | endpoints: getProperty(e, "endpoints") == null 18 | ? null 19 | : USBEndpoint.fromEndpoints(getProperty(e, "endpoints")), 20 | )) 21 | .toList(); 22 | } 23 | 24 | @override 25 | String toString() => 26 | 'USBAlternateInterface(alternateSetting: $alternateSetting, endpoints: $endpoints)'; 27 | } 28 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/configurations/usb_configuration.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'package:usb_device_platform_interface/models/configurations/usb_interface.dart'; 4 | 5 | class USBConfiguration { 6 | final String? configurationName; 7 | final int? configurationValue; 8 | final List? usbInterfaces; 9 | 10 | USBConfiguration( 11 | {required this.configurationName, 12 | required this.configurationValue, 13 | required this.usbInterfaces}); 14 | 15 | static USBConfiguration fromConfiguration(dynamic configuration) { 16 | return USBConfiguration( 17 | configurationName: getProperty(configuration, "configurationName"), 18 | configurationValue: getProperty(configuration, "configurationValue"), 19 | usbInterfaces: getProperty(configuration, "interfaces") == null 20 | ? null 21 | : USBInterface.fromInterfaces( 22 | getProperty(configuration, "interfaces")), 23 | ); 24 | } 25 | 26 | @override 27 | String toString() => 28 | 'USBConfiguration(configurationName: $configurationName, configurationValue: $configurationValue, usbInterfaces: $usbInterfaces)'; 29 | } 30 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/configurations/usb_device_info.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | class USBDeviceInfo { 4 | final int usbVersionMajor; 5 | final int usbVersionMinor; 6 | final int usbVersionSubMinor; 7 | final int deviceClass; 8 | final int deviceSubClass; 9 | final int deviceProtocol; 10 | final int vendorId; 11 | final int productId; 12 | final int deviceVersionMajor; 13 | final int deviceVersionMinor; 14 | final int deviceVersionSubMinor; 15 | final String manufacturerName; 16 | final String productName; 17 | final String serialNumber; 18 | final bool opened; 19 | 20 | USBDeviceInfo( 21 | this.usbVersionMajor, 22 | this.usbVersionMinor, 23 | this.usbVersionSubMinor, 24 | this.deviceClass, 25 | this.deviceSubClass, 26 | this.deviceProtocol, 27 | this.vendorId, 28 | this.productId, 29 | this.deviceVersionMajor, 30 | this.deviceVersionMinor, 31 | this.deviceVersionSubMinor, 32 | this.manufacturerName, 33 | this.productName, 34 | this.serialNumber, 35 | this.opened); 36 | 37 | static USBDeviceInfo fromDeviceJS(dynamic pairedDevice) { 38 | return USBDeviceInfo( 39 | getProperty(pairedDevice, 'usbVersionMajor'), 40 | getProperty(pairedDevice, 'usbVersionMinor'), 41 | getProperty(pairedDevice, 'usbVersionSubminor'), 42 | getProperty(pairedDevice, 'deviceClass'), 43 | getProperty(pairedDevice, 'deviceSubclass'), 44 | getProperty(pairedDevice, 'deviceProtocol'), 45 | getProperty(pairedDevice, 'vendorId'), 46 | getProperty(pairedDevice, 'productId'), 47 | getProperty(pairedDevice, 'deviceVersionMajor'), 48 | getProperty(pairedDevice, 'deviceVersionMinor'), 49 | getProperty(pairedDevice, 'deviceVersionSubminor'), 50 | getProperty(pairedDevice, 'manufacturerName'), 51 | getProperty(pairedDevice, 'productName'), 52 | getProperty(pairedDevice, 'serialNumber'), 53 | getProperty(pairedDevice, 'opened'), 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/configurations/usb_endpoint.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | class USBEndpoint { 4 | final String direction; 5 | final int endpointNumber; 6 | final int packetSize; 7 | final String type; 8 | 9 | USBEndpoint( 10 | {required this.direction, 11 | required this.endpointNumber, 12 | required this.packetSize, 13 | required this.type}); 14 | 15 | static List fromEndpoints(List endpoints) { 16 | return endpoints 17 | .map((endpoint) => USBEndpoint( 18 | direction: getProperty(endpoint, "direction"), 19 | endpointNumber: getProperty(endpoint, "endpointNumber"), 20 | packetSize: getProperty(endpoint, "packetSize"), 21 | type: getProperty(endpoint, "type"))) 22 | .toList(); 23 | } 24 | 25 | @override 26 | String toString() => 27 | 'USBEndpoint(direction: $direction, endpointNumber: $endpointNumber, packetSize: $packetSize, type: $type )'; 28 | } 29 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/configurations/usb_interface.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'package:usb_device_platform_interface/models/configurations/usb_alternate_interface.dart'; 4 | 5 | class USBInterface { 6 | final int interfaceNumber; 7 | final bool claimed; 8 | final List? alternatesInterface; 9 | 10 | USBInterface( 11 | {required this.interfaceNumber, 12 | required this.claimed, 13 | required this.alternatesInterface}); 14 | 15 | static List fromInterfaces(List interfaces) { 16 | return interfaces 17 | .map((interface) => USBInterface( 18 | interfaceNumber: getProperty(interface, "interfaceNumber"), 19 | claimed: getProperty(interface, "claimed"), 20 | alternatesInterface: getProperty(interface, "alternates") == null 21 | ? null 22 | : USBAlternateInterface.fromAlternateInterfaces( 23 | getProperty(interface, "alternates")))) 24 | .toList(); 25 | } 26 | 27 | @override 28 | String toString() => 29 | 'USBInterface(interfaceNumber: $interfaceNumber, claimed: $claimed, alternatesInterface: $alternatesInterface )'; 30 | } 31 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/param/device_filter.dart: -------------------------------------------------------------------------------- 1 | class DeviceFilter { 2 | final int vendorId; 3 | final int productId; 4 | 5 | DeviceFilter({ 6 | required this.vendorId, 7 | required this.productId, 8 | }); 9 | } 10 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/param/setup_param.dart: -------------------------------------------------------------------------------- 1 | class SetupParam { 2 | final String requestType; 3 | final String recipient; 4 | final int request; 5 | final int value; 6 | final int index; 7 | 8 | SetupParam({ 9 | required this.requestType, 10 | required this.recipient, 11 | required this.request, 12 | required this.value, 13 | required this.index, 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/transfer/response/status_response.dart: -------------------------------------------------------------------------------- 1 | enum StatusResponse { 2 | ok, 3 | stall, 4 | babble, 5 | empty_data, 6 | } 7 | 8 | extension StatusResponseHelper on StatusResponse { 9 | static StatusResponse fromString(String value) { 10 | return StatusResponse.values 11 | .firstWhere((type) => type.toString().split(".").last == value); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/transfer/usb_in_transfer_result.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'dart:typed_data'; 4 | 5 | import 'package:usb_device_platform_interface/models/transfer/response/status_response.dart'; 6 | 7 | class USBInTransferResult { 8 | final Uint8List data; 9 | final StatusResponse status; 10 | 11 | USBInTransferResult({ 12 | required this.data, 13 | required this.status, 14 | }); 15 | 16 | static USBInTransferResult fromDataJS(dynamic dataJS) { 17 | var data = getProperty(dataJS, 'data'); 18 | StatusResponse status = 19 | StatusResponseHelper.fromString(getProperty(dataJS, 'status')); 20 | return USBInTransferResult( 21 | data: Uint8List.view(getProperty(data, 'buffer')), status: status); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/transfer/usb_isochronous_in_transfer_result.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | import 'dart:typed_data'; 3 | 4 | class USBIsochronousInTransferResult { 5 | final Uint8List data; 6 | final dynamic packets; 7 | 8 | USBIsochronousInTransferResult({ 9 | required this.data, 10 | required this.packets, 11 | }); 12 | 13 | static USBIsochronousInTransferResult fromDataJS(dynamic dataJS) { 14 | var data = getProperty(dataJS, 'data'); 15 | return USBIsochronousInTransferResult( 16 | data: Uint8List.view(getProperty(data, 'buffer')), 17 | packets: getProperty(dataJS, 'packets')); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/transfer/usb_isochronous_out_transfer_result.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | class USBIsochronousOutTransferResult { 4 | final dynamic packets; 5 | 6 | USBIsochronousOutTransferResult({ 7 | required this.packets, 8 | }); 9 | 10 | static USBIsochronousOutTransferResult fromDataJS(dynamic dataJS) { 11 | return USBIsochronousOutTransferResult( 12 | packets: getProperty(dataJS, 'packets')); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/models/transfer/usb_out_transfer_result.dart: -------------------------------------------------------------------------------- 1 | import 'dart:js_util'; 2 | 3 | import 'package:usb_device_platform_interface/models/transfer/response/status_response.dart'; 4 | 5 | class USBOutTransferResult { 6 | final int bytesWritten; 7 | final StatusResponse status; 8 | 9 | USBOutTransferResult({ 10 | required this.bytesWritten, 11 | required this.status, 12 | }); 13 | 14 | static USBOutTransferResult fromDataJS(dynamic res) { 15 | StatusResponse status = 16 | StatusResponseHelper.fromString(getProperty(res, 'status')); 17 | return USBOutTransferResult( 18 | bytesWritten: getProperty(res, 'bytesWritten'), status: status); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /usb_device_platform_interface/lib/usb_device_platform_interface.dart: -------------------------------------------------------------------------------- 1 | import 'package:plugin_platform_interface/plugin_platform_interface.dart'; 2 | import 'package:usb_device_platform_interface/method_channel_usb_device.dart'; 3 | import 'package:usb_device_platform_interface/models/configurations/usb_configuration.dart'; 4 | import 'package:usb_device_platform_interface/models/configurations/usb_device_info.dart'; 5 | import 'package:usb_device_platform_interface/models/param/device_filter.dart'; 6 | import 'package:usb_device_platform_interface/models/param/setup_param.dart'; 7 | 8 | import 'models/transfer/usb_in_transfer_result.dart'; 9 | import 'models/transfer/usb_isochronous_in_transfer_result.dart'; 10 | import 'models/transfer/usb_isochronous_out_transfer_result.dart'; 11 | import 'models/transfer/usb_out_transfer_result.dart'; 12 | 13 | export 'package:usb_device_platform_interface/models/configurations/usb_interface.dart'; 14 | export 'package:usb_device_platform_interface/models/configurations/usb_alternate_interface.dart'; 15 | export 'package:usb_device_platform_interface/models/configurations/usb_device_info.dart'; 16 | export 'package:usb_device_platform_interface/models/configurations/usb_configuration.dart'; 17 | export 'package:usb_device_platform_interface/models/configurations/usb_endpoint.dart'; 18 | export 'package:usb_device_platform_interface/models/param/setup_param.dart'; 19 | export 'package:usb_device_platform_interface/models/param/device_filter.dart'; 20 | export 'package:usb_device_platform_interface/models/transfer/usb_in_transfer_result.dart'; 21 | export 'package:usb_device_platform_interface/models/transfer/usb_out_transfer_result.dart'; 22 | export 'package:usb_device_platform_interface/models/transfer/usb_isochronous_in_transfer_result.dart'; 23 | export 'package:usb_device_platform_interface/models/transfer/usb_isochronous_out_transfer_result.dart'; 24 | export 'package:usb_device_platform_interface/models/transfer/response/status_response.dart'; 25 | 26 | abstract class UsbDevicePlatform extends PlatformInterface { 27 | static final Object _token = Object(); 28 | 29 | /// Constructs a UsbDevicePlatform. 30 | UsbDevicePlatform() : super(token: _token); 31 | 32 | static UsbDevicePlatform _instance = MethodChannelUsbDevice(); 33 | 34 | /// The default instance of [UsbDevicePlatform] to use. 35 | /// 36 | /// Defaults to [MethodChannelUsbDevice]. 37 | static UsbDevicePlatform get instance => _instance; 38 | 39 | /// Platform-specific plugins should set this with their own platform-specific 40 | /// class that extends [UsbDevicePlatform] when they register themselves. 41 | static set instance(UsbDevicePlatform instance) { 42 | PlatformInterface.verifyToken(instance, _token); 43 | _instance = instance; 44 | } 45 | 46 | /// Returns usb devices 47 | Future> get pairedDevices { 48 | throw UnimplementedError('devices() has not been implemented.'); 49 | } 50 | 51 | /// Returns true if web usb is supported 52 | Future isSupported() { 53 | throw UnimplementedError('isSupported() has not been implemented.'); 54 | } 55 | 56 | /// Returns a Future with the device object that matches the specified filter by predefined vendor ID, product ID, class or subclass code, protocol code or serial number. 57 | Future requestDevices(List filters) { 58 | throw UnimplementedError('requestDevices() has not been implemented.'); 59 | } 60 | 61 | /// Set functions to get a callback when the paired device is connect 62 | Future setOnConnectCallback(Function(dynamic) onConnect) { 63 | throw UnimplementedError( 64 | 'setOnConnectCallback() has not been implemented.'); 65 | } 66 | 67 | /// Set functions to get a callback when the paired device is disconnect 68 | Future setOnDisconnectCallback(Function(dynamic) onDisconnect) { 69 | throw UnimplementedError( 70 | 'setOnDisconnectCallback() has not been implemented.'); 71 | } 72 | 73 | /// Returns a Future that resolves when a device session has started. 74 | Future open(dynamic device) { 75 | throw UnimplementedError('open() has not been implemented.'); 76 | } 77 | 78 | /// Return a map of paired device's info 79 | Future getPairedDeviceInfo(dynamic pairedDevice) async { 80 | throw UnimplementedError('getPairedDeviceInfo() has not been implemented.'); 81 | } 82 | 83 | /// Return a list of available configuration to be selected 84 | Future> getAvailableConfigurations( 85 | dynamic pairedDevice) { 86 | throw UnimplementedError( 87 | 'getAvailableConfiguration() has not been implemented.'); 88 | } 89 | 90 | Future getSelectedConfiguration(dynamic pairedDevice) { 91 | throw UnimplementedError( 92 | 'getSelectedConfiguration() has not been implemented.'); 93 | } 94 | 95 | /// Returns a Future that resolves when all open interfaces are released and the device session has ended. 96 | Future close(dynamic device) { 97 | throw UnimplementedError('close() has not been implemented.'); 98 | } 99 | 100 | /// Claims the interface of the device (by the number specified in configuration.interfaces) 101 | Future claimInterface(dynamic device, int interfaceNumber) { 102 | throw UnimplementedError('claimInterface() has not been implemented.'); 103 | } 104 | 105 | /// Returns a Future that resolves when a claimed interface is released from exclusive access 106 | Future releaseInterface(dynamic device, int interfaceNumber) { 107 | throw UnimplementedError('releaseInterface() has not been implemented.'); 108 | } 109 | 110 | /// Returns a Future that resolves when the device is reset and all app operations canceled and their promises rejected 111 | Future reset(dynamic device) { 112 | throw UnimplementedError('reset() has not been implemented.'); 113 | } 114 | 115 | /// Select the configuration of the device. Returns a Future resolved when the setup has been applied. 116 | Future selectConfiguration(dynamic device, int configurationValue) { 117 | throw UnimplementedError('selectConfiguration() has not been implemented.'); 118 | } 119 | 120 | ///Returns a Future that resolves when a halt condition is cleared. 121 | Future clearHalt(dynamic device, String direction, int endpointNumber) { 122 | throw UnimplementedError('clearHalt() has not been implemented.'); 123 | } 124 | 125 | /// Waits for a specified control transfer from the device. Returns a Future resolved with the transfer data and status. 126 | Future controlTransferIn( 127 | dynamic device, SetupParam setup, 128 | {int? length}) { 129 | throw UnimplementedError('controlTransferIn() has not been implemented.'); 130 | } 131 | 132 | /// Sends a specified control transfer to the device. Returns the Future resolved with the transfer status and the number of bytes written 133 | Future controlTransferOut( 134 | dynamic device, SetupParam setup, 135 | {dynamic data}) { 136 | throw UnimplementedError('controlTransferOut() has not been implemented.'); 137 | } 138 | 139 | ///Waits for a bulk or interrupt transfer from the device on a specified endpoint. Returns the Future resolved with the transfer data and status. 140 | Future transferIn( 141 | dynamic device, int endpointNumber, int length) { 142 | throw UnimplementedError('transferIn() has not been implemented.'); 143 | } 144 | 145 | ///Sends a bulk or interrupt transfer to the specified endpoint of the device. Returns the Future resolved with the transfer status and the number of bytes written. 146 | Future transferOut( 147 | dynamic device, int endpointNumber, dynamic data) { 148 | throw UnimplementedError('transferOut() has not been implemented.'); 149 | } 150 | 151 | ///Returns a Future that resolves when time sensitive information has been transmitted to the USB device. 152 | Future isochronousTransferIn( 153 | dynamic device, int endpointNumber, List packetLengths) { 154 | throw UnimplementedError( 155 | 'isochronousTransferIn() has not been implemented.'); 156 | } 157 | 158 | /// Returns a Future that resolves when time sensitive information has been transmitted from the USB device. 159 | Future isochronousTransferOut( 160 | dynamic device, int endpointNumber, dynamic data) { 161 | throw UnimplementedError( 162 | 'isochronousTransferOut() has not been implemented.'); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /usb_device_platform_interface/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 9 | url: "https://pub.dev" 10 | source: hosted 11 | version: "2.10.0" 12 | boolean_selector: 13 | dependency: transitive 14 | description: 15 | name: boolean_selector 16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" 17 | url: "https://pub.dev" 18 | source: hosted 19 | version: "2.1.1" 20 | characters: 21 | dependency: transitive 22 | description: 23 | name: characters 24 | sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c 25 | url: "https://pub.dev" 26 | source: hosted 27 | version: "1.2.1" 28 | clock: 29 | dependency: transitive 30 | description: 31 | name: clock 32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf 33 | url: "https://pub.dev" 34 | source: hosted 35 | version: "1.1.1" 36 | collection: 37 | dependency: transitive 38 | description: 39 | name: collection 40 | sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 41 | url: "https://pub.dev" 42 | source: hosted 43 | version: "1.17.0" 44 | fake_async: 45 | dependency: transitive 46 | description: 47 | name: fake_async 48 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" 49 | url: "https://pub.dev" 50 | source: hosted 51 | version: "1.3.1" 52 | flutter: 53 | dependency: "direct main" 54 | description: flutter 55 | source: sdk 56 | version: "0.0.0" 57 | flutter_test: 58 | dependency: "direct dev" 59 | description: flutter 60 | source: sdk 61 | version: "0.0.0" 62 | js: 63 | dependency: transitive 64 | description: 65 | name: js 66 | sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" 67 | url: "https://pub.dev" 68 | source: hosted 69 | version: "0.6.5" 70 | matcher: 71 | dependency: transitive 72 | description: 73 | name: matcher 74 | sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" 75 | url: "https://pub.dev" 76 | source: hosted 77 | version: "0.12.13" 78 | material_color_utilities: 79 | dependency: transitive 80 | description: 81 | name: material_color_utilities 82 | sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 83 | url: "https://pub.dev" 84 | source: hosted 85 | version: "0.2.0" 86 | meta: 87 | dependency: transitive 88 | description: 89 | name: meta 90 | sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" 91 | url: "https://pub.dev" 92 | source: hosted 93 | version: "1.8.0" 94 | path: 95 | dependency: transitive 96 | description: 97 | name: path 98 | sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b 99 | url: "https://pub.dev" 100 | source: hosted 101 | version: "1.8.2" 102 | plugin_platform_interface: 103 | dependency: "direct main" 104 | description: 105 | name: plugin_platform_interface 106 | sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" 107 | url: "https://pub.dev" 108 | source: hosted 109 | version: "2.1.4" 110 | sky_engine: 111 | dependency: transitive 112 | description: flutter 113 | source: sdk 114 | version: "0.0.99" 115 | source_span: 116 | dependency: transitive 117 | description: 118 | name: source_span 119 | sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 120 | url: "https://pub.dev" 121 | source: hosted 122 | version: "1.9.1" 123 | stack_trace: 124 | dependency: transitive 125 | description: 126 | name: stack_trace 127 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 128 | url: "https://pub.dev" 129 | source: hosted 130 | version: "1.11.0" 131 | stream_channel: 132 | dependency: transitive 133 | description: 134 | name: stream_channel 135 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" 136 | url: "https://pub.dev" 137 | source: hosted 138 | version: "2.1.1" 139 | string_scanner: 140 | dependency: transitive 141 | description: 142 | name: string_scanner 143 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" 144 | url: "https://pub.dev" 145 | source: hosted 146 | version: "1.2.0" 147 | term_glyph: 148 | dependency: transitive 149 | description: 150 | name: term_glyph 151 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 152 | url: "https://pub.dev" 153 | source: hosted 154 | version: "1.2.1" 155 | test_api: 156 | dependency: transitive 157 | description: 158 | name: test_api 159 | sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 160 | url: "https://pub.dev" 161 | source: hosted 162 | version: "0.4.16" 163 | vector_math: 164 | dependency: transitive 165 | description: 166 | name: vector_math 167 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" 168 | url: "https://pub.dev" 169 | source: hosted 170 | version: "2.1.4" 171 | sdks: 172 | dart: ">=2.18.0 <3.0.0" 173 | flutter: ">=1.17.0" 174 | -------------------------------------------------------------------------------- /usb_device_platform_interface/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: usb_device_platform_interface 2 | description: A common platform interface for usb_device plugin. this package is used in usb_device plugin 3 | version: 1.0.0 4 | repository: https://github.com/Apparence-io/webUSB_plugin/ 5 | 6 | environment: 7 | sdk: ">=2.17.3 <3.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | plugin_platform_interface: ^2.1.4 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | 19 | # For information on the generic Dart part of this file, see the 20 | # following page: https://dart.dev/tools/pub/pubspec 21 | 22 | # The following section is specific to Flutter. 23 | flutter: 24 | 25 | # To add assets to your package, add an assets section, like this: 26 | # assets: 27 | # - images/a_dot_burr.jpeg 28 | # - images/a_dot_ham.jpeg 29 | # 30 | # For details regarding assets in packages, see 31 | # https://flutter.dev/assets-and-images/#from-packages 32 | # 33 | # An image asset can refer to one or more resolution-specific "variants", see 34 | # https://flutter.dev/assets-and-images/#resolution-aware. 35 | 36 | # To add custom fonts to your package, add a fonts section here, 37 | # in this "flutter" section. Each entry in this list should have a 38 | # "family" key with the font family name, and a "fonts" key with a 39 | # list giving the asset and other descriptors for the font. For 40 | # example: 41 | # fonts: 42 | # - family: Schyler 43 | # fonts: 44 | # - asset: fonts/Schyler-Regular.ttf 45 | # - asset: fonts/Schyler-Italic.ttf 46 | # style: italic 47 | # - family: Trajan Pro 48 | # fonts: 49 | # - asset: fonts/TrajanPro.ttf 50 | # - asset: fonts/TrajanPro_Bold.ttf 51 | # weight: 700 52 | # 53 | # For details regarding fonts in packages, see 54 | # https://flutter.dev/custom-fonts/#from-packages 55 | -------------------------------------------------------------------------------- /usb_device_platform_interface/test/usb_device_platform_interface_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /usb_device_web/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/ephemeral 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /usb_device_web/.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: package 11 | -------------------------------------------------------------------------------- /usb_device_web/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.6 2 | 3 | * fix bug JS 4 | ## 0.0.5 5 | 6 | * fix bug JS / dart class mapping 7 | ## 0.0.4 8 | 9 | * fix bug onConnect/onDiconnect 10 | ## 0.0.3 11 | 12 | * fix bug in release mode 13 | ## 0.0.2 14 | 15 | * Change readme/pubspec + format 16 | 17 | ## 0.0.1 18 | 19 | * First release 20 | -------------------------------------------------------------------------------- /usb_device_web/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2021 Apparence 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /usb_device_web/README.md: -------------------------------------------------------------------------------- 1 | # usb_device_web 2 | 3 | A stub implementation of the Device usb plugin for Web 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Dart 8 | [package](https://flutter.dev/developing-packages/), 9 | a library module containing code that can be shared easily across 10 | multiple Flutter or Dart projects. 11 | 12 | For help getting started with Flutter, view our 13 | [online documentation](https://flutter.dev/docs), which offers tutorials, 14 | samples, guidance on mobile development, and a full API reference. 15 | -------------------------------------------------------------------------------- /usb_device_web/assets/webusb.js: -------------------------------------------------------------------------------- 1 | 2 | class WebUsbJS { 3 | WebUsbJS(){ 4 | } 5 | 6 | isSupported() { 7 | return window.navigator.usb != null; 8 | } 9 | 10 | // Pair device 11 | getPairedDevices() { 12 | return window.navigator.usb.getDevices(); 13 | } 14 | 15 | requestDevice(filters) { 16 | return window.navigator.usb.requestDevice({ filters: filters }); 17 | } 18 | 19 | setOnConnectCallback(callback) { 20 | window.navigator.usb.onconnect = ((event) => { 21 | callback(event.device); 22 | }); 23 | } 24 | 25 | setOnDisconnectCallback(callback) { 26 | window.navigator.usb.ondisconnect = ((event) => { 27 | callback(event.device); 28 | }); 29 | } 30 | 31 | // Session setup 32 | open(device) { 33 | return device.open(); 34 | } 35 | 36 | close(device) { 37 | return device.close(); 38 | } 39 | 40 | claimInterface(device, interfaceNumber) { 41 | return device.claimInterface(interfaceNumber); 42 | } 43 | 44 | releaseInterface(device, interfaceNumber) { 45 | return device.releaseInterface(interfaceNumber); 46 | } 47 | 48 | reset(device) { 49 | return device.reset(); 50 | } 51 | 52 | selectConfiguration(device, configurationValue) { 53 | return device.selectConfiguration(configurationValue); 54 | } 55 | 56 | clearHalt(device, direction, endpointNumber) { 57 | return device.clearHalt(direction, endpointNumber); 58 | } 59 | 60 | // Data transfert 61 | controlTransferIn (device, setup, length) { 62 | return device.controlTransferIn(setup, length); 63 | } 64 | 65 | controlTransferOut(device, setup, data) { 66 | return device.controlTransferOut(setup, data); 67 | } 68 | 69 | transferIn(device, endpointNumber, length) { 70 | return device.transferIn(endpointNumber, length); 71 | } 72 | 73 | transferOut (device, endpointNumber, data) { 74 | return device.transferOut(endpointNumber, data); 75 | } 76 | 77 | isochronousTransferIn(device, endpointNumber, packetLengths) { 78 | return device.isochronousTransferIn(endpointNumber, packetLengths); 79 | } 80 | 81 | isochronousTransferOut(device, endpointNumber, packetLengths) { 82 | return device.isochronousTransferOut(endpointNumber, packetLengths); 83 | } 84 | } 85 | 86 | window.WebUsbJS = WebUsbJS 87 | -------------------------------------------------------------------------------- /usb_device_web/lib/import_js/import_js_library.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/foundation.dart'; 4 | 5 | import 'import_js_library_web.dart'; 6 | 7 | class ImportJsLibrary { 8 | static Future import(String url) { 9 | if (kIsWeb) 10 | return ImportJsLibraryWeb.import(url); 11 | else 12 | return Future.value(null); 13 | } 14 | 15 | static bool isImported(String url) { 16 | if (kIsWeb) { 17 | return ImportJsLibraryWeb.isImported(url); 18 | } else { 19 | return false; 20 | } 21 | } 22 | 23 | static registerWith(dynamic _) { 24 | // useful for flutter registrar 25 | } 26 | } 27 | 28 | String _libraryUrl(String url, String pluginName) { 29 | if (url.startsWith("./")) { 30 | url = url.replaceFirst("./", ""); 31 | return "./assets/packages/$pluginName/$url"; 32 | } 33 | if (url.startsWith("assets/")) { 34 | return "./assets/packages/$pluginName/$url"; 35 | } else { 36 | return url; 37 | } 38 | } 39 | 40 | Future importJsLibrary({required String url, String? flutterPluginName}) async { 41 | if (flutterPluginName == null) { 42 | await ImportJsLibrary.import(url); 43 | } else { 44 | await ImportJsLibrary.import(_libraryUrl(url, flutterPluginName)); 45 | } 46 | } 47 | 48 | bool isJsLibraryImported(String url, {String? flutterPluginName}) { 49 | if (flutterPluginName == null) { 50 | return ImportJsLibrary.isImported(url); 51 | } else { 52 | return ImportJsLibrary.isImported(_libraryUrl(url, flutterPluginName)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /usb_device_web/lib/import_js/import_js_library_web.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:html' as html; 3 | 4 | class ImportJsLibraryWeb { 5 | /// Injects the library by its [url] 6 | static Future import(String url) { 7 | return _importJSLibraries([url]); 8 | } 9 | 10 | static html.ScriptElement _createScriptTag(String library) { 11 | final html.ScriptElement script = html.ScriptElement() 12 | ..type = "text/javascript" 13 | ..charset = "utf-8" 14 | ..async = true 15 | //..defer = true 16 | ..src = library; 17 | return script; 18 | } 19 | 20 | /// Injects a bunch of libraries in the and returns a 21 | /// Future that resolves when all load. 22 | static Future _importJSLibraries(List libraries) { 23 | final List> loading = >[]; 24 | final head = html.querySelector('head'); 25 | 26 | libraries.forEach((String library) { 27 | if (!isImported(library)) { 28 | final scriptTag = _createScriptTag(library); 29 | head!.children.add(scriptTag); 30 | loading.add(scriptTag.onLoad.first); 31 | } 32 | }); 33 | 34 | return Future.wait(loading); 35 | } 36 | 37 | static bool _isLoaded(html.Element head, String url) { 38 | if (url.startsWith("./")) { 39 | url = url.replaceFirst("./", ""); 40 | } 41 | for (var element in head.children) { 42 | if (element is html.ScriptElement) { 43 | if (element.src.endsWith(url)) { 44 | return true; 45 | } 46 | } 47 | } 48 | return false; 49 | } 50 | 51 | static bool isImported(String url) { 52 | final head = html.querySelector('head')!; 53 | return _isLoaded(head, url); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /usb_device_web/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 9 | url: "https://pub.dev" 10 | source: hosted 11 | version: "2.10.0" 12 | boolean_selector: 13 | dependency: transitive 14 | description: 15 | name: boolean_selector 16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" 17 | url: "https://pub.dev" 18 | source: hosted 19 | version: "2.1.1" 20 | characters: 21 | dependency: transitive 22 | description: 23 | name: characters 24 | sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c 25 | url: "https://pub.dev" 26 | source: hosted 27 | version: "1.2.1" 28 | clock: 29 | dependency: transitive 30 | description: 31 | name: clock 32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf 33 | url: "https://pub.dev" 34 | source: hosted 35 | version: "1.1.1" 36 | collection: 37 | dependency: transitive 38 | description: 39 | name: collection 40 | sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 41 | url: "https://pub.dev" 42 | source: hosted 43 | version: "1.17.0" 44 | fake_async: 45 | dependency: transitive 46 | description: 47 | name: fake_async 48 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" 49 | url: "https://pub.dev" 50 | source: hosted 51 | version: "1.3.1" 52 | flutter: 53 | dependency: "direct main" 54 | description: flutter 55 | source: sdk 56 | version: "0.0.0" 57 | flutter_test: 58 | dependency: "direct dev" 59 | description: flutter 60 | source: sdk 61 | version: "0.0.0" 62 | flutter_web_plugins: 63 | dependency: "direct main" 64 | description: flutter 65 | source: sdk 66 | version: "0.0.0" 67 | js: 68 | dependency: "direct main" 69 | description: 70 | name: js 71 | sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" 72 | url: "https://pub.dev" 73 | source: hosted 74 | version: "0.6.5" 75 | matcher: 76 | dependency: transitive 77 | description: 78 | name: matcher 79 | sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" 80 | url: "https://pub.dev" 81 | source: hosted 82 | version: "0.12.13" 83 | material_color_utilities: 84 | dependency: transitive 85 | description: 86 | name: material_color_utilities 87 | sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 88 | url: "https://pub.dev" 89 | source: hosted 90 | version: "0.2.0" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" 96 | url: "https://pub.dev" 97 | source: hosted 98 | version: "1.8.0" 99 | path: 100 | dependency: transitive 101 | description: 102 | name: path 103 | sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b 104 | url: "https://pub.dev" 105 | source: hosted 106 | version: "1.8.2" 107 | plugin_platform_interface: 108 | dependency: transitive 109 | description: 110 | name: plugin_platform_interface 111 | sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" 112 | url: "https://pub.dev" 113 | source: hosted 114 | version: "2.1.4" 115 | sky_engine: 116 | dependency: transitive 117 | description: flutter 118 | source: sdk 119 | version: "0.0.99" 120 | source_span: 121 | dependency: transitive 122 | description: 123 | name: source_span 124 | sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 125 | url: "https://pub.dev" 126 | source: hosted 127 | version: "1.9.1" 128 | stack_trace: 129 | dependency: transitive 130 | description: 131 | name: stack_trace 132 | sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 133 | url: "https://pub.dev" 134 | source: hosted 135 | version: "1.11.0" 136 | stream_channel: 137 | dependency: transitive 138 | description: 139 | name: stream_channel 140 | sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" 141 | url: "https://pub.dev" 142 | source: hosted 143 | version: "2.1.1" 144 | string_scanner: 145 | dependency: transitive 146 | description: 147 | name: string_scanner 148 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" 149 | url: "https://pub.dev" 150 | source: hosted 151 | version: "1.2.0" 152 | term_glyph: 153 | dependency: transitive 154 | description: 155 | name: term_glyph 156 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 157 | url: "https://pub.dev" 158 | source: hosted 159 | version: "1.2.1" 160 | test_api: 161 | dependency: transitive 162 | description: 163 | name: test_api 164 | sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 165 | url: "https://pub.dev" 166 | source: hosted 167 | version: "0.4.16" 168 | usb_device_platform_interface: 169 | dependency: "direct main" 170 | description: 171 | name: usb_device_platform_interface 172 | sha256: "97e34276a32a34c49eebeaa97efe4add7b7a63d4cd50ee0817aa0ccc7741bd57" 173 | url: "https://pub.dev" 174 | source: hosted 175 | version: "0.0.2" 176 | vector_math: 177 | dependency: transitive 178 | description: 179 | name: vector_math 180 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" 181 | url: "https://pub.dev" 182 | source: hosted 183 | version: "2.1.4" 184 | sdks: 185 | dart: ">=2.18.0 <3.0.0" 186 | flutter: ">=1.20.0" 187 | -------------------------------------------------------------------------------- /usb_device_web/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: usb_device_web 2 | description: A stub implementation of the Device usb plugin for Web. This package is used in usb_device plugin 3 | version: 1.0.0 4 | repository: https://github.com/Apparence-io/webUSB_plugin/ 5 | 6 | environment: 7 | sdk: ">=2.17.3 <3.0.0" 8 | flutter: ">=1.20.0" 9 | 10 | 11 | flutter: 12 | plugin: 13 | platforms: 14 | web: 15 | pluginClass: WebUSBPlugin 16 | fileName: usb_device_web.dart 17 | assets: 18 | - assets/webusb.js 19 | 20 | dependencies: 21 | flutter: 22 | sdk: flutter 23 | flutter_web_plugins: 24 | sdk: flutter 25 | usb_device_platform_interface: ^1.0.0 26 | js: ^0.6.5 27 | dev_dependencies: 28 | flutter_test: 29 | sdk: flutter 30 | 31 | # For information on the generic Dart part of this file, see the 32 | # following page: https://dart.dev/tools/pub/pubspec 33 | -------------------------------------------------------------------------------- /usb_device_web/test/usb_device_web_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | --------------------------------------------------------------------------------