diff --git a/LICENSE b/LICENSE index 46e9d56a..2fdca2eb 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/packages/window_manager_platform_interface/.gitignore b/packages/window_manager_platform_interface/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/window_manager_platform_interface/.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_platform_interface/.metadata b/packages/window_manager_platform_interface/.metadata new file mode 100644 index 00000000..b2763f65 --- /dev/null +++ b/packages/window_manager_platform_interface/.metadata @@ -0,0 +1,30 @@ +# 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 + - platform: macos + 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_platform_interface/CHANGELOG.md b/packages/window_manager_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..d0bd041d --- /dev/null +++ b/packages/window_manager_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* Initial release. diff --git a/packages/window_manager_platform_interface/LICENSE b/packages/window_manager_platform_interface/LICENSE new file mode 100644 index 00000000..2fdca2eb --- /dev/null +++ b/packages/window_manager_platform_interface/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-present LiJianying + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/window_manager_platform_interface/README.md b/packages/window_manager_platform_interface/README.md new file mode 100644 index 00000000..4ac89a87 --- /dev/null +++ b/packages/window_manager_platform_interface/README.md @@ -0,0 +1,16 @@ +# window_manager_platform_interface + +[![pub version][pub-image]][pub-url] + +[pub-image]: https://img.shields.io/pub/v/window_manager_platform_interface.svg +[pub-url]: https://pub.dev/packages/window_manager_platform_interface + +A common platform interface for the [window_manager](https://pub.dev/packages/window_manager) plugin. + +## Usage + +To implement a new platform-specific implementation of window_manager, extend `WindowManagerPlatform` with an implementation that performs the platform-specific behavior, and when you register your plugin, set the default `WindowManagerPlatform` by calling `WindowManagerPlatform.instance = MyPlatformWindowManager()`. + +## License + +[MIT](./LICENSE) diff --git a/packages/window_manager_platform_interface/analysis_options.yaml b/packages/window_manager_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..9033bb29 --- /dev/null +++ b/packages/window_manager_platform_interface/analysis_options.yaml @@ -0,0 +1 @@ +include: package:mostly_reasonable_lints/analysis_options.yaml diff --git a/packages/window_manager_platform_interface/lib/src/window_manager_method_channel.dart b/packages/window_manager_platform_interface/lib/src/window_manager_method_channel.dart new file mode 100644 index 00000000..e02d42a0 --- /dev/null +++ b/packages/window_manager_platform_interface/lib/src/window_manager_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; +import 'package:window_manager_platform_interface/src/window_manager_platform_interface.dart'; + +/// An implementation of [WindowManagerPlatform] that uses method channels. +class MethodChannelWindowManager extends WindowManagerPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('window_manager'); + + @override + Future getPlatformVersion() async { + final version = + await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/packages/window_manager_platform_interface/lib/src/window_manager_platform_interface.dart b/packages/window_manager_platform_interface/lib/src/window_manager_platform_interface.dart new file mode 100644 index 00000000..9715a034 --- /dev/null +++ b/packages/window_manager_platform_interface/lib/src/window_manager_platform_interface.dart @@ -0,0 +1,28 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:window_manager_platform_interface/src/window_manager_method_channel.dart'; + +abstract class WindowManagerPlatform extends PlatformInterface { + /// Constructs a WindowManagerPlatform. + WindowManagerPlatform() : super(token: _token); + + static final Object _token = Object(); + + static WindowManagerPlatform _instance = MethodChannelWindowManager(); + + /// The default instance of [WindowManagerPlatform] to use. + /// + /// Defaults to [MethodChannelWindowManager]. + static WindowManagerPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [WindowManagerPlatform] when + /// they register themselves. + static set instance(WindowManagerPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/packages/window_manager_platform_interface/lib/window_manager_platform_interface.dart b/packages/window_manager_platform_interface/lib/window_manager_platform_interface.dart new file mode 100644 index 00000000..57bbf8cc --- /dev/null +++ b/packages/window_manager_platform_interface/lib/window_manager_platform_interface.dart @@ -0,0 +1,4 @@ +library window_manager_platform_interface; + +export 'src/window_manager_method_channel.dart'; +export 'src/window_manager_platform_interface.dart'; diff --git a/packages/window_manager_platform_interface/pubspec.yaml b/packages/window_manager_platform_interface/pubspec.yaml new file mode 100644 index 00000000..92b2e170 --- /dev/null +++ b/packages/window_manager_platform_interface/pubspec.yaml @@ -0,0 +1,18 @@ +name: window_manager_platform_interface +description: A common platform interface for the window_manager plugin. +version: 0.0.1 +homepage: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager_platform_interface + +environment: + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.3.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + mostly_reasonable_lints: ^0.1.2 diff --git a/packages/window_manager_platform_interface/test/src/window_manager_method_channel_test.dart b/packages/window_manager_platform_interface/test/src/window_manager_method_channel_test.dart new file mode 100644 index 00000000..b9b023f7 --- /dev/null +++ b/packages/window_manager_platform_interface/test/src/window_manager_method_channel_test.dart @@ -0,0 +1,29 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:window_manager_platform_interface/src/window_manager_method_channel.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + MethodChannelWindowManager platform = MethodChannelWindowManager(); + const MethodChannel channel = MethodChannel('window_manager'); + + 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'); + }); +}