diff --git a/lib/storage/app_storage.dart b/lib/storage/app_storage.dart index f86b27a..c4fc7aa 100644 --- a/lib/storage/app_storage.dart +++ b/lib/storage/app_storage.dart @@ -6,9 +6,13 @@ import 'package:flutter/services.dart'; import 'package:flutter_unit_mac/app/res/cons.dart'; import 'package:flutter_unit_mac/app/res/sp.dart'; import 'package:flutter_unit_mac/blocs/global/global_state.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart' as path; +import 'package:sqflite_common/sqlite_api.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; + +import 'dao/db_setup/setup_db.dart'; /// create by 张风捷特烈 on 2020-03-04 /// contact me by email 1981462002@qq.com /// 说明: @@ -47,21 +51,23 @@ class AppStorage { // 初始化数据库 Future initDb() async { - var databasesPath = await getDatabasesPath(); - var dbPath = path.join(databasesPath, "flutter.db"); - var exists = await databaseExists(dbPath); - if (!exists) { - try { - await Directory(path.dirname(dbPath)).create(recursive: true); - print("========= assets ======拷贝完成===="); - } catch (_) {} - ByteData data = await rootBundle.load(path.join("assets", "flutter.db")); + setupDatabase(); + var databasesPath = await getApplicationSupportDirectory(); + var dbPath = path.join(databasesPath.path, "flutter.db"); + + var file = File(dbPath); + if (!file.existsSync()) { + await Directory(path.dirname(dbPath)).create(recursive: true); + ByteData data = await rootBundle.load("assets/flutter.db"); List bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); await File(dbPath).writeAsBytes(bytes, flush: true); + print("========= assets ======拷贝完成==${file.path}=="); } else { - print("========= 数据库 ======已存在===="); + print("========= 数据库 ======已存在==${file.path}=="); } - return await openDatabase(dbPath, readOnly: false); + + var databaseFactory = databaseFactoryFfi; + return await databaseFactory.openDatabase(dbPath); } } diff --git a/lib/storage/dao/db_setup/setup_db.dart b/lib/storage/dao/db_setup/setup_db.dart new file mode 100644 index 0000000..680eb4f --- /dev/null +++ b/lib/storage/dao/db_setup/setup_db.dart @@ -0,0 +1,25 @@ +import 'dart:ffi'; +import 'dart:io'; + +import 'package:sqlite3/open.dart'; +import 'package:sqlite3/sqlite3.dart'; +import 'package:path/path.dart'; + +setupDatabase(){ + if(Platform.isWindows){ + var location = Directory.current.path; + windowsInit(join(location, 'sqlite3.dll')); + } +} + +void windowsInit(String path) { + open.overrideFor(OperatingSystem.windows, () { + try { + return DynamicLibrary.open(path); + } catch (e) { + stderr.writeln('Failed to load sqlite3.dll at $path'); + rethrow; + } + }); + sqlite3.openInMemory().dispose(); +} \ No newline at end of file diff --git a/plugins/path_provider_fde/.gitignore b/plugins/path_provider_fde/.gitignore new file mode 100644 index 0000000..0393a47 --- /dev/null +++ b/plugins/path_provider_fde/.gitignore @@ -0,0 +1,5 @@ +.dart_tool +.packages +.flutter-plugins +.flutter-plugins-dependencies +pubspec.lock diff --git a/plugins/path_provider_fde/LICENSE b/plugins/path_provider_fde/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/plugins/path_provider_fde/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/plugins/path_provider_fde/README.md b/plugins/path_provider_fde/README.md new file mode 100644 index 0000000..576ad17 --- /dev/null +++ b/plugins/path_provider_fde/README.md @@ -0,0 +1,19 @@ +# path_provider_fde + +Prototype Windows implementation of +[path_provider](https://pub.dev/packages/path_provider) + +See [the main flutter_plugins README](../README.md) for general information about what +this plugin is and how to use it. + +## Supported Platforms + +- [x] Windows + +macOS and Linux are already supported by `path_provider`. + +## Caveats + +The paths returned by this plugin may change in the future. Most notably, +`getApplicationSupportDirectory` will likely return a different path in the +future. diff --git a/plugins/path_provider_fde/ios/path_provider_fde.podspec b/plugins/path_provider_fde/ios/path_provider_fde.podspec new file mode 100644 index 0000000..f13d7e8 --- /dev/null +++ b/plugins/path_provider_fde/ios/path_provider_fde.podspec @@ -0,0 +1,21 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'path_provider_fde' + s.version = '0.0.1' + s.summary = 'No-op implementation of path_provider_fde desktop plugin to avoid build issues on iOS' + s.description = <<-DESC +temp fake path_provider_fde plugin + DESC + s.homepage = 'https://github.com/google/flutter-desktop-embedding/tree/master/plugins/path_provider_fde' + s.license = { :file => '../LICENSE' } + s.author = { 'Flutter Desktop Embedding Developers' => 'flutter-desktop-embedding-dev@googlegroups.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + + s.ios.deployment_target = '8.0' +end + diff --git a/plugins/path_provider_fde/pubspec.yaml b/plugins/path_provider_fde/pubspec.yaml new file mode 100644 index 0000000..a67710c --- /dev/null +++ b/plugins/path_provider_fde/pubspec.yaml @@ -0,0 +1,20 @@ +name: path_provider_fde +description: Temporary desktop implmentations of path_provider from flutter/plugins +version: 0.0.1 + +# Do not publish this plugin. See: +# https://github.com/google/flutter-desktop-embedding/blob/master/plugins/README.md#using-plugins +publish_to: none + +flutter: + plugin: + platforms: + windows: + pluginClass: PathProviderPlugin + +environment: + sdk: ">=2.1.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter diff --git a/plugins/path_provider_fde/windows/.gitignore b/plugins/path_provider_fde/windows/.gitignore new file mode 100644 index 0000000..b3eb2be --- /dev/null +++ b/plugins/path_provider_fde/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/plugins/path_provider_fde/windows/CMakeLists.txt b/plugins/path_provider_fde/windows/CMakeLists.txt new file mode 100644 index 0000000..5144bfd --- /dev/null +++ b/plugins/path_provider_fde/windows/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +set(PROJECT_NAME "path_provider_fde") +project(${PROJECT_NAME} LANGUAGES CXX) + +set(PLUGIN_NAME "${PROJECT_NAME}_plugin") + +add_library(${PLUGIN_NAME} SHARED + "path_provider_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_compile_definitions(${PLUGIN_NAME} PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) +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(path_provider_fde_bundled_libraries + "" + PARENT_SCOPE +) diff --git a/plugins/path_provider_fde/windows/include/path_provider_fde/path_provider_plugin.h b/plugins/path_provider_fde/windows/include/path_provider_fde/path_provider_plugin.h new file mode 100644 index 0000000..eb1e570 --- /dev/null +++ b/plugins/path_provider_fde/windows/include/path_provider_fde/path_provider_plugin.h @@ -0,0 +1,36 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef PLUGINS_PATH_PROVIDER_PLUGIN_WINDOWS_H_ +#define PLUGINS_PATH_PROVIDER_PLUGIN_WINDOWS_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 PathProviderPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // PLUGINS_PATH_PROVIDER_PLUGIN_WINDOWS_H_ diff --git a/plugins/path_provider_fde/windows/path_provider_plugin.cpp b/plugins/path_provider_fde/windows/path_provider_plugin.cpp new file mode 100644 index 0000000..7d3688c --- /dev/null +++ b/plugins/path_provider_fde/windows/path_provider_plugin.cpp @@ -0,0 +1,167 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "include/path_provider_fde/path_provider_plugin.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace { + +using flutter::EncodableValue; + +// Converts an null-terminated array of wchar_t's to a std::string. +std::string StdStringFromWideChars(wchar_t *wide_chars) { + std::wstring_convert> wide_to_utf8; + return wide_to_utf8.to_bytes(wide_chars); +} + +// Gets the path to the given folder ID, without verifying that it exists, +// or an empty string on failure. +std::string GetFolderPath(REFKNOWNFOLDERID folder_id) { + wchar_t *wide_path = nullptr; + if (!SUCCEEDED(SHGetKnownFolderPath(folder_id, KF_FLAG_DONT_VERIFY, nullptr, + &wide_path))) { + return ""; + } + std::string path = StdStringFromWideChars(wide_path); + CoTaskMemFree(wide_path); + return path; +} + +// Returns the name of the executable, without the .exe extension, or an empty +// string on failure. +std::string GetExecutableName() { + wchar_t buffer[MAX_PATH]; + if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) { + return ""; + } + std::string executable_path = StdStringFromWideChars(buffer); + size_t last_separator_position = executable_path.find_last_of('\\'); + std::string executable_name; + if (last_separator_position == std::string::npos) { + executable_name = executable_path; + } else { + executable_name = executable_path.substr(last_separator_position + 1); + } + // Strip the .exe extension, if present. + std::string extension = ".exe"; + if (executable_name.compare(executable_name.size() - extension.size(), + extension.size(), extension) == 0) { + executable_name = + executable_name.substr(0, executable_name.size() - extension.size()); + } + return executable_name; +} + +class PathProviderPlugin : public flutter::Plugin { + public: + static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar); + + virtual ~PathProviderPlugin(); + + private: + PathProviderPlugin(); + + // Called when a method is called on plugin channel; + void HandleMethodCall( + const flutter::MethodCall<> &method_call, + std::unique_ptr> result); +}; + +// static +void PathProviderPlugin::RegisterWithRegistrar( + flutter::PluginRegistrar *registrar) { + auto channel = std::make_unique>( + registrar->messenger(), "plugins.flutter.io/path_provider", + &flutter::StandardMethodCodec::GetInstance()); + + // Uses new instead of make_unique due to private constructor. + std::unique_ptr plugin(new PathProviderPlugin()); + + channel->SetMethodCallHandler( + [plugin_pointer = plugin.get()](const auto &call, auto result) { + plugin_pointer->HandleMethodCall(call, std::move(result)); + }); + + registrar->AddPlugin(std::move(plugin)); +} + +PathProviderPlugin::PathProviderPlugin() = default; + +PathProviderPlugin::~PathProviderPlugin() = default; + +void PathProviderPlugin::HandleMethodCall( + const flutter::MethodCall<> &method_call, + std::unique_ptr> result) { + if (method_call.method_name().compare("getTemporaryDirectory") == 0) { + wchar_t path_buffer[MAX_PATH]; + DWORD length = GetTempPath(MAX_PATH, path_buffer); + if (length == 0 || length > MAX_PATH) { + result->Error("Unable to get temporary path"); + return; + } + std::string result_path = StdStringFromWideChars(path_buffer); + result->Success(EncodableValue(result_path)); + } else if (method_call.method_name().compare( + "getApplicationSupportDirectory") == 0) { + std::string path = GetFolderPath(FOLDERID_RoamingAppData); + if (path.empty()) { + result->Error("Unable to get application data path"); + return; + } + // Use the executable name as the subdirectory for now. + std::string exe_name = GetExecutableName(); + if (exe_name.empty()) { + result->Error("Unable to get exe name"); + return; + } + std::ostringstream response_stream; + response_stream << path << "\\" << exe_name; + result->Success(EncodableValue(response_stream.str())); + } else if (method_call.method_name().compare( + "getApplicationDocumentsDirectory") == 0) { + std::string path = GetFolderPath(FOLDERID_Documents); + if (path.empty()) { + result->Error("Unable to get documents path"); + return; + } + result->Success(EncodableValue(path)); + } else if (method_call.method_name().compare("getDownloadsDirectory") == 0) { + std::string path = GetFolderPath(FOLDERID_Downloads); + if (path.empty()) { + result->Error("Unable to get downloads path"); + return; + } + result->Success(EncodableValue(path)); + } else { + result->NotImplemented(); + } +} + +} // namespace + +void PathProviderPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + PathProviderPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +} diff --git a/pubspec.lock b/pubspec.lock index 2cc3e5c..537d2d9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.5.0-nullsafety.1" bloc: dependency: transitive description: @@ -21,35 +21,42 @@ packages: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0-nullsafety.1" characters: dependency: transitive description: name: characters url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0-nullsafety.3" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" cupertino_icons: dependency: "direct main" description: @@ -70,7 +77,14 @@ packages: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0-nullsafety.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" file: dependency: transitive description: @@ -120,21 +134,35 @@ packages: name: js url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.3-nullsafety.3" + version: "0.6.3-nullsafety.1" matcher: dependency: transitive description: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0-nullsafety.4" + moor: + dependency: transitive + description: + name: moor + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.4.0" + moor_ffi: + dependency: transitive + description: + name: moor_ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.8.0" nested: dependency: transitive description: @@ -148,7 +176,7 @@ packages: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.8.0-nullsafety.1" path_provider: dependency: "direct main" description: @@ -156,6 +184,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.6.11" + path_provider_fde: + dependency: "direct main" + description: + path: "plugins/path_provider_fde" + relative: true + source: path + version: "0.0.1" path_provider_linux: dependency: transitive description: @@ -176,7 +211,21 @@ packages: name: path_provider_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.9.2" platform: dependency: transitive description: @@ -225,7 +274,14 @@ packages: name: shared_preferences url: "https://pub.flutter-io.cn" source: hosted - version: "0.5.6+3" + version: "0.5.12+4" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.2+4" shared_preferences_macos: dependency: transitive description: @@ -247,6 +303,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.1.2+4" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+3" sky_engine: dependency: transitive description: flutter @@ -258,7 +321,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.8.0-nullsafety.2" sqflite: dependency: "direct main" description: @@ -273,27 +336,48 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0+1" + sqflite_common_ffi: + dependency: "direct main" + description: + name: sqflite_common_ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.0+1" + sqlite3: + dependency: transitive + description: + name: sqlite3 + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.8" + sqlite3_flutter_libs: + dependency: transitive + description: + name: sqlite3_flutter_libs + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.10.0-nullsafety.2" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0-nullsafety.1" synchronized: dependency: transitive description: @@ -307,14 +391,14 @@ packages: name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.19-nullsafety.2" toggle_rotate: dependency: "direct main" description: @@ -328,7 +412,7 @@ packages: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0-nullsafety.3" url_launcher: dependency: "direct main" description: @@ -363,7 +447,14 @@ packages: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0-nullsafety.3" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.4" xdg_directories: dependency: transitive description: @@ -372,5 +463,5 @@ packages: source: hosted version: "0.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.10.0-110 <=2.11.0-213.0.dev" flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 474837e..d67d551 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,11 +27,14 @@ dependencies: sqflite: ^1.2.1 #数据库 toggle_rotate: ^0.0.5 flutter_star: ^0.1.2 # 星星组件 - shared_preferences: ^0.5.6+3 # xml 固化 + shared_preferences: ^0.5.12+4 # xml 固化 + sqflite_common_ffi: url_launcher: ^5.4.2 # url path_provider: ^1.6.11 intl: ^0.16.1 # 格式化 share: ^0.6.3+6 + path_provider_fde: + path: ./plugins/path_provider_fde dev_dependencies: flutter_test: sdk: flutter diff --git a/sqlite3.dll b/sqlite3.dll new file mode 100644 index 0000000..401d256 Binary files /dev/null and b/sqlite3.dll differ diff --git a/windows/AppConfiguration.props b/windows/AppConfiguration.props deleted file mode 100644 index 7cfa4f8..0000000 --- a/windows/AppConfiguration.props +++ /dev/null @@ -1,6 +0,0 @@ - - - - flutter_unit_mac - - diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 65af544..39790b3 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15) -project(flutter_unit LANGUAGES CXX) +project(flutter_db LANGUAGES CXX) -set(BINARY_NAME "flutter_unit") +set(BINARY_NAME "flutter_db") cmake_policy(SET CMP0063 NEW) diff --git a/windows/FlutterBuild.vcxproj b/windows/FlutterBuild.vcxproj deleted file mode 100644 index 8ef93f9..0000000 --- a/windows/FlutterBuild.vcxproj +++ /dev/null @@ -1,50 +0,0 @@ - - - - - Debug - x64 - - - Profile - x64 - - - Release - x64 - - - - 15.0 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F} - Flutter Build - 10.0 - - - - v141 - v142 - - - - - - - - - - - - - - "$(ProjectDir)scripts\prepare_dependencies" $(Configuration) - Running Flutter backend build - force_to_run_every_time - - - - - - - - diff --git a/windows/Runner.sln b/windows/Runner.sln deleted file mode 100644 index 7bfc8e0..0000000 --- a/windows/Runner.sln +++ /dev/null @@ -1,43 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29709.97 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Runner", "Runner.vcxproj", "{5A827760-CF8B-408A-99A3-B6C0AD2271E7}" - ProjectSection(ProjectDependencies) = postProject - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F} = {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Flutter Build", "FlutterBuild.vcxproj", "{6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Flutter Plugins", "Flutter Plugins", "{5C2E738A-1DD3-445A-AAC8-EEB9648DD07C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Profile|x64 = Profile|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Debug|x64.ActiveCfg = Debug|x64 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Debug|x64.Build.0 = Debug|x64 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Profile|x64.ActiveCfg = Profile|x64 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Profile|x64.Build.0 = Profile|x64 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Release|x64.ActiveCfg = Release|x64 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Release|x64.Build.0 = Release|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Debug|x64.ActiveCfg = Debug|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Debug|x64.Build.0 = Debug|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Profile|x64.ActiveCfg = Profile|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Profile|x64.Build.0 = Profile|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Release|x64.ActiveCfg = Release|x64 - {6419BF13-6ECD-4CD2-9E85-E566A1F03F8F}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B8A69CB0-A974-4774-9EBD-1E5EECACD186} - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - EndGlobalSection -EndGlobal \ No newline at end of file diff --git a/windows/Runner.vcxproj b/windows/Runner.vcxproj deleted file mode 100644 index 7a151a6..0000000 --- a/windows/Runner.vcxproj +++ /dev/null @@ -1,260 +0,0 @@ - - - - - Debug - x64 - - - Profile - x64 - - - Release - x64 - - - - 15.0 - {5A827760-CF8B-408A-99A3-B6C0AD2271E7} - flutter_unit_mac - 10.0 - - - - Application - true - v141 - v142 - Unicode - - - Application - false - v141 - v142 - true - Unicode - - - Application - false - v141 - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - - - - - - $(ProjectDir)..\build\windows\$(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)..\build\windows\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ - - - $(ProjectDir)..\build\windows\$(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)..\build\windows\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ - - - $(ProjectDir)..\build\windows\$(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)..\build\windows\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ - - - - Level4 - Disabled - true - true - $(ProjectDir);$(FLUTTER_EPHEMERAL_DIR);$(FLUTTER_EPHEMERAL_DIR)\cpp_client_wrapper\include;%(AdditionalIncludeDirectories) - _MBCS;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) - true - 4100 - - - flutter_windows.dll.lib;%(AdditionalDependencies) - $(FLUTTER_EPHEMERAL_DIR);$(OutDir)..\Plugins;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - - - - - - "$(ProjectDir)scripts\bundle_assets_and_deps" "$(FLUTTER_EPHEMERAL_DIR)\" "$(OutputPath)" "$(OutputPath)..\Plugins\" "$(TargetFileName)" - - - Bundling dependencies - Dummy_Run_Always - - - - - - - Level4 - MaxSpeed - true - true - true - true - $(ProjectDir);$(FLUTTER_EPHEMERAL_DIR);$(FLUTTER_EPHEMERAL_DIR)\cpp_client_wrapper\include;%(AdditionalIncludeDirectories) - _MBCS;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) - true - 4100 - - - true - true - flutter_windows.dll.lib;%(AdditionalDependencies) - $(FLUTTER_EPHEMERAL_DIR);$(OutDir)..\Plugins;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - - - - - - "$(ProjectDir)scripts\bundle_assets_and_deps" "$(FLUTTER_EPHEMERAL_DIR)\" "$(OutputPath)" "$(OutputPath)..\Plugins\" "$(TargetFileName)" - - - Bundling dependencies - Dummy_Run_Always - - - - - - - Level4 - MaxSpeed - true - true - true - true - $(ProjectDir);$(FLUTTER_EPHEMERAL_DIR);$(FLUTTER_EPHEMERAL_DIR)\cpp_client_wrapper\include;%(AdditionalIncludeDirectories) - _MBCS;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) - true - 4100 - - - true - true - flutter_windows.dll.lib;%(AdditionalDependencies) - $(FLUTTER_EPHEMERAL_DIR);$(OutDir)..\Plugins;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - - - - - - "$(ProjectDir)scripts\bundle_assets_and_deps" "$(FLUTTER_EPHEMERAL_DIR)\" "$(OutputPath)" "$(OutputPath)..\Plugins\" "$(TargetFileName)" - - - Bundling dependencies - Dummy_Run_Always - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(SolutionDir) - - diff --git a/windows/Runner.vcxproj.filters b/windows/Runner.vcxproj.filters deleted file mode 100644 index aff5122..0000000 --- a/windows/Runner.vcxproj.filters +++ /dev/null @@ -1,82 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {2761a4b5-57b2-4d50-a677-d20ddc17a7f1} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files\Client Wrapper - - - Source Files\Client Wrapper - - - Source Files\Client Wrapper - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - - - - Resource Files - - - - - Resource Files - - - diff --git a/windows/flutter/.template_version b/windows/flutter/.template_version deleted file mode 100644 index 0cfbf08..0000000 --- a/windows/flutter/.template_version +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/windows/flutter/CMakeLists.txt b/windows/flutter/CMakeLists.txt index 3c1726f..c7a8c76 100644 --- a/windows/flutter/CMakeLists.txt +++ b/windows/flutter/CMakeLists.txt @@ -34,8 +34,8 @@ add_dependencies(flutter flutter_assemble) # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE - "engine_method_result.cc" - "standard_codec.cc" + "core_implementations.cc" + "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN @@ -43,6 +43,7 @@ list(APPEND CPP_WRAPPER_SOURCES_PLUGIN ) 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}/") @@ -79,11 +80,13 @@ add_dependencies(flutter_wrapper_app flutter_assemble) # _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} - ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" diff --git a/windows/flutter/GeneratedPlugins.props b/windows/flutter/GeneratedPlugins.props deleted file mode 100644 index d3d26c7..0000000 --- a/windows/flutter/GeneratedPlugins.props +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4bfa0f3..3f78b6b 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -4,6 +4,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + PathProviderPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PathProviderPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 4d10c25..3fa4322 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + path_provider_fde ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt index 83e5aca..977e38b 100644 --- a/windows/runner/CMakeLists.txt +++ b/windows/runner/CMakeLists.txt @@ -7,12 +7,12 @@ add_executable(${BINARY_NAME} WIN32 "run_loop.cpp" "utils.cpp" "win32_window.cpp" - "window_configuration.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/windows/runner/Runner.rc b/windows/runner/Runner.rc index 5b41a82..6d5db82 100644 --- a/windows/runner/Runner.rc +++ b/windows/runner/Runner.rc @@ -54,6 +54,57 @@ END // 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.toly1994" "\0" + VALUE "FileDescription", "A new Flutter application." "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "flutter_db" "\0" + VALUE "LegalCopyright", "Copyright (C) 2020 com.toly1994. All rights reserved." "\0" + VALUE "OriginalFilename", "flutter_db.exe" "\0" + VALUE "ProductName", "flutter_db" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + #endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/windows/runner/flutter_window.cpp b/windows/runner/flutter_window.cpp index fe980cf..c422723 100644 --- a/windows/runner/flutter_window.cpp +++ b/windows/runner/flutter_window.cpp @@ -1,5 +1,7 @@ #include "flutter_window.h" +#include + #include "flutter/generated_plugin_registrant.h" FlutterWindow::FlutterWindow(RunLoop* run_loop, @@ -8,22 +10,55 @@ FlutterWindow::FlutterWindow(RunLoop* run_loop, FlutterWindow::~FlutterWindow() {} -void FlutterWindow::OnCreate() { - Win32Window::OnCreate(); +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } - // The size here is arbitrary since SetChildContent will resize it. - flutter_controller_ = - std::make_unique(100, 100, project_); - RegisterPlugins(flutter_controller_.get()); - run_loop_->RegisterFlutterInstance(flutter_controller_.get()); + 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()); + run_loop_->RegisterFlutterInstance(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; } void FlutterWindow::OnDestroy() { if (flutter_controller_) { - run_loop_->UnregisterFlutterInstance(flutter_controller_.get()); + run_loop_->UnregisterFlutterInstance(flutter_controller_->engine()); 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 opporutunity 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/windows/runner/flutter_window.h b/windows/runner/flutter_window.h index 4f41e16..b663ddd 100644 --- a/windows/runner/flutter_window.h +++ b/windows/runner/flutter_window.h @@ -1,14 +1,14 @@ -#ifndef FLUTTER_WINDOW_H_ -#define FLUTTER_WINDOW_H_ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ #include #include +#include + #include "run_loop.h" #include "win32_window.h" -#include - // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { public: @@ -20,8 +20,10 @@ class FlutterWindow : public Win32Window { protected: // Win32Window: - void OnCreate() override; + bool OnCreate() override; void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; private: // The run loop driving events for this window. @@ -34,4 +36,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index c428b4b..4f154b9 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -4,28 +4,27 @@ #include "flutter_window.h" #include "run_loop.h" -#include "window_configuration.h" +#include "utils.h" -int APIENTRY wWinMain(_In_ HINSTANCE instance, - _In_opt_ HINSTANCE prev, - _In_ wchar_t* command_line, - _In_ int show_command) { +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()) { - ::AllocConsole(); + CreateAndAttachConsole(); } - // Initialize COM, so that it is available for use in the library and/or plugins. + // Initialize COM, so that it is available for use in the library and/or + // plugins. ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); RunLoop run_loop; flutter::DartProject project(L"data"); FlutterWindow window(&run_loop, project); - Win32Window::Point origin(kFlutterWindowOriginX, kFlutterWindowOriginY); - Win32Window::Size size(kFlutterWindowWidth, kFlutterWindowHeight); - if (!window.CreateAndShow(kFlutterWindowTitle, origin, size)) { + Win32Window::Point origin(200, 100); + Win32Window::Size size(800, 600); + if (!window.CreateAndShow(L"flutter_db", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/windows/runner/run_loop.cpp b/windows/runner/run_loop.cpp index f91d6d4..2d6636a 100644 --- a/windows/runner/run_loop.cpp +++ b/windows/runner/run_loop.cpp @@ -1,9 +1,6 @@ #include "run_loop.h" -#include -// Don't stomp std::min/std::max -#undef max -#undef min +#include #include @@ -47,20 +44,19 @@ void RunLoop::Run() { } void RunLoop::RegisterFlutterInstance( - flutter::FlutterViewController* flutter_instance) { + flutter::FlutterEngine* flutter_instance) { flutter_instances_.insert(flutter_instance); } void RunLoop::UnregisterFlutterInstance( - flutter::FlutterViewController* flutter_instance) { + flutter::FlutterEngine* flutter_instance) { flutter_instances_.erase(flutter_instance); } RunLoop::TimePoint RunLoop::ProcessFlutterMessages() { TimePoint next_event_time = TimePoint::max(); - for (auto flutter_controller : flutter_instances_) { - std::chrono::nanoseconds wait_duration = - flutter_controller->ProcessMessages(); + for (auto instance : flutter_instances_) { + std::chrono::nanoseconds wait_duration = instance->ProcessMessages(); if (wait_duration != std::chrono::nanoseconds::max()) { next_event_time = std::min(next_event_time, TimePoint::clock::now() + wait_duration); diff --git a/windows/runner/run_loop.h b/windows/runner/run_loop.h index 442a58e..000d362 100644 --- a/windows/runner/run_loop.h +++ b/windows/runner/run_loop.h @@ -1,7 +1,7 @@ -#ifndef RUN_LOOP_H_ -#define RUN_LOOP_H_ +#ifndef RUNNER_RUN_LOOP_H_ +#define RUNNER_RUN_LOOP_H_ -#include +#include #include #include @@ -22,11 +22,11 @@ class RunLoop { // Registers the given Flutter instance for event servicing. void RegisterFlutterInstance( - flutter::FlutterViewController* flutter_instance); + flutter::FlutterEngine* flutter_instance); // Unregisters the given Flutter instance from event servicing. void UnregisterFlutterInstance( - flutter::FlutterViewController* flutter_instance); + flutter::FlutterEngine* flutter_instance); private: using TimePoint = std::chrono::steady_clock::time_point; @@ -34,7 +34,7 @@ class RunLoop { // Processes all currently pending messages for registered Flutter instances. TimePoint ProcessFlutterMessages(); - std::set flutter_instances_; + std::set flutter_instances_; }; -#endif // RUN_LOOP_H_ +#endif // RUNNER_RUN_LOOP_H_ diff --git a/windows/runner/utils.h b/windows/runner/utils.h index d247a66..d792603 100644 --- a/windows/runner/utils.h +++ b/windows/runner/utils.h @@ -1,8 +1,8 @@ -#ifndef CONSOLE_UTILS_H_ -#define CONSOLE_UTILS_H_ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ // Creates a console for the process, and redirects stdout and stderr to // it for both the runner and the Flutter library. void CreateAndAttachConsole(); -#endif // CONSOLE_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/windows/runner/win32_window.cpp b/windows/runner/win32_window.cpp index 677a9a6..efc3eb9 100644 --- a/windows/runner/win32_window.cpp +++ b/windows/runner/win32_window.cpp @@ -122,9 +122,11 @@ bool Win32Window::CreateAndShow(const std::wstring& title, Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); - OnCreate(); + if (!window) { + return false; + } - return window != nullptr; + return OnCreate(); } // static @@ -152,13 +154,6 @@ Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { - auto window = - reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - - if (window == nullptr) { - return 0; - } - switch (message) { case WM_DESTROY: window_handle_ = nullptr; @@ -179,8 +174,7 @@ Win32Window::MessageHandler(HWND hwnd, return 0; } case WM_SIZE: - RECT rect; - GetClientRect(hwnd, &rect); + RECT rect = GetClientArea(); if (child_content_ != nullptr) { // Size and position the child window. MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, @@ -193,11 +187,6 @@ Win32Window::MessageHandler(HWND hwnd, SetFocus(child_content_); } return 0; - - // Messages that are directly forwarded to embedding. - case WM_FONTCHANGE: - SendMessage(child_content_, WM_FONTCHANGE, NULL, NULL); - return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -223,8 +212,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { void Win32Window::SetChildContent(HWND content) { child_content_ = content; SetParent(content, window_handle_); - RECT frame; - GetClientRect(window_handle_, &frame); + RECT frame = GetClientArea(); MoveWindow(content, frame.left, frame.top, frame.right - frame.left, frame.bottom - frame.top, true); @@ -232,6 +220,12 @@ void Win32Window::SetChildContent(HWND content) { SetFocus(child_content_); } +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + HWND Win32Window::GetHandle() { return window_handle_; } @@ -240,8 +234,9 @@ void Win32Window::SetQuitOnClose(bool quit_on_close) { quit_on_close_ = quit_on_close; } -void Win32Window::OnCreate() { +bool Win32Window::OnCreate() { // No-op; provided for subclasses. + return true; } void Win32Window::OnDestroy() { diff --git a/windows/runner/win32_window.h b/windows/runner/win32_window.h index 5cbb5d5..17ba431 100644 --- a/windows/runner/win32_window.h +++ b/windows/runner/win32_window.h @@ -1,8 +1,7 @@ -#ifndef WIN32_WINDOW_H_ -#define WIN32_WINDOW_H_ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ -#include -#include +#include #include #include @@ -52,6 +51,9 @@ class Win32Window { // 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 @@ -62,8 +64,8 @@ class Win32Window { LPARAM const lparam) noexcept; // Called when CreateAndShow is called, allowing subclass window-related - // setup. - virtual void OnCreate(); + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); // Called when Destroy is called. virtual void OnDestroy(); @@ -93,4 +95,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/windows/runner/window_configuration.cpp b/windows/runner/window_configuration.cpp deleted file mode 100644 index fa0d95b..0000000 --- a/windows/runner/window_configuration.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "window_configuration.h" - -const wchar_t* kFlutterWindowTitle = L"flutter_unit_mac"; -const unsigned int kFlutterWindowOriginX = 10; -const unsigned int kFlutterWindowOriginY = 10; -const unsigned int kFlutterWindowWidth = 800; -const unsigned int kFlutterWindowHeight = 600; diff --git a/windows/runner/window_configuration.h b/windows/runner/window_configuration.h deleted file mode 100644 index ea5cead..0000000 --- a/windows/runner/window_configuration.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef WINDOW_CONFIGURATION_ -#define WINDOW_CONFIGURATION_ - -// This is a temporary approach to isolate changes that people are likely to -// make to main.cpp, where the APIs are still in flux. This will reduce the -// need to resolve conflicts or re-create changes slightly differently every -// time the Windows Flutter API surface changes. -// -// Longer term there should be simpler configuration options for common -// customizations like this, without requiring native code changes. - -extern const wchar_t* kFlutterWindowTitle; -extern const unsigned int kFlutterWindowOriginX; -extern const unsigned int kFlutterWindowOriginY; -extern const unsigned int kFlutterWindowWidth; -extern const unsigned int kFlutterWindowHeight; - -#endif // WINDOW_CONFIGURATION_ diff --git a/windows/scripts/bundle_assets_and_deps.bat b/windows/scripts/bundle_assets_and_deps.bat deleted file mode 100644 index 25ae1c4..0000000 --- a/windows/scripts/bundle_assets_and_deps.bat +++ /dev/null @@ -1,37 +0,0 @@ -@echo off - -set FLUTTER_CACHE_DIR=%~1 -set BUNDLE_DIR=%~2 -set PLUGIN_DIR=%~3 -set EXE_NAME=%~4 - -set DATA_DIR=%BUNDLE_DIR%data - -if not exist "%DATA_DIR%" call mkdir "%DATA_DIR%" -if %errorlevel% neq 0 exit /b %errorlevel% - -:: Write the executable name to the location expected by the Flutter tool. -echo %EXE_NAME%>"%FLUTTER_CACHE_DIR%exe_filename" - -:: Copy the Flutter assets to the data directory. -set FLUTTER_APP_DIR=%~dp0..\.. -set ASSET_DIR_NAME=flutter_assets -set TARGET_ASSET_DIR=%DATA_DIR%\%ASSET_DIR_NAME% -if exist "%TARGET_ASSET_DIR%" call rmdir /s /q "%TARGET_ASSET_DIR%" -if %errorlevel% neq 0 exit /b %errorlevel% -call xcopy /s /e /i /q "%FLUTTER_APP_DIR%\build\%ASSET_DIR_NAME%" "%TARGET_ASSET_DIR%" -if %errorlevel% neq 0 exit /b %errorlevel% - -:: Copy the icudtl.dat file from the Flutter tree to the data directory. -call xcopy /y /d /q "%FLUTTER_CACHE_DIR%icudtl.dat" "%DATA_DIR%" -if %errorlevel% neq 0 exit /b %errorlevel% - -:: Copy the Flutter DLL to the target location. -call xcopy /y /d /q "%FLUTTER_CACHE_DIR%flutter_windows.dll" "%BUNDLE_DIR%" -if %errorlevel% neq 0 exit /b %errorlevel% - -:: Copy any Plugin DLLs to the target location. -if exist "%PLUGIN_DIR%" ( - call xcopy /y /d /q "%PLUGIN_DIR%"*.dll "%BUNDLE_DIR%" - if %errorlevel% neq 0 exit /b %errorlevel% -) diff --git a/windows/scripts/prepare_dependencies.bat b/windows/scripts/prepare_dependencies.bat deleted file mode 100644 index d05238b..0000000 --- a/windows/scripts/prepare_dependencies.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off - -:: Run flutter tool backend. -set BUILD_MODE=%~1 -"%FLUTTER_ROOT%\packages\flutter_tools\bin\tool_backend" windows-x64 %BUILD_MODE%