-
-
Notifications
You must be signed in to change notification settings - Fork 203
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_macos package
- Loading branch information
Showing
14 changed files
with
303 additions
and
0 deletions.
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
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 | ||
|
||
* TODO: Describe 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 @@ | ||
TODO: Add your license here. |
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,15 @@ | ||
# window_manager_macos | ||
|
||
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. | ||
|
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 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
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,8 @@ | ||
|
||
import 'window_manager_macos_platform_interface.dart'; | ||
|
||
class WindowManagerMacos { | ||
Future<String?> getPlatformVersion() { | ||
return WindowManagerMacosPlatform.instance.getPlatformVersion(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/window_manager_macos/lib/window_manager_macos_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 'window_manager_macos_platform_interface.dart'; | ||
|
||
/// An implementation of [WindowManagerMacosPlatform] that uses method channels. | ||
class MethodChannelWindowManagerMacos extends WindowManagerMacosPlatform { | ||
/// The method channel used to interact with the native platform. | ||
@visibleForTesting | ||
final methodChannel = const MethodChannel('window_manager_macos'); | ||
|
||
@override | ||
Future<String?> getPlatformVersion() async { | ||
final version = await methodChannel.invokeMethod<String>('getPlatformVersion'); | ||
return version; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/window_manager_macos/lib/window_manager_macos_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,29 @@ | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'window_manager_macos_method_channel.dart'; | ||
|
||
abstract class WindowManagerMacosPlatform extends PlatformInterface { | ||
/// Constructs a WindowManagerMacosPlatform. | ||
WindowManagerMacosPlatform() : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
static WindowManagerMacosPlatform _instance = MethodChannelWindowManagerMacos(); | ||
|
||
/// The default instance of [WindowManagerMacosPlatform] to use. | ||
/// | ||
/// Defaults to [MethodChannelWindowManagerMacos]. | ||
static WindowManagerMacosPlatform get instance => _instance; | ||
|
||
/// Platform-specific implementations should set this with their own | ||
/// platform-specific class that extends [WindowManagerMacosPlatform] when | ||
/// they register themselves. | ||
static set instance(WindowManagerMacosPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
Future<String?> getPlatformVersion() { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/window_manager_macos/macos/Classes/WindowManagerMacosPlugin.swift
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,19 @@ | ||
import Cocoa | ||
import FlutterMacOS | ||
|
||
public class WindowManagerMacosPlugin: NSObject, FlutterPlugin { | ||
public static func register(with registrar: FlutterPluginRegistrar) { | ||
let channel = FlutterMethodChannel(name: "window_manager_macos", binaryMessenger: registrar.messenger) | ||
let instance = WindowManagerMacosPlugin() | ||
registrar.addMethodCallDelegate(instance, channel: channel) | ||
} | ||
|
||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
switch call.method { | ||
case "getPlatformVersion": | ||
result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString) | ||
default: | ||
result(FlutterMethodNotImplemented) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/window_manager_macos/macos/window_manager_macos.podspec
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,23 @@ | ||
# | ||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. | ||
# Run `pod lib lint window_manager_macos.podspec` to validate before publishing. | ||
# | ||
Pod::Spec.new do |s| | ||
s.name = 'window_manager_macos' | ||
s.version = '0.0.1' | ||
s.summary = 'A new Flutter plugin project.' | ||
s.description = <<-DESC | ||
A new Flutter plugin project. | ||
DESC | ||
s.homepage = 'http://example.com' | ||
s.license = { :file => '../LICENSE' } | ||
s.author = { 'Your Company' => '[email protected]' } | ||
|
||
s.source = { :path => '.' } | ||
s.source_files = 'Classes/**/*' | ||
s.dependency 'FlutterMacOS' | ||
|
||
s.platform = :osx, '10.11' | ||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } | ||
s.swift_version = '5.0' | ||
end |
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,69 @@ | ||
name: window_manager_macos | ||
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: | ||
macos: | ||
pluginClass: WindowManagerMacosPlugin | ||
|
||
# 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 |
27 changes: 27 additions & 0 deletions
27
packages/window_manager_macos/test/window_manager_macos_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,27 @@ | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:window_manager_macos/window_manager_macos_method_channel.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
MethodChannelWindowManagerMacos platform = MethodChannelWindowManagerMacos(); | ||
const MethodChannel channel = MethodChannel('window_manager_macos'); | ||
|
||
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'); | ||
}); | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/window_manager_macos/test/window_manager_macos_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_test/flutter_test.dart'; | ||
import 'package:window_manager_macos/window_manager_macos.dart'; | ||
import 'package:window_manager_macos/window_manager_macos_platform_interface.dart'; | ||
import 'package:window_manager_macos/window_manager_macos_method_channel.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
class MockWindowManagerMacosPlatform | ||
with MockPlatformInterfaceMixin | ||
implements WindowManagerMacosPlatform { | ||
|
||
@override | ||
Future<String?> getPlatformVersion() => Future.value('42'); | ||
} | ||
|
||
void main() { | ||
final WindowManagerMacosPlatform initialPlatform = WindowManagerMacosPlatform.instance; | ||
|
||
test('$MethodChannelWindowManagerMacos is the default instance', () { | ||
expect(initialPlatform, isInstanceOf<MethodChannelWindowManagerMacos>()); | ||
}); | ||
|
||
test('getPlatformVersion', () async { | ||
WindowManagerMacos windowManagerMacosPlugin = WindowManagerMacos(); | ||
MockWindowManagerMacosPlatform fakePlatform = MockWindowManagerMacosPlatform(); | ||
WindowManagerMacosPlatform.instance = fakePlatform; | ||
|
||
expect(await windowManagerMacosPlugin.getPlatformVersion(), '42'); | ||
}); | ||
} |