-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Add window_manager_platform_interface package
- Loading branch information
Showing
12 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022-present LiJianying <[email protected]> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
1 change: 1 addition & 0 deletions
1
packages/window_manager_platform_interface/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:mostly_reasonable_lints/analysis_options.yaml |
17 changes: 17 additions & 0 deletions
17
packages/window_manager_platform_interface/lib/src/window_manager_method_channel.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String?> getPlatformVersion() async { | ||
final version = | ||
await methodChannel.invokeMethod<String>('getPlatformVersion'); | ||
return version; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/window_manager_platform_interface/lib/src/window_manager_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String?> getPlatformVersion() { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/window_manager_platform_interface/lib/window_manager_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library window_manager_platform_interface; | ||
|
||
export 'src/window_manager_method_channel.dart'; | ||
export 'src/window_manager_platform_interface.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
29 changes: 29 additions & 0 deletions
29
packages/window_manager_platform_interface/test/src/window_manager_method_channel_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
} |