Skip to content

Commit

Permalink
替换desktop_window插件为window_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Feb 4, 2023
1 parent d49ba45 commit e95a335
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
6 changes: 1 addition & 5 deletions lib/home/splash_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:desktop_window/desktop_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/demo/demo_page.dart';
import 'package:flutter_deer/login/login_router.dart';
Expand Down Expand Up @@ -46,10 +45,7 @@ class _SplashPageState extends State<SplashPage> {
}
_initSplash();
});
/// 设置桌面端窗口大小
if (Device.isDesktop) {
DesktopWindow.setWindowSize(const Size(400, 800));
}

if (Device.isAndroid) {
const QuickActions quickActions = QuickActions();
quickActions.initialize((String shortcutType) async {
Expand Down
20 changes: 20 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:sp_util/sp_util.dart';
import 'package:url_strategy/url_strategy.dart';
import 'package:window_manager/window_manager.dart';

Future<void> main() async {
// debugProfileBuildsEnabled = true;
Expand All @@ -30,6 +31,25 @@ Future<void> main() async {
/// 确保初始化完成
WidgetsFlutterBinding.ensureInitialized();

if (Device.isDesktop) {
await WindowManager.instance.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
/// 隐藏标题栏及操作按钮
// await windowManager.setTitleBarStyle(
// TitleBarStyle.hidden,
// windowButtonVisibility: false,
// );
/// 设置桌面端窗口大小
await windowManager.setSize(const Size(400, 800));
await windowManager.setMinimumSize(const Size(400, 800));
/// 居中显示
await windowManager.center();
await windowManager.show();
await windowManager.setPreventClose(false);
await windowManager.setSkipTaskbar(false);
});
}

/// 去除URL中的“#”(hash),仅针对Web。默认为setHashUrlStrategy
/// 注意本地部署和远程部署时`web/index.html`中的base标签,https://github.com/flutter/flutter/issues/69760
setPathUrlStrategy();
Expand Down
6 changes: 4 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
import FlutterMacOS
import Foundation

import desktop_window
import device_info_plus
import path_provider_macos
import screen_retriever
import shared_preferences_macos
import sqflite
import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DesktopWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWindowPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
6 changes: 4 additions & 2 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,24 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework",
"${BUILT_PRODUCTS_DIR}/desktop_window/desktop_window.framework",
"${BUILT_PRODUCTS_DIR}/device_info_plus/device_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_macos/path_provider_macos.framework",
"${BUILT_PRODUCTS_DIR}/screen_retriever/screen_retriever.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_macos/shared_preferences_macos.framework",
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher_macos/url_launcher_macos.framework",
"${BUILT_PRODUCTS_DIR}/window_manager/window_manager.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMDB.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/desktop_window.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_macos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/screen_retriever.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_macos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_macos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/window_manager.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ dependencies:
vibration_web: 1.6.5
# 获取当前设备信息 https://github.com/fluttercommunity/plus_plugins/tree/main/packages/device_info_plus
device_info_plus: 8.0.0
# 改变桌面端窗口大小(MacOS/Linux/Windows) https://github.com/mix1009/desktop_window
desktop_window: 0.4.0
# 桌面应用调整窗口的大小和位置 https://github.com/leanflutter/window_manager
window_manager: 0.3.0
# 高德2D地图插件(支持Web) https://github.com/simplezhli/flutter_2d_amap
flutter_2d_amap:
git:
Expand Down
9 changes: 6 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

#include "generated_plugin_registrant.h"

#include <desktop_window/desktop_window_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
DesktopWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopWindowPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
3 changes: 2 additions & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
desktop_window
screen_retriever
url_launcher_windows
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit e95a335

Please sign in to comment.