From 369131e50242091de00163d0b1fc16de33336928 Mon Sep 17 00:00:00 2001
From: "Lauren N. Liberda" <lauren@selfisekai.rocks>
Date: Tue, 30 May 2023 03:06:58 +0200
Subject: [PATCH 1/2] fix window/layout on pmos

---
 .../intiface_configuration_cubit.dart         | 19 ++++++++++++++---
 lib/intiface_central_app.dart                 | 21 +++++++++++--------
 lib/util/intiface_util.dart                   |  8 +++++++
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/lib/configuration/intiface_configuration_cubit.dart b/lib/configuration/intiface_configuration_cubit.dart
index 6d761bf..0f23aa4 100644
--- a/lib/configuration/intiface_configuration_cubit.dart
+++ b/lib/configuration/intiface_configuration_cubit.dart
@@ -81,6 +81,11 @@ class WebsocketServerPort extends IntifaceConfigurationState {
   WebsocketServerPort(this.value);
 }
 
+class Pmos extends IntifaceConfigurationState {
+  final bool value;
+  Pmos(this.value);
+}
+
 class UseCompactDisplay extends IntifaceConfigurationState {
   final bool value;
   UseCompactDisplay(this.value);
@@ -139,8 +144,10 @@ class IntifaceConfigurationCubit extends Cubit<IntifaceConfigurationState> {
     // Our initializer runs through all of our known configuration values, either setting them to what they already are,
     // or providing them with default values.
 
-    // Window settings for desktop. Will be ignored on mobile. Default to expanded.
-    useCompactDisplay = _prefs.getBool("useCompactDisplay") ?? false;
+    pmos = await isPostmarket();
+
+    // Window settings for desktop. Will be ignored on mobile. Default to expanded except pmos.
+    useCompactDisplay = _prefs.getBool("useCompactDisplay") ?? pmos;
 
     // Check all of our values to make sure they exist. If not, set defaults, based on platform if needed.
     serverName = _prefs.getString("serverName") ?? "Intiface Server";
@@ -157,7 +164,7 @@ class IntifaceConfigurationCubit extends Cubit<IntifaceConfigurationState> {
     showExtendedUI = _prefs.getBool("showExtendedUI") ?? false;
     allowRawMessages = _prefs.getBool("allowRawMessages") ?? false;
     unreadNews = _prefs.getBool("unreadNews") ?? false;
-    useSideNavigationBar = _prefs.getBool("useSideNavigationBar") ?? isDesktop();
+    useSideNavigationBar = _prefs.getBool("useSideNavigationBar") ?? isDesktop() && !pmos;
     useLightTheme = _prefs.getBool("useLightTheme") ?? true;
 
     // True on all platforms
@@ -206,6 +213,12 @@ class IntifaceConfigurationCubit extends Cubit<IntifaceConfigurationState> {
     emit(CurrentDeviceConfigEtag(value));
   }
 
+  bool get pmos => _prefs.getBool("pmos")!;
+  set pmos(bool value) {
+    _prefs.setBool("pmos", value);
+    emit(Pmos(value));
+  }
+
   // Slam to false until we figure out how to window resizing.
   bool get useCompactDisplay => false; //_prefs.getBool("useCompactDisplay")!;
   set useCompactDisplay(bool value) {
diff --git a/lib/intiface_central_app.dart b/lib/intiface_central_app.dart
index 1fac674..d547773 100644
--- a/lib/intiface_central_app.dart
+++ b/lib/intiface_central_app.dart
@@ -90,20 +90,23 @@ class IntifaceCentralApp extends StatelessWidget with WindowListener {
       );
 
       windowManager.addListener(this);
-      windowManager.setPosition(guiSettingsCubit.getWindowPosition());
-      windowDisplayModeResize(configCubit.useCompactDisplay, guiSettingsCubit);
+      if (!configCubit.pmos) {
+        windowManager.setPosition(guiSettingsCubit.getWindowPosition());
+        windowDisplayModeResize(configCubit.useCompactDisplay, guiSettingsCubit);
+
+        configCubit.stream.listen((event) {
+          if (event is! UseCompactDisplay) {
+            return;
+          }
+          windowDisplayModeResize(event.value, guiSettingsCubit);
+        });
+      }
+
       windowManager.waitUntilReadyToShow(windowOptions, () async {
         await windowManager.show();
         await windowManager.focus();
       });
 
-      configCubit.stream.listen((event) {
-        if (event is! UseCompactDisplay) {
-          return;
-        }
-        windowDisplayModeResize(event.value, guiSettingsCubit);
-      });
-
       // Only add app update checks on desktop, mobile apps will use stores.
       updateRepo.addProvider(IntifaceCentralDesktopUpdater(configCubit.currentAppVersion));
     } else {
diff --git a/lib/util/intiface_util.dart b/lib/util/intiface_util.dart
index 2f2ccb6..fb3031e 100644
--- a/lib/util/intiface_util.dart
+++ b/lib/util/intiface_util.dart
@@ -1,3 +1,4 @@
+import 'package:device_info_plus/device_info_plus.dart';
 import 'package:path_provider/path_provider.dart';
 import 'package:path/path.dart' as p;
 import 'dart:io';
@@ -81,3 +82,10 @@ class IntifacePaths {
 
 bool isDesktop() => Platform.isLinux || Platform.isMacOS || Platform.isWindows;
 bool isMobile() => Platform.isAndroid || Platform.isIOS;
+Future<bool> isPostmarket() async {
+  if (!Platform.isLinux) return false;
+
+  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
+  LinuxDeviceInfo linuxInfo = await deviceInfo.linuxInfo;
+  return linuxInfo.id == "postmarketos";
+}
-- 
2.40.1

