From 0716556750944c218615a3019878767e41180e84 Mon Sep 17 00:00:00 2001 From: Jaylen Bian Date: Sat, 17 Jul 2021 00:37:47 +0800 Subject: [PATCH] [infra_ui] Migrate infra_ui from package to plugin --- app_flowy/packages/flowy_infra_ui/.gitignore | 72 +---- app_flowy/packages/flowy_infra_ui/.metadata | 4 +- app_flowy/packages/flowy_infra_ui/README.md | 44 +--- .../flowy_infra_ui/android/.gitignore | 8 + .../flowy_infra_ui/android/build.gradle | 50 ++++ .../flowy_infra_ui/android/gradle.properties | 3 + .../gradle/wrapper/gradle-wrapper.properties | 5 + .../flowy_infra_ui/android/settings.gradle | 1 + .../android/src/main/AndroidManifest.xml | 3 + .../flowy_infra_ui/FlowyInfraUiPlugin.kt | 35 +++ .../packages/flowy_infra_ui/example/README.md | 4 +- .../example/android/app/build.gradle | 2 +- .../android/app/src/debug/AndroidManifest.xml | 2 +- .../android/app/src/main/AndroidManifest.xml | 4 +- .../MainActivity.kt | 2 +- .../app/src/profile/AndroidManifest.xml | 2 +- .../example/ios/Flutter/Debug.xcconfig | 1 + .../example/ios/Flutter/Release.xcconfig | 1 + .../flowy_infra_ui/example/ios/Podfile | 41 +++ .../flowy_infra_ui/example/ios/Podfile.lock | 22 ++ .../ios/Runner.xcodeproj/project.pbxproj | 75 +++++- .../contents.xcworkspacedata | 3 + .../example/ios/Runner/Info.plist | 2 +- .../macos/Flutter/Flutter-Debug.xcconfig | 1 + .../macos/Flutter/Flutter-Release.xcconfig | 1 + .../Flutter/GeneratedPluginRegistrant.swift | 2 + .../flowy_infra_ui/example/macos/Podfile | 40 +++ .../macos/Runner.xcodeproj/project.pbxproj | 6 +- .../xcshareddata/xcschemes/Runner.xcscheme | 8 +- .../macos/Runner/Configs/AppInfo.xcconfig | 4 +- .../flowy_infra_ui/example/pubspec.lock | 14 +- .../flowy_infra_ui/example/pubspec.yaml | 55 +--- .../example/test/widget_test.dart | 25 +- .../flowy_infra_ui/example/web/index.html | 6 +- .../flowy_infra_ui/example/web/manifest.json | 6 +- .../flowy_infra_ui/example/windows/.gitignore | 17 ++ .../example/windows/CMakeLists.txt | 95 +++++++ .../example/windows/flutter/CMakeLists.txt | 103 ++++++++ .../flutter/generated_plugin_registrant.cc | 12 + .../flutter/generated_plugin_registrant.h | 13 + .../windows/flutter/generated_plugins.cmake | 16 ++ .../example/windows/runner/CMakeLists.txt | 17 ++ .../example/windows/runner/Runner.rc | 121 +++++++++ .../example/windows/runner/flutter_window.cpp | 61 +++++ .../example/windows/runner/flutter_window.h | 33 +++ .../example/windows/runner/main.cpp | 43 +++ .../example/windows/runner/resource.h | 16 ++ .../windows/runner/resources/app_icon.ico | Bin 0 -> 33772 bytes .../windows/runner/runner.exe.manifest | 20 ++ .../example/windows/runner/utils.cpp | 64 +++++ .../example/windows/runner/utils.h | 19 ++ .../example/windows/runner/win32_window.cpp | 245 ++++++++++++++++++ .../example/windows/runner/win32_window.h | 98 +++++++ .../packages/flowy_infra_ui/ios/.gitignore | 38 +++ .../flowy_infra_ui/ios/Assets/.gitkeep | 0 .../ios/Classes/FlowyInfraUiPlugin.h | 4 + .../ios/Classes/FlowyInfraUiPlugin.m | 15 ++ .../ios/Classes/SwiftFlowyInfraUiPlugin.swift | 14 + .../flowy_infra_ui/ios/flowy_infra_ui.podspec | 23 ++ .../flowy_infra_ui/lib/flowy_infra_ui.dart | 13 + .../lib/flowy_infra_ui_web.dart | 44 ++++ .../macos/Classes/FlowyInfraUiPlugin.swift | 19 ++ .../macos/flowy_infra_ui.podspec | 22 ++ .../packages/flowy_infra_ui/pubspec.lock | 14 +- .../packages/flowy_infra_ui/pubspec.yaml | 58 ++--- .../test/flowy_infra_ui_test.dart | 23 ++ .../flowy_infra_ui/test/flowy_ui_test.dart | 1 - .../flowy_infra_ui/windows/.gitignore | 17 ++ .../flowy_infra_ui/windows/CMakeLists.txt | 24 ++ .../windows/flowy_infra_ui_plugin.cpp | 82 ++++++ .../flowy_infra_ui/flowy_infra_ui_plugin.h | 23 ++ 71 files changed, 1744 insertions(+), 237 deletions(-) create mode 100644 app_flowy/packages/flowy_infra_ui/android/.gitignore create mode 100644 app_flowy/packages/flowy_infra_ui/android/build.gradle create mode 100644 app_flowy/packages/flowy_infra_ui/android/gradle.properties create mode 100644 app_flowy/packages/flowy_infra_ui/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 app_flowy/packages/flowy_infra_ui/android/settings.gradle create mode 100644 app_flowy/packages/flowy_infra_ui/android/src/main/AndroidManifest.xml create mode 100644 app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt rename app_flowy/packages/flowy_infra_ui/example/android/app/src/main/kotlin/com/example/{example => flowy_infra_ui_example}/MainActivity.kt (69%) create mode 100644 app_flowy/packages/flowy_infra_ui/example/ios/Podfile create mode 100644 app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock create mode 100644 app_flowy/packages/flowy_infra_ui/example/macos/Podfile create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/.gitignore create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/CMakeLists.txt create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/flutter/CMakeLists.txt create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.cc create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.h create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugins.cmake create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/CMakeLists.txt create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/Runner.rc create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.cpp create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.h create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/main.cpp create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/resource.h create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/resources/app_icon.ico create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/runner.exe.manifest create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.cpp create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.h create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.cpp create mode 100644 app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.h create mode 100644 app_flowy/packages/flowy_infra_ui/ios/.gitignore create mode 100644 app_flowy/packages/flowy_infra_ui/ios/Assets/.gitkeep create mode 100644 app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h create mode 100644 app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m create mode 100644 app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift create mode 100644 app_flowy/packages/flowy_infra_ui/ios/flowy_infra_ui.podspec create mode 100644 app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart create mode 100644 app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart create mode 100644 app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift create mode 100644 app_flowy/packages/flowy_infra_ui/macos/flowy_infra_ui.podspec create mode 100644 app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart delete mode 100644 app_flowy/packages/flowy_infra_ui/test/flowy_ui_test.dart create mode 100644 app_flowy/packages/flowy_infra_ui/windows/.gitignore create mode 100644 app_flowy/packages/flowy_infra_ui/windows/CMakeLists.txt create mode 100644 app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp create mode 100644 app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h diff --git a/app_flowy/packages/flowy_infra_ui/.gitignore b/app_flowy/packages/flowy_infra_ui/.gitignore index a247422ef7..e9dc58d3d6 100644 --- a/app_flowy/packages/flowy_infra_ui/.gitignore +++ b/app_flowy/packages/flowy_infra_ui/.gitignore @@ -1,75 +1,7 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp .DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# 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 -**/doc/api/ .dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies + .packages -.pub-cache/ .pub/ + build/ - -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Flutter.podspec -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/ephemeral -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 diff --git a/app_flowy/packages/flowy_infra_ui/.metadata b/app_flowy/packages/flowy_infra_ui/.metadata index f323c72cb1..505610f134 100644 --- a/app_flowy/packages/flowy_infra_ui/.metadata +++ b/app_flowy/packages/flowy_infra_ui/.metadata @@ -4,7 +4,7 @@ # This file should be version controlled and should not be manually edited. version: - revision: 96bbcd006fafade4ad7a4abde77cec32df6846ea + revision: fa5883b78e566877613ad1ccb48dd92075cb5c23 channel: dev -project_type: package +project_type: plugin diff --git a/app_flowy/packages/flowy_infra_ui/README.md b/app_flowy/packages/flowy_infra_ui/README.md index 8b55e735b5..2644e9ffa9 100644 --- a/app_flowy/packages/flowy_infra_ui/README.md +++ b/app_flowy/packages/flowy_infra_ui/README.md @@ -1,39 +1,15 @@ - +## Getting Started -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/developing-packages/), +a specialized package that includes platform-specific implementation code for +Android and/or iOS. -## Features +For help getting started with Flutter, view our +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/app_flowy/packages/flowy_infra_ui/android/.gitignore b/app_flowy/packages/flowy_infra_ui/android/.gitignore new file mode 100644 index 0000000000..c6cbe562a4 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/app_flowy/packages/flowy_infra_ui/android/build.gradle b/app_flowy/packages/flowy_infra_ui/android/build.gradle new file mode 100644 index 0000000000..f1e1c9e76e --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/build.gradle @@ -0,0 +1,50 @@ +group 'com.example.flowy_infra_ui' +version '1.0-SNAPSHOT' + +buildscript { + ext.kotlin_version = '1.3.50' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +rootProject.allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion 30 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + minSdkVersion 16 + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/app_flowy/packages/flowy_infra_ui/android/gradle.properties b/app_flowy/packages/flowy_infra_ui/android/gradle.properties new file mode 100644 index 0000000000..94adc3a3f9 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/app_flowy/packages/flowy_infra_ui/android/gradle/wrapper/gradle-wrapper.properties b/app_flowy/packages/flowy_infra_ui/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..3c9d0852bf --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/app_flowy/packages/flowy_infra_ui/android/settings.gradle b/app_flowy/packages/flowy_infra_ui/android/settings.gradle new file mode 100644 index 0000000000..0dc790b56b --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'flowy_infra_ui' diff --git a/app_flowy/packages/flowy_infra_ui/android/src/main/AndroidManifest.xml b/app_flowy/packages/flowy_infra_ui/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..f93233246e --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt b/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt new file mode 100644 index 0000000000..5d98dd8f10 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt @@ -0,0 +1,35 @@ +package com.example.flowy_infra_ui + +import androidx.annotation.NonNull + +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result + +/** FlowyInfraUiPlugin */ +class FlowyInfraUiPlugin: FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private lateinit var channel : MethodChannel + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flowy_infra_ui") + channel.setMethodCallHandler(this) + } + + override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + if (call.method == "getPlatformVersion") { + result.success("Android ${android.os.Build.VERSION.RELEASE}") + } else { + result.notImplemented() + } + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } +} diff --git a/app_flowy/packages/flowy_infra_ui/example/README.md b/app_flowy/packages/flowy_infra_ui/example/README.md index a135626028..7bc0ab05f6 100644 --- a/app_flowy/packages/flowy_infra_ui/example/README.md +++ b/app_flowy/packages/flowy_infra_ui/example/README.md @@ -1,6 +1,6 @@ -# example +# flowy_infra_ui_example -A new Flutter project. +Demonstrates how to use the flowy_infra_ui plugin. ## Getting Started diff --git a/app_flowy/packages/flowy_infra_ui/example/android/app/build.gradle b/app_flowy/packages/flowy_infra_ui/example/android/app/build.gradle index 56bfa9b78f..7530664892 100644 --- a/app_flowy/packages/flowy_infra_ui/example/android/app/build.gradle +++ b/app_flowy/packages/flowy_infra_ui/example/android/app/build.gradle @@ -43,7 +43,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.example" + applicationId "com.example.flowy_infra_ui_example" minSdkVersion 16 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() diff --git a/app_flowy/packages/flowy_infra_ui/example/android/app/src/debug/AndroidManifest.xml b/app_flowy/packages/flowy_infra_ui/example/android/app/src/debug/AndroidManifest.xml index c208884f30..26ef01e2ad 100644 --- a/app_flowy/packages/flowy_infra_ui/example/android/app/src/debug/AndroidManifest.xml +++ b/app_flowy/packages/flowy_infra_ui/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.example.flowy_infra_ui_example"> diff --git a/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/AndroidManifest.xml b/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/AndroidManifest.xml index 34dd77efb2..48bd1e58f9 100644 --- a/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/AndroidManifest.xml +++ b/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="com.example.flowy_infra_ui_example"> + package="com.example.flowy_infra_ui_example"> diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Debug.xcconfig b/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Debug.xcconfig index 592ceee85b..ec97fc6f30 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Debug.xcconfig +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Release.xcconfig b/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Release.xcconfig index 592ceee85b..c4855bfe20 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Release.xcconfig +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Podfile b/app_flowy/packages/flowy_infra_ui/example/ios/Podfile new file mode 100644 index 0000000000..1e8c3c90a5 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock b/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock new file mode 100644 index 0000000000..c5a50f2dc9 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - flowy_infra_ui (0.0.1): + - Flutter + - Flutter (1.0.0) + +DEPENDENCIES: + - flowy_infra_ui (from `.symlinks/plugins/flowy_infra_ui/ios`) + - Flutter (from `Flutter`) + +EXTERNAL SOURCES: + flowy_infra_ui: + :path: ".symlinks/plugins/flowy_infra_ui/ios" + Flutter: + :path: Flutter + +SPEC CHECKSUMS: + flowy_infra_ui: 146c88346fd55d2ee6a41ae35059a5bf095cfbb3 + Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + +PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c + +COCOAPODS: 1.9.3 diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj index c6759a6e8f..eb8f7f7e87 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 73D88840D6ADB1B9C000C539 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA749E34E8D549849F119B5B /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -32,6 +33,7 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 3CA8F348EBCAB0B9417EC70D /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -42,6 +44,9 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BD462F555277405D97D69F24 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + C010FCE60C748638851A2DFA /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + CA749E34E8D549849F119B5B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,12 +54,32 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 73D88840D6ADB1B9C000C539 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 2A04BAC54BC6D85A998F0000 /* Frameworks */ = { + isa = PBXGroup; + children = ( + CA749E34E8D549849F119B5B /* Pods_Runner.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 8F8024933033E730415889FC /* Pods */ = { + isa = PBXGroup; + children = ( + C010FCE60C748638851A2DFA /* Pods-Runner.debug.xcconfig */, + BD462F555277405D97D69F24 /* Pods-Runner.release.xcconfig */, + 3CA8F348EBCAB0B9417EC70D /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -72,6 +97,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, + 8F8024933033E730415889FC /* Pods */, + 2A04BAC54BC6D85A998F0000 /* Frameworks */, ); sourceTree = ""; }; @@ -105,12 +132,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 653DE1EFE700467C4AF71781 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + C71338FE5F010950C936DB01 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -183,6 +212,28 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; + 653DE1EFE700467C4AF71781 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -197,6 +248,24 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + C71338FE5F010950C936DB01 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/flowy_infra_ui/flowy_infra_ui.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flowy_infra_ui.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -291,7 +360,7 @@ ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.flowyInfraUiExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -415,7 +484,7 @@ ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.flowyInfraUiExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -434,7 +503,7 @@ ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.flowyInfraUiExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a16ed..21a3cc14c7 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Runner/Info.plist b/app_flowy/packages/flowy_infra_ui/example/ios/Runner/Info.plist index a060db61e4..78bd1d1d6c 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Runner/Info.plist +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Runner/Info.plist @@ -11,7 +11,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - example + flowy_infra_ui_example CFBundlePackageType APPL CFBundleShortVersionString diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Debug.xcconfig b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b608..4b81f9b2d2 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Debug.xcconfig +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Release.xcconfig b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Release.xcconfig index c2efd0b608..5caa9d1579 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Release.xcconfig +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/GeneratedPluginRegistrant.swift b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817a52..fe63258f95 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import flowy_infra_ui func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FlowyInfraUiPlugin.register(with: registry.registrar(forPlugin: "FlowyInfraUiPlugin")) } diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Podfile b/app_flowy/packages/flowy_infra_ui/example/macos/Podfile new file mode 100644 index 0000000000..dade8dfad0 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Podfile @@ -0,0 +1,40 @@ +platform :osx, '10.11' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/project.pbxproj b/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/project.pbxproj index cc89c87828..547137744c 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/project.pbxproj +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/project.pbxproj @@ -54,7 +54,7 @@ /* Begin PBXFileReference section */ 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; - 33CC10ED2044A3C60003C045 /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10ED2044A3C60003C045 /* flowy_infra_ui_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "flowy_infra_ui_example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; @@ -105,7 +105,7 @@ 33CC10EE2044A3C60003C045 /* Products */ = { isa = PBXGroup; children = ( - 33CC10ED2044A3C60003C045 /* example.app */, + 33CC10ED2044A3C60003C045 /* flowy_infra_ui_example.app */, ); name = Products; sourceTree = ""; @@ -172,7 +172,7 @@ ); name = Runner; productName = Runner; - productReference = 33CC10ED2044A3C60003C045 /* example.app */; + productReference = 33CC10ED2044A3C60003C045 /* flowy_infra_ui_example.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index ae8ff59d97..9420dfd1a6 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -15,7 +15,7 @@ @@ -31,7 +31,7 @@ @@ -54,7 +54,7 @@ @@ -73,7 +73,7 @@ diff --git a/app_flowy/packages/flowy_infra_ui/example/macos/Runner/Configs/AppInfo.xcconfig b/app_flowy/packages/flowy_infra_ui/example/macos/Runner/Configs/AppInfo.xcconfig index cf9be60ca4..76ad650b99 100644 --- a/app_flowy/packages/flowy_infra_ui/example/macos/Runner/Configs/AppInfo.xcconfig +++ b/app_flowy/packages/flowy_infra_ui/example/macos/Runner/Configs/AppInfo.xcconfig @@ -5,10 +5,10 @@ // 'flutter create' template. // The application's name. By default this is also the title of the Flutter window. -PRODUCT_NAME = example +PRODUCT_NAME = flowy_infra_ui_example // The application's bundle identifier -PRODUCT_BUNDLE_IDENTIFIER = com.example.example +PRODUCT_BUNDLE_IDENTIFIER = com.example.flowyInfraUiExample // The copyright displayed in application information PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock index 510052ef08..c05870c42c 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock @@ -116,6 +116,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" lint: dependency: transitive description: @@ -263,4 +275,4 @@ packages: version: "2.1.0" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + flutter: ">=1.20.0" diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml b/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml index 3440f8d831..901200091e 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml @@ -1,8 +1,7 @@ -name: example -description: A new Flutter project. +name: flowy_infra_ui_example +description: Demonstrates how to use the flowy_infra_ui plugin. -publish_to: 'none' -version: 1.0.0+1 +publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: sdk: ">=2.12.0 <3.0.0" @@ -11,59 +10,17 @@ dependencies: flutter: sdk: flutter - cupertino_icons: ^1.0.2 flowy_infra_ui: path: ../ + cupertino_icons: ^1.0.2 + dev_dependencies: flutter_test: sdk: flutter - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^1.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. flutter: - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. - uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, 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 from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages + uses-material-design: true \ No newline at end of file diff --git a/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart b/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart index ceaa592386..1d7ea5f43e 100644 --- a/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart +++ b/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart @@ -8,23 +8,20 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:example/main.dart'; +import 'package:flowy_infra_ui_example/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('Verify Platform version', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const ExampleApp()); + await tester.pumpWidget(const MyApp()); - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Text && + widget.data!.startsWith('Running on:'), + ), + findsOneWidget, + ); }); } diff --git a/app_flowy/packages/flowy_infra_ui/example/web/index.html b/app_flowy/packages/flowy_infra_ui/example/web/index.html index eed169dc70..dda953d8dd 100644 --- a/app_flowy/packages/flowy_infra_ui/example/web/index.html +++ b/app_flowy/packages/flowy_infra_ui/example/web/index.html @@ -18,15 +18,15 @@ - + - + - example + flowy_infra_ui_example diff --git a/app_flowy/packages/flowy_infra_ui/example/web/manifest.json b/app_flowy/packages/flowy_infra_ui/example/web/manifest.json index 8c012917da..5c3b6fad3c 100644 --- a/app_flowy/packages/flowy_infra_ui/example/web/manifest.json +++ b/app_flowy/packages/flowy_infra_ui/example/web/manifest.json @@ -1,11 +1,11 @@ { - "name": "example", - "short_name": "example", + "name": "flowy_infra_ui_example", + "short_name": "flowy_infra_ui_example", "start_url": ".", "display": "standalone", "background_color": "#0175C2", "theme_color": "#0175C2", - "description": "A new Flutter project.", + "description": "Demonstrates how to use the flowy_infra_ui plugin.", "orientation": "portrait-primary", "prefer_related_applications": false, "icons": [ diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/.gitignore b/app_flowy/packages/flowy_infra_ui/example/windows/.gitignore new file mode 100644 index 0000000000..d492d0d98c --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/CMakeLists.txt b/app_flowy/packages/flowy_infra_ui/example/windows/CMakeLists.txt new file mode 100644 index 0000000000..50d22a91d1 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.15) +project(flowy_infra_ui_example LANGUAGES CXX) + +set(BINARY_NAME "flowy_infra_ui_example") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() + +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/flutter/CMakeLists.txt b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000000..b02c5485c9 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.15) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + windows-x64 $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.cc b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000000..eb5983d9f8 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,12 @@ +// +// Generated file. Do not edit. +// + +#include "generated_plugin_registrant.h" + +#include + +void RegisterPlugins(flutter::PluginRegistry* registry) { + FlowyInfraUiPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlowyInfraUiPlugin")); +} diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.h b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000000..9846246b4d --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,13 @@ +// +// Generated file. Do not edit. +// + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugins.cmake b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugins.cmake new file mode 100644 index 0000000000..c82a15ca3f --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/flutter/generated_plugins.cmake @@ -0,0 +1,16 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + flowy_infra_ui +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/CMakeLists.txt b/app_flowy/packages/flowy_infra_ui/example/windows/runner/CMakeLists.txt new file mode 100644 index 0000000000..0b899a0bcf --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.15) +project(runner LANGUAGES CXX) + +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) +apply_standard_settings(${BINARY_NAME}) +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/Runner.rc b/app_flowy/packages/flowy_infra_ui/example/windows/runner/Runner.rc new file mode 100644 index 0000000000..7db52c01ae --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#ifdef FLUTTER_BUILD_NUMBER +#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#else +#define VERSION_AS_NUMBER 1,0,0 +#endif + +#ifdef FLUTTER_BUILD_NAME +#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "Demonstrates how to use the flowy_infra_ui plugin." "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "flowy_infra_ui_example" "\0" + VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "flowy_infra_ui_example.exe" "\0" + VALUE "ProductName", "flowy_infra_ui_example" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.cpp b/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.cpp new file mode 100644 index 0000000000..b43b9095ea --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.cpp @@ -0,0 +1,61 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.h b/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.h new file mode 100644 index 0000000000..6da0652f05 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/flutter_window.h @@ -0,0 +1,33 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/main.cpp b/app_flowy/packages/flowy_infra_ui/example/windows/runner/main.cpp new file mode 100644 index 0000000000..a1b7c151e3 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.CreateAndShow(L"flowy_infra_ui_example", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/resource.h b/app_flowy/packages/flowy_infra_ui/example/windows/runner/resource.h new file mode 100644 index 0000000000..66a65d1e4a --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/resources/app_icon.ico b/app_flowy/packages/flowy_infra_ui/example/windows/runner/resources/app_icon.ico new file mode 100644 index 0000000000000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AsbU-a94MYYtA#&!c`xGIaV;yzsmrjfieTEtqB_WgZp2*NplHx=$O{M~2#i_vJ{ps-NgK zQsxKK_CBM2PP_je+Xft`(vYfXXgIUr{=PA=7a8`2EHk)Ym2QKIforz# tySWtj{oF3N9@_;i*Fv5S)9x^z=nlWP>jpp-9)52ZmLVA=i*%6g{{fxOO~wEK literal 0 HcmV?d00001 diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/runner.exe.manifest b/app_flowy/packages/flowy_infra_ui/example/windows/runner/runner.exe.manifest new file mode 100644 index 0000000000..c977c4a425 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.cpp b/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.cpp new file mode 100644 index 0000000000..d19bdbbcc3 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.cpp @@ -0,0 +1,64 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr); + if (target_length == 0) { + return std::string(); + } + std::string utf8_string; + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), + target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.h b/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.h new file mode 100644 index 0000000000..3879d54755 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.cpp b/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.cpp new file mode 100644 index 0000000000..c10f08dc7d --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.cpp @@ -0,0 +1,245 @@ +#include "win32_window.h" + +#include + +#include "resource.h" + +namespace { + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + FreeLibrary(user32_module); + } +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + return OnCreate(); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} diff --git a/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.h b/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.h new file mode 100644 index 0000000000..17ba431125 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/windows/runner/win32_window.h @@ -0,0 +1,98 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates and shows a win32 window with |title| and position and size using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size to will treat the width height passed in to this function + // as logical pixels and scale to appropriate for the default monitor. Returns + // true if the window was created successfully. + bool CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responsponds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/app_flowy/packages/flowy_infra_ui/ios/.gitignore b/app_flowy/packages/flowy_infra_ui/ios/.gitignore new file mode 100644 index 0000000000..0c885071e3 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/.gitignore @@ -0,0 +1,38 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig +/Flutter/ephemeral/ +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/app_flowy/packages/flowy_infra_ui/ios/Assets/.gitkeep b/app_flowy/packages/flowy_infra_ui/ios/Assets/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h new file mode 100644 index 0000000000..9f353812ba --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface FlowyInfraUiPlugin : NSObject +@end diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m new file mode 100644 index 0000000000..6609bdcf24 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m @@ -0,0 +1,15 @@ +#import "FlowyInfraUiPlugin.h" +#if __has_include() +#import +#else +// Support project import fallback if the generated compatibility header +// is not copied when this plugin is created as a library. +// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 +#import "flowy_infra_ui-Swift.h" +#endif + +@implementation FlowyInfraUiPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + [SwiftFlowyInfraUiPlugin registerWithRegistrar:registrar]; +} +@end diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift new file mode 100644 index 0000000000..5459739470 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift @@ -0,0 +1,14 @@ +import Flutter +import UIKit + +public class SwiftFlowyInfraUiPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "flowy_infra_ui", binaryMessenger: registrar.messenger()) + let instance = SwiftFlowyInfraUiPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + result("iOS " + UIDevice.current.systemVersion) + } +} diff --git a/app_flowy/packages/flowy_infra_ui/ios/flowy_infra_ui.podspec b/app_flowy/packages/flowy_infra_ui/ios/flowy_infra_ui.podspec new file mode 100644 index 0000000000..767ae7c3cd --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/flowy_infra_ui.podspec @@ -0,0 +1,23 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flowy_infra_ui.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flowy_infra_ui' + 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@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'Flutter' + s.platform = :ios, '8.0' + + # Flutter.framework does not contain a i386 slice. + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + s.swift_version = '5.0' +end diff --git a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart new file mode 100644 index 0000000000..2efe27d245 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart @@ -0,0 +1,13 @@ + +import 'dart:async'; + +import 'package:flutter/services.dart'; + +class FlowyInfraUi { + static const MethodChannel _channel = MethodChannel('flowy_infra_ui'); + + static Future get platformVersion async { + final String? version = await _channel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart new file mode 100644 index 0000000000..f9d9035149 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart @@ -0,0 +1,44 @@ +import 'dart:async'; +// In order to *not* need this ignore, consider extracting the "web" version +// of your plugin as a separate package, instead of inlining it in the same +// package as the core of your plugin. +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as html show window; + +import 'package:flutter/services.dart'; +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; + +/// A web implementation of the FlowyInfraUi plugin. +class FlowyInfraUiWeb { + static void registerWith(Registrar registrar) { + final MethodChannel channel = MethodChannel( + 'flowy_infra_ui', + const StandardMethodCodec(), + registrar, + ); + + final pluginInstance = FlowyInfraUiWeb(); + channel.setMethodCallHandler(pluginInstance.handleMethodCall); + } + + /// Handles method calls over the MethodChannel of this plugin. + /// Note: Check the "federated" architecture for a new way of doing this: + /// https://flutter.dev/go/federated-plugins + Future handleMethodCall(MethodCall call) async { + switch (call.method) { + case 'getPlatformVersion': + return getPlatformVersion(); + default: + throw PlatformException( + code: 'Unimplemented', + details: 'flowy_infra_ui for web doesn\'t implement \'${call.method}\'', + ); + } + } + + /// Returns a [String] containing the version of the platform. + Future getPlatformVersion() { + final version = html.window.navigator.userAgent; + return Future.value(version); + } +} diff --git a/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift b/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift new file mode 100644 index 0000000000..b0fcc26b21 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift @@ -0,0 +1,19 @@ +import Cocoa +import FlutterMacOS + +public class FlowyInfraUiPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "flowy_infra_ui", binaryMessenger: registrar.messenger) + let instance = FlowyInfraUiPlugin() + 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) + } + } +} diff --git a/app_flowy/packages/flowy_infra_ui/macos/flowy_infra_ui.podspec b/app_flowy/packages/flowy_infra_ui/macos/flowy_infra_ui.podspec new file mode 100644 index 0000000000..2dd79403f1 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/macos/flowy_infra_ui.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flowy_infra_ui.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flowy_infra_ui' + 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@example.com' } + 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 diff --git a/app_flowy/packages/flowy_infra_ui/pubspec.lock b/app_flowy/packages/flowy_infra_ui/pubspec.lock index 87940a591f..cff84ae06e 100644 --- a/app_flowy/packages/flowy_infra_ui/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/pubspec.lock @@ -102,6 +102,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" lint: dependency: transitive description: @@ -249,4 +261,4 @@ packages: version: "2.1.0" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + flutter: ">=1.20.0" diff --git a/app_flowy/packages/flowy_infra_ui/pubspec.yaml b/app_flowy/packages/flowy_infra_ui/pubspec.yaml index bc7007349b..d1af8afe3d 100644 --- a/app_flowy/packages/flowy_infra_ui/pubspec.yaml +++ b/app_flowy/packages/flowy_infra_ui/pubspec.yaml @@ -1,22 +1,26 @@ name: flowy_infra_ui -description: A new Flutter package project. +description: A new flutter plugin project. version: 0.0.1 homepage: publish_to: 'none' environment: sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + flutter: ">=1.20.0" dependencies: flutter: sdk: flutter + flutter_web_plugins: + sdk: flutter + # Thirdparty packages textstyle_extensions: '2.0.0-nullsafety' dartz: '0.10.0-nullsafety.2' provider: ^5.0.0 styled_widget: '>=0.3.1' equatable: '>=2.0.2' animations: ^2.0.0 + # Flowy packages flowy_infra: path: ../flowy_infra @@ -24,41 +28,19 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^1.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. flutter: - - # To add assets to your 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/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # To add custom fonts to your 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/custom-fonts/#from-packages + plugin: + platforms: + android: + package: com.example.flowy_infra_ui + pluginClass: FlowyInfraUiPlugin + ios: + pluginClass: FlowyInfraUiPlugin + macos: + pluginClass: FlowyInfraUiPlugin + windows: + pluginClass: FlowyInfraUiPlugin + web: + pluginClass: FlowyInfraUiWeb + fileName: flowy_infra_ui_web.dart \ No newline at end of file diff --git a/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart b/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart new file mode 100644 index 0000000000..c7e2a4cf99 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/test/flowy_infra_ui_test.dart @@ -0,0 +1,23 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flowy_infra_ui/flowy_infra_ui.dart'; + +void main() { + const MethodChannel channel = MethodChannel('flowy_infra_ui'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await FlowyInfraUi.platformVersion, '42'); + }); +} diff --git a/app_flowy/packages/flowy_infra_ui/test/flowy_ui_test.dart b/app_flowy/packages/flowy_infra_ui/test/flowy_ui_test.dart deleted file mode 100644 index 8b13789179..0000000000 --- a/app_flowy/packages/flowy_infra_ui/test/flowy_ui_test.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/app_flowy/packages/flowy_infra_ui/windows/.gitignore b/app_flowy/packages/flowy_infra_ui/windows/.gitignore new file mode 100644 index 0000000000..b3eb2be169 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/app_flowy/packages/flowy_infra_ui/windows/CMakeLists.txt b/app_flowy/packages/flowy_infra_ui/windows/CMakeLists.txt new file mode 100644 index 0000000000..27ce69d238 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/windows/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.15) +set(PROJECT_NAME "flowy_infra_ui") +project(${PROJECT_NAME} LANGUAGES CXX) + +# This value is used when generating builds using this plugin, so it must +# not be changed +set(PLUGIN_NAME "flowy_infra_ui_plugin") + +add_library(${PLUGIN_NAME} SHARED + "flowy_infra_ui_plugin.cpp" +) +apply_standard_settings(${PLUGIN_NAME}) +set_target_properties(${PLUGIN_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) +target_include_directories(${PLUGIN_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) + +# List of absolute paths to libraries that should be bundled with the plugin +set(flowy_infra_ui_bundled_libraries + "" + PARENT_SCOPE +) diff --git a/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp b/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp new file mode 100644 index 0000000000..f4329eacf4 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp @@ -0,0 +1,82 @@ +#include "include/flowy_infra_ui/flowy_infra_ui_plugin.h" + +// This must be included before many other Windows headers. +#include + +// For getPlatformVersion; remove unless needed for your plugin implementation. +#include + +#include +#include +#include + +#include +#include +#include + +namespace { + +class FlowyInfraUiPlugin : public flutter::Plugin { + public: + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); + + FlowyInfraUiPlugin(); + + virtual ~FlowyInfraUiPlugin(); + + private: + // Called when a method is called on this plugin's channel from Dart. + void HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result); +}; + +// static +void FlowyInfraUiPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarWindows *registrar) { + auto channel = + std::make_unique>( + registrar->messenger(), "flowy_infra_ui", + &flutter::StandardMethodCodec::GetInstance()); + + auto plugin = std::make_unique(); + + channel->SetMethodCallHandler( + [plugin_pointer = plugin.get()](const auto &call, auto result) { + plugin_pointer->HandleMethodCall(call, std::move(result)); + }); + + registrar->AddPlugin(std::move(plugin)); +} + +FlowyInfraUiPlugin::FlowyInfraUiPlugin() {} + +FlowyInfraUiPlugin::~FlowyInfraUiPlugin() {} + +void FlowyInfraUiPlugin::HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result) { + if (method_call.method_name().compare("getPlatformVersion") == 0) { + std::ostringstream version_stream; + version_stream << "Windows "; + if (IsWindows10OrGreater()) { + version_stream << "10+"; + } else if (IsWindows8OrGreater()) { + version_stream << "8"; + } else if (IsWindows7OrGreater()) { + version_stream << "7"; + } + result->Success(flutter::EncodableValue(version_stream.str())); + } else { + result->NotImplemented(); + } +} + +} // namespace + +void FlowyInfraUiPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + FlowyInfraUiPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +} diff --git a/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h b/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h new file mode 100644 index 0000000000..cdd90185ab --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h @@ -0,0 +1,23 @@ +#ifndef FLUTTER_PLUGIN_FLOWY_INFRA_UI_PLUGIN_H_ +#define FLUTTER_PLUGIN_FLOWY_INFRA_UI_PLUGIN_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void FlowyInfraUiPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_PLUGIN_FLOWY_INFRA_UI_PLUGIN_H_