Skip to content

Commit

Permalink
Save window size for desktop versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hhanh00 committed Feb 13, 2023
1 parent b0e66c5 commit 8466be5
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 9 deletions.
31 changes: 30 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:warp_api/warp_api.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:window_manager/window_manager.dart';
import 'accounts.dart';
import 'animated_qr.dart';
import 'coin/coin.dart';
Expand Down Expand Up @@ -191,8 +192,36 @@ class LoadProgressState extends State<LoadProgress> {

final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();

void main() {
class OnWindow extends WindowListener {
@override
void onWindowResized() async {
final s = await windowManager.getSize();
final prefs = await SharedPreferences.getInstance();
prefs.setDouble('width', s.width);
prefs.setDouble('height', s.height);
}
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();

final prefs = await SharedPreferences.getInstance();
final width = prefs.getDouble('width');
final height = prefs.getDouble('height');
final size = width != null && height != null ? Size(width, height) : null;
WindowOptions windowOptions = WindowOptions(
center: true,
size: size,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
windowManager.addListener(OnWindow());
AwesomeNotifications().initialize(
'resource://drawable/res_notification',
[
Expand Down
8 changes: 8 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <awesome_notifications/awesome_notifications_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
Expand All @@ -17,7 +19,13 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) awesome_notifications_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AwesomeNotificationsPlugin");
awesome_notifications_plugin_register_with_registrar(awesome_notifications_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
awesome_notifications
screen_retriever
url_launcher_linux
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import awesome_notifications
import connectivity_plus_macos
import network_info_plus_macos
import path_provider_foundation
import screen_retriever
import share_plus_macos
import shared_preferences_foundation
import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
Expand All @@ -22,7 +24,9 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
NetworkInfoPlusPlugin.register(with: registry.registrar(forPlugin: "NetworkInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
12 changes: 12 additions & 0 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ PODS:
- Flutter
- FlutterMacOS
- ReachabilitySwift (5.0.0)
- screen_retriever (0.0.1):
- FlutterMacOS
- share_plus_macos (0.0.1):
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS
- window_manager (0.2.0):
- FlutterMacOS

DEPENDENCIES:
- app_links (from `Flutter/ephemeral/.symlinks/plugins/app_links/macos`)
Expand All @@ -31,9 +35,11 @@ DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral`)
- network_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/network_info_plus_macos/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`)
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
- share_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

SPEC REPOS:
trunk:
Expand All @@ -54,12 +60,16 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/network_info_plus_macos/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos
screen_retriever:
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
share_plus_macos:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
window_manager:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
app_links: 4481ed4d71f384b0c3ae5016f4633aa73d32ff67
Expand All @@ -70,9 +80,11 @@ SPEC CHECKSUMS:
network_info_plus_macos: d2b9e6c01c291449b91a584217aa53b113847dbd
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
url_launcher_macos: c04e4fa86382d4f94f6b38f14625708be3ae52e2
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

Expand Down
9 changes: 3 additions & 6 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,12 @@
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 327;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NAME)";
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.17;
PRODUCT_BUNDLE_IDENTIFIER = me.hanh.ywallet;
PROVISIONING_PROFILE_SPECIFIER = "";
STRIP_STYLE = "non-global";
Expand Down Expand Up @@ -555,13 +554,12 @@
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 327;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NAME)";
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.17;
PRODUCT_BUNDLE_IDENTIFIER = me.hanh.ywallet;
PROVISIONING_PROFILE_SPECIFIER = "";
STRIP_STYLE = "non-global";
Expand All @@ -579,13 +577,12 @@
CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 327;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NAME)";
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.17;
PRODUCT_BUNDLE_IDENTIFIER = me.hanh.ywallet;
PROVISIONING_PROFILE_SPECIFIER = "";
STRIP_STYLE = "non-global";
Expand Down
2 changes: 1 addition & 1 deletion packages/warp_api_ffi/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.18.0 <4.0.0"
dart: ">=2.18.0 <3.0.0"
flutter: ">=1.20.0"
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.4"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "4931f226ca158123ccd765325e9fbf360bfed0af9b460a10f960f9bb13d58323"
url: "https://pub.dev"
source: hosted
version: "0.1.6"
sensors_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1694,6 +1702,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.6.1"
window_manager:
dependency: "direct main"
description:
name: window_manager
sha256: "5bdd29dc5f1f3185fc90696373a571d77968e03e5e820fb1ecdbdade3f5d8fff"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
xdg_directories:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.3.0+372
version: 1.3.1+373

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -40,6 +40,7 @@ dependencies:
shared_preferences: ^2.0.7
shared_preferences_android:
shared_preferences_ios:
window_manager: ^0.3.0
flutter_markdown: ^0.6.6
velocity_x: ^3.3.0
decimal: ^2.1.0
Expand Down
6 changes: 6 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <network_info_plus_windows/network_info_plus_windows_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) {
AppLinksPluginCApiRegisterWithRegistrar(
Expand All @@ -27,6 +29,10 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
NetworkInfoPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("NetworkInfoPlusWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
local_auth_windows
network_info_plus_windows
screen_retriever
url_launcher_windows
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 8466be5

Please sign in to comment.