Skip to content

An open-source cross-platform alternative to AirDrop

Disable position persistence on Wayland (#546)

Gabriel Limaa73f5d1f92c5
diff --git a/lib/pages/tabs/settings_tab.dart b/lib/pages/tabs/settings_tab.dart
index 6b6e5b03..43e741b5 100644
--- a/lib/pages/tabs/settings_tab.dart
+++ b/lib/pages/tabs/settings_tab.dart
@@ -121,13 +121,15 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
),
),
if (checkPlatformIsDesktop()) ...[
- _BooleanEntry(
- label: t.settingsTab.general.saveWindowPlacement,
- value: settings.saveWindowPlacement,
- onChanged: (b) async {
- await ref.read(settingsProvider.notifier).setSaveWindowPlacement(b);
- },
- ),
+ /// Wayland does window position handling, so there's no need for it. See [https://github.com/localsend/localsend/issues/544]
+ if (checkPlatformIsNotWaylandDesktop())
+ _BooleanEntry(
+ label: t.settingsTab.general.saveWindowPlacement,
+ value: settings.saveWindowPlacement,
+ onChanged: (b) async {
+ await ref.read(settingsProvider.notifier).setSaveWindowPlacement(b);
+ },
+ ),
if (checkPlatformHasTray()) ...[
_BooleanEntry(
label: t.settingsTab.general.minimizeToTray,
diff --git a/lib/provider/persistence_provider.dart b/lib/provider/persistence_provider.dart
index db6437b8..107d28c0 100644
--- a/lib/provider/persistence_provider.dart
+++ b/lib/provider/persistence_provider.dart
@@ -294,6 +294,7 @@ class PersistenceService {
}
bool getSaveWindowPlacement() {
+ if (!checkPlatformIsNotWaylandDesktop()) return false;
return _prefs.getBool(_saveWindowPlacement) ?? true;
}
}
diff --git a/lib/util/native/platform_check.dart b/lib/util/native/platform_check.dart
index d26655e6..86e84d29 100644
--- a/lib/util/native/platform_check.dart
+++ b/lib/util/native/platform_check.dart
@@ -1,3 +1,4 @@
+import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
bool checkPlatform(List<TargetPlatform> platforms, {bool web = false}) {
@@ -41,3 +42,15 @@ bool checkPlatformWithGallery() {
bool checkPlatformWithFileSystem() {
return checkPlatform([TargetPlatform.linux, TargetPlatform.windows, TargetPlatform.android, TargetPlatform.macOS]);
}
+
+/// Convenience function to check if the app is not running on a Linux device with the Wayland display manager
+bool checkPlatformIsNotWaylandDesktop() {
+ if (checkPlatform([TargetPlatform.linux])) {
+ if (Platform.environment['XDG_SESSION_TYPE'] == 'wayland') {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ return true;
+}