Skip to content

Commit

Permalink
wip: Add window_manager_platform_interface package
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Oct 27, 2024
1 parent 21b3493 commit 92e6a90
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
SOFTWARE.
29 changes: 29 additions & 0 deletions packages/window_manager_platform_interface/.gitignore
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/
30 changes: 30 additions & 0 deletions packages/window_manager_platform_interface/.metadata
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'
3 changes: 3 additions & 0 deletions packages/window_manager_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* Initial release.
21 changes: 21 additions & 0 deletions packages/window_manager_platform_interface/LICENSE
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.
16 changes: 16 additions & 0 deletions packages/window_manager_platform_interface/README.md
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
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;
}
}
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.');
}
}
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';
18 changes: 18 additions & 0 deletions packages/window_manager_platform_interface/pubspec.yaml
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
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');
});
}

0 comments on commit 92e6a90

Please sign in to comment.