Skip to content

Commit 92e6a90

Browse files
committed
wip: Add window_manager_platform_interface package
1 parent 21b3493 commit 92e6a90

12 files changed

+197
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
build/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: "2663184aa79047d0a33a14a3b607954f8fdd8730"
8+
channel: "stable"
9+
10+
project_type: plugin
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
17+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
18+
- platform: macos
19+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
20+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
21+
22+
# User provided section
23+
24+
# List of Local paths (relative to this file) that should be
25+
# ignored by the migrate tool.
26+
#
27+
# Files that are not part of the templates will be ignored by default.
28+
unmanaged_files:
29+
- 'lib/main.dart'
30+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial release.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022-present LiJianying <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# window_manager_platform_interface
2+
3+
[![pub version][pub-image]][pub-url]
4+
5+
[pub-image]: https://img.shields.io/pub/v/window_manager_platform_interface.svg
6+
[pub-url]: https://pub.dev/packages/window_manager_platform_interface
7+
8+
A common platform interface for the [window_manager](https://pub.dev/packages/window_manager) plugin.
9+
10+
## Usage
11+
12+
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()`.
13+
14+
## License
15+
16+
[MIT](./LICENSE)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:mostly_reasonable_lints/analysis_options.yaml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:window_manager_platform_interface/src/window_manager_platform_interface.dart';
4+
5+
/// An implementation of [WindowManagerPlatform] that uses method channels.
6+
class MethodChannelWindowManager extends WindowManagerPlatform {
7+
/// The method channel used to interact with the native platform.
8+
@visibleForTesting
9+
final methodChannel = const MethodChannel('window_manager');
10+
11+
@override
12+
Future<String?> getPlatformVersion() async {
13+
final version =
14+
await methodChannel.invokeMethod<String>('getPlatformVersion');
15+
return version;
16+
}
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
2+
import 'package:window_manager_platform_interface/src/window_manager_method_channel.dart';
3+
4+
abstract class WindowManagerPlatform extends PlatformInterface {
5+
/// Constructs a WindowManagerPlatform.
6+
WindowManagerPlatform() : super(token: _token);
7+
8+
static final Object _token = Object();
9+
10+
static WindowManagerPlatform _instance = MethodChannelWindowManager();
11+
12+
/// The default instance of [WindowManagerPlatform] to use.
13+
///
14+
/// Defaults to [MethodChannelWindowManager].
15+
static WindowManagerPlatform get instance => _instance;
16+
17+
/// Platform-specific implementations should set this with their own
18+
/// platform-specific class that extends [WindowManagerPlatform] when
19+
/// they register themselves.
20+
static set instance(WindowManagerPlatform instance) {
21+
PlatformInterface.verifyToken(instance, _token);
22+
_instance = instance;
23+
}
24+
25+
Future<String?> getPlatformVersion() {
26+
throw UnimplementedError('platformVersion() has not been implemented.');
27+
}
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library window_manager_platform_interface;
2+
3+
export 'src/window_manager_method_channel.dart';
4+
export 'src/window_manager_platform_interface.dart';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: window_manager_platform_interface
2+
description: A common platform interface for the window_manager plugin.
3+
version: 0.0.1
4+
homepage: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager_platform_interface
5+
6+
environment:
7+
sdk: ">=3.0.0 <4.0.0"
8+
flutter: ">=3.3.0"
9+
10+
dependencies:
11+
flutter:
12+
sdk: flutter
13+
plugin_platform_interface: ^2.0.2
14+
15+
dev_dependencies:
16+
flutter_test:
17+
sdk: flutter
18+
mostly_reasonable_lints: ^0.1.2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:flutter/services.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:window_manager_platform_interface/src/window_manager_method_channel.dart';
4+
5+
void main() {
6+
TestWidgetsFlutterBinding.ensureInitialized();
7+
8+
MethodChannelWindowManager platform = MethodChannelWindowManager();
9+
const MethodChannel channel = MethodChannel('window_manager');
10+
11+
setUp(() {
12+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
13+
.setMockMethodCallHandler(
14+
channel,
15+
(MethodCall methodCall) async {
16+
return '42';
17+
},
18+
);
19+
});
20+
21+
tearDown(() {
22+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
23+
.setMockMethodCallHandler(channel, null);
24+
});
25+
26+
test('getPlatformVersion', () async {
27+
expect(await platform.getPlatformVersion(), '42');
28+
});
29+
}

0 commit comments

Comments
 (0)