From 9900e55d1b6a8bec952ba1ae1eb90f2c91a94841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=81=A5=E8=8E=B9?= Date: Sat, 26 Oct 2024 18:11:59 +0800 Subject: [PATCH] wip: Add window_manager_windows package --- packages/window_manager_windows/.gitignore | 29 +++++++ packages/window_manager_windows/.metadata | 27 +++++++ packages/window_manager_windows/CHANGELOG.md | 3 + packages/window_manager_windows/LICENSE | 1 + packages/window_manager_windows/README.md | 18 +++++ .../analysis_options.yaml | 4 + .../lib/window_manager_windows.dart | 14 ++++ ...window_manager_windows_method_channel.dart | 17 +++++ ...ow_manager_windows_platform_interface.dart | 29 +++++++ packages/window_manager_windows/pubspec.yaml | 75 +++++++++++++++++++ ...w_manager_windows_method_channel_test.dart | 27 +++++++ .../test/window_manager_windows_test.dart | 29 +++++++ 12 files changed, 273 insertions(+) create mode 100644 packages/window_manager_windows/.gitignore create mode 100644 packages/window_manager_windows/.metadata create mode 100644 packages/window_manager_windows/CHANGELOG.md create mode 100644 packages/window_manager_windows/LICENSE create mode 100644 packages/window_manager_windows/README.md create mode 100644 packages/window_manager_windows/analysis_options.yaml create mode 100644 packages/window_manager_windows/lib/window_manager_windows.dart create mode 100644 packages/window_manager_windows/lib/window_manager_windows_method_channel.dart create mode 100644 packages/window_manager_windows/lib/window_manager_windows_platform_interface.dart create mode 100644 packages/window_manager_windows/pubspec.yaml create mode 100644 packages/window_manager_windows/test/window_manager_windows_method_channel_test.dart create mode 100644 packages/window_manager_windows/test/window_manager_windows_test.dart diff --git a/packages/window_manager_windows/.gitignore b/packages/window_manager_windows/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/window_manager_windows/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/window_manager_windows/.metadata b/packages/window_manager_windows/.metadata new file mode 100644 index 00000000..17ceedf5 --- /dev/null +++ b/packages/window_manager_windows/.metadata @@ -0,0 +1,27 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "2663184aa79047d0a33a14a3b607954f8fdd8730" + channel: "stable" + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 + base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/window_manager_windows/CHANGELOG.md b/packages/window_manager_windows/CHANGELOG.md new file mode 100644 index 00000000..41cc7d81 --- /dev/null +++ b/packages/window_manager_windows/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/packages/window_manager_windows/LICENSE b/packages/window_manager_windows/LICENSE new file mode 100644 index 00000000..ba75c69f --- /dev/null +++ b/packages/window_manager_windows/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/packages/window_manager_windows/README.md b/packages/window_manager_windows/README.md new file mode 100644 index 00000000..f3a2d790 --- /dev/null +++ b/packages/window_manager_windows/README.md @@ -0,0 +1,18 @@ +# window_manager_windows + +A new Flutter plugin project. + +## Getting Started + +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/to/develop-plugins), +a specialized package that includes platform-specific implementation code for +Android and/or iOS. + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev), which offers tutorials, +samples, guidance on mobile development, and a full API reference. + +The plugin project was generated without specifying the `--platforms` flag, no platforms are currently supported. +To add platforms, run `flutter create -t plugin --platforms .` in this directory. +You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/to/pubspec-plugin-platforms. diff --git a/packages/window_manager_windows/analysis_options.yaml b/packages/window_manager_windows/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/window_manager_windows/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/window_manager_windows/lib/window_manager_windows.dart b/packages/window_manager_windows/lib/window_manager_windows.dart new file mode 100644 index 00000000..6ea6f783 --- /dev/null +++ b/packages/window_manager_windows/lib/window_manager_windows.dart @@ -0,0 +1,14 @@ +// You have generated a new plugin project without specifying the `--platforms` +// flag. A plugin project with no platform support was generated. To add a +// platform, run `flutter create -t plugin --platforms .` under the +// same directory. You can also find a detailed instruction on how to add +// platforms in the `pubspec.yaml` at +// https://flutter.dev/to/pubspec-plugin-platforms. + +import 'window_manager_windows_platform_interface.dart'; + +class WindowManagerWindows { + Future getPlatformVersion() { + return WindowManagerWindowsPlatform.instance.getPlatformVersion(); + } +} diff --git a/packages/window_manager_windows/lib/window_manager_windows_method_channel.dart b/packages/window_manager_windows/lib/window_manager_windows_method_channel.dart new file mode 100644 index 00000000..2f8143cf --- /dev/null +++ b/packages/window_manager_windows/lib/window_manager_windows_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'window_manager_windows_platform_interface.dart'; + +/// An implementation of [WindowManagerWindowsPlatform] that uses method channels. +class MethodChannelWindowManagerWindows extends WindowManagerWindowsPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('window_manager_windows'); + + @override + Future getPlatformVersion() async { + final version = await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/packages/window_manager_windows/lib/window_manager_windows_platform_interface.dart b/packages/window_manager_windows/lib/window_manager_windows_platform_interface.dart new file mode 100644 index 00000000..69ab6a31 --- /dev/null +++ b/packages/window_manager_windows/lib/window_manager_windows_platform_interface.dart @@ -0,0 +1,29 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'window_manager_windows_method_channel.dart'; + +abstract class WindowManagerWindowsPlatform extends PlatformInterface { + /// Constructs a WindowManagerWindowsPlatform. + WindowManagerWindowsPlatform() : super(token: _token); + + static final Object _token = Object(); + + static WindowManagerWindowsPlatform _instance = MethodChannelWindowManagerWindows(); + + /// The default instance of [WindowManagerWindowsPlatform] to use. + /// + /// Defaults to [MethodChannelWindowManagerWindows]. + static WindowManagerWindowsPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [WindowManagerWindowsPlatform] when + /// they register themselves. + static set instance(WindowManagerWindowsPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/packages/window_manager_windows/pubspec.yaml b/packages/window_manager_windows/pubspec.yaml new file mode 100644 index 00000000..5824b0f0 --- /dev/null +++ b/packages/window_manager_windows/pubspec.yaml @@ -0,0 +1,75 @@ +name: window_manager_windows +description: "A new Flutter plugin project." +version: 0.0.1 +homepage: + +environment: + sdk: ^3.5.3 + flutter: '>=3.3.0' + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^4.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.) + # which should be registered in the plugin registry. This is required for + # using method channels. + # The Android 'package' specifies package in which the registered class is. + # This is required for using method channels on Android. + # The 'ffiPlugin' specifies that native code should be built and bundled. + # This is required for using `dart:ffi`. + # All these are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + platforms: + # This plugin project was generated without specifying any + # platforms with the `--platform` argument. If you see the `some_platform` map below, remove it and + # then add platforms following the instruction here: + # https://flutter.dev/to/pubspec-plugin-platforms + # ------------------- + some_platform: + pluginClass: somePluginClass + # ------------------- + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/to/asset-from-package + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/to/font-from-package diff --git a/packages/window_manager_windows/test/window_manager_windows_method_channel_test.dart b/packages/window_manager_windows/test/window_manager_windows_method_channel_test.dart new file mode 100644 index 00000000..a85b6f1b --- /dev/null +++ b/packages/window_manager_windows/test/window_manager_windows_method_channel_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:window_manager_windows/window_manager_windows_method_channel.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + MethodChannelWindowManagerWindows platform = MethodChannelWindowManagerWindows(); + const MethodChannel channel = MethodChannel('window_manager_windows'); + + setUp(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + channel, + (MethodCall methodCall) async { + return '42'; + }, + ); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null); + }); + + test('getPlatformVersion', () async { + expect(await platform.getPlatformVersion(), '42'); + }); +} diff --git a/packages/window_manager_windows/test/window_manager_windows_test.dart b/packages/window_manager_windows/test/window_manager_windows_test.dart new file mode 100644 index 00000000..6b643b0a --- /dev/null +++ b/packages/window_manager_windows/test/window_manager_windows_test.dart @@ -0,0 +1,29 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:window_manager_windows/window_manager_windows.dart'; +import 'package:window_manager_windows/window_manager_windows_platform_interface.dart'; +import 'package:window_manager_windows/window_manager_windows_method_channel.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +class MockWindowManagerWindowsPlatform + with MockPlatformInterfaceMixin + implements WindowManagerWindowsPlatform { + + @override + Future getPlatformVersion() => Future.value('42'); +} + +void main() { + final WindowManagerWindowsPlatform initialPlatform = WindowManagerWindowsPlatform.instance; + + test('$MethodChannelWindowManagerWindows is the default instance', () { + expect(initialPlatform, isInstanceOf()); + }); + + test('getPlatformVersion', () async { + WindowManagerWindows windowManagerWindowsPlugin = WindowManagerWindows(); + MockWindowManagerWindowsPlatform fakePlatform = MockWindowManagerWindowsPlatform(); + WindowManagerWindowsPlatform.instance = fakePlatform; + + expect(await windowManagerWindowsPlugin.getPlatformVersion(), '42'); + }); +}