Desktop fixes for 0.25.0 (#24)
* Deep linking settings * Update web template * Fix template * Fix web template again * Bump dev_dependencies * Add flutter_bootstrap.js * Use project_name_slug variable * web mobile-web-app-capable * externalNativeBuild * Remove externalNativeBuild * serious_python: 0.8.2 * Added sys.argv support * Pass argv * pwa_background_color and pwa_theme_color options * Fix pwa_background_color in template * Fix pwa_background_color again * Set default pwa_background_color * pwa white background * Use pid for sockets * Move setupDesktop() * Update MainFlutterWindow.swift * Rewrite setupDesktop * Use windowManager.setSkipTaskbar * Hide Linux window * Prevent quit on close * FLET_HIDE_APP_ON_START
This commit is contained in:
parent
287ee5350f
commit
893e7d9fd5
|
|
@ -10,6 +10,7 @@ import 'package:path/path.dart' as path;
|
|||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:serious_python/serious_python.dart';
|
||||
import 'package:url_strategy/url_strategy.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
{% for dep in cookiecutter.flutter.dependencies %}
|
||||
import 'package:{{ dep }}/{{ dep }}.dart' as {{ dep }};
|
||||
|
|
@ -99,6 +100,8 @@ void main(List<String> args) async {
|
|||
debugPrint = (String? message, {int? wrapWidth}) => null;
|
||||
}
|
||||
|
||||
await setupDesktop();
|
||||
|
||||
{% for dep in cookiecutter.flutter.dependencies %}
|
||||
{{ dep }}.ensureInitialized();
|
||||
{% endfor %}
|
||||
|
|
@ -156,8 +159,6 @@ Future prepareApp() async {
|
|||
setPathUrlStrategy();
|
||||
}
|
||||
} else {
|
||||
await setupDesktop();
|
||||
|
||||
// extract app from asset
|
||||
appDir = await extractAssetZip(assetPath, checkHash: true);
|
||||
|
||||
|
|
@ -198,7 +199,7 @@ Future prepareApp() async {
|
|||
environmentVariables["FLET_SERVER_PORT"] = tcpPort.toString();
|
||||
} else {
|
||||
// use UDS on other platforms
|
||||
pageUrl = "flet.sock";
|
||||
pageUrl = "flet_$pid.sock";
|
||||
environmentVariables["FLET_SERVER_UDS_PATH"] = pageUrl;
|
||||
}
|
||||
}
|
||||
|
|
@ -227,7 +228,7 @@ Future<String?> runPythonApp(List<String> args) async {
|
|||
'Python output TCP Server is listening on port ${outSocketServer.port}');
|
||||
socketAddr = "$tcpAddr:${outSocketServer.port}";
|
||||
} else {
|
||||
socketAddr = "stdout.sock";
|
||||
socketAddr = "stdout_$pid.sock";
|
||||
if (await File(socketAddr).exists()) {
|
||||
await File(socketAddr).delete();
|
||||
}
|
||||
|
|
@ -345,4 +346,33 @@ Future<int> getUnusedPort() {
|
|||
socket.close();
|
||||
return port;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool isDesktop() {
|
||||
return !kIsWeb &&
|
||||
(defaultTargetPlatform == TargetPlatform.windows ||
|
||||
defaultTargetPlatform == TargetPlatform.macOS ||
|
||||
defaultTargetPlatform == TargetPlatform.linux);
|
||||
}
|
||||
|
||||
Future setupDesktop() async {
|
||||
if (isDesktop()) {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
Map<String, String> env = Platform.environment;
|
||||
var hideWindowOnStart = env["FLET_HIDE_WINDOW_ON_START"];
|
||||
var hideAppOnStart = env["FLET_HIDE_APP_ON_START"];
|
||||
debugPrint("hideWindowOnStart: $hideWindowOnStart");
|
||||
debugPrint("hideAppOnStart: $hideAppOnStart");
|
||||
|
||||
await windowManager.waitUntilReadyToShow(null, () async {
|
||||
if (hideWindowOnStart == null && hideAppOnStart == null) {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
} else if (hideAppOnStart != null) {
|
||||
await windowManager.setSkipTaskbar(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ static void my_application_activate(GApplication* application) {
|
|||
}
|
||||
|
||||
gtk_window_set_default_size(window, 1280, 720);
|
||||
gtk_widget_show(GTK_WIDGET(window));
|
||||
gtk_widget_realize(GTK_WIDGET(window));
|
||||
|
||||
g_autoptr(FlDartProject) project = fl_dart_project_new();
|
||||
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ import FlutterMacOS
|
|||
@NSApplicationMain
|
||||
class AppDelegate: FlutterAppDelegate {
|
||||
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
return true
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import Cocoa
|
||||
import FlutterMacOS
|
||||
import window_manager
|
||||
|
||||
class MainFlutterWindow: NSWindow {
|
||||
override func awakeFromNib() {
|
||||
|
|
@ -12,4 +13,9 @@ class MainFlutterWindow: NSWindow {
|
|||
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
|
||||
super.order(place, relativeTo: otherWin)
|
||||
hiddenWindowAtLaunch()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ dependencies:
|
|||
dependency_overrides:
|
||||
wakelock_plus: ^1.2.5
|
||||
web: ^1.0.0
|
||||
window_manager: ^0.4.3
|
||||
|
||||
# {% if 'flet_audio_recorder' in cookiecutter.flutter.dependencies %}
|
||||
record: ^5.1.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue