π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][auth] review fixes: launch-time menubar mode snapshot, 2d display hit test
Ivn Nv45fdf75972aa
diff --git a/mobile/apps/auth/lib/services/window_listener_service.dart b/mobile/apps/auth/lib/services/window_listener_service.dartindex 07b819d006..7b5633922e 100644--- a/mobile/apps/auth/lib/services/window_listener_service.dart+++ b/mobile/apps/auth/lib/services/window_listener_service.dart@@ -21,6 +21,7 @@ class WindowListenerService with WindowListener, TrayListener {bool _isListening = false;bool _isQuitting = false;bool _isOneOffWindowed = false;+ bool _launchMenubarMode = false;bool get isOneOffWindowed => _isOneOffWindowed;@@ -31,6 +32,12 @@ class WindowListenerService with WindowListener, TrayListener {Future<void> init() async {_preferences = await SharedPreferences.getInstance();+ // Snapshot at launch: toggling the setting mid-session persists the pref+ // but must not reroute window behavior until restart, since the+ // startup-only window setup (title bar, size, activation policy) only+ // runs for the mode active at launch.+ _launchMenubarMode = Platform.isMacOS &&+ (_preferences.getBool(PreferenceService.kMenubarMode) ?? false);if (_isListening) return;windowManager.addListener(this);trayManager.addListener(this);@@ -38,8 +45,7 @@ class WindowListenerService with WindowListener, TrayListener {}bool isMenubarMode() {- return Platform.isMacOS &&- (_preferences.getBool(PreferenceService.kMenubarMode) ?? false);+ return _launchMenubarMode;}Size getWindowSize() {@@ -120,22 +126,22 @@ class WindowListenerService with WindowListener, TrayListener {const h = menubarPopoverHeight;// The status item is mirrored on every display's menubar, but// trayManager.getBounds() reports a single static instance, so the click- // display has to come from the cursor. Only the horizontal coordinate is- // used: it needs no coordinate-space conversion, and vertically a menubar- // popover always sits just below the top of its display.+ // display has to come from the cursor position.Offset? cursor;+ List<Display> displays = const [];try {- cursor = await screenRetriever.getCursorScreenPoint();+ displays = await screenRetriever.getAllDisplays();+ final raw = await screenRetriever.getCursorScreenPoint();+ cursor = Offset(raw.dx, raw.dy + _cursorYCorrection(displays));} catch (_) {}final tray = await trayManager.getBounds();- final anchorX = cursor?.dx ?? tray?.center.dx;- if (anchorX != null) {- final displayBounds = await _boundsOfDisplayAtX(anchorX);+ final anchor = cursor ?? tray?.center;+ if (anchor != null) {+ final displayBounds = _nearestDisplayBounds(anchor, displays);final trayOnSameDisplay = tray != null &&displayBounds != null &&- tray.center.dx >= displayBounds.left &&- tray.center.dx < displayBounds.right;- double x = (trayOnSameDisplay ? tray.center.dx : anchorX) - w / 2;+ _nearestDisplayBounds(tray.center, displays) == displayBounds;+ double x = (trayOnSameDisplay ? tray.center.dx : anchor.dx) - w / 2;final double y =trayOnSameDisplay ? tray.bottom + 4 : (displayBounds?.top ?? 0) + 4;if (displayBounds != null) {@@ -149,23 +155,48 @@ class WindowListenerService with WindowListener, TrayListener {await windowManager.show();}- Future<Rect?> _boundsOfDisplayAtX(double x) async {- try {- final displays = await screenRetriever.getAllDisplays();- Rect? fallback;- for (final display in displays) {- final position = display.visiblePosition;- final size = display.visibleSize ?? display.size;- if (position == null) continue;- final bounds =- Rect.fromLTWH(position.dx, position.dy, size.width, size.height);- fallback ??= bounds;- if (x >= bounds.left && x < bounds.right) return bounds;+ // screen_retriever's macOS getCursorScreenPoint flips y against the lowest+ // display top instead of the primary display top, a constant offset equal+ // to the lowest top's y in top-left coordinates. Reconstruct it from the+ // display list (frame top = visible top minus the menu bar strip).+ double _cursorYCorrection(List<Display> displays) {+ double lowestFrameTop = 0;+ for (final display in displays) {+ final visibleTop = display.visiblePosition?.dy;+ final visibleHeight = display.visibleSize?.height;+ if (visibleTop == null || visibleHeight == null) continue;+ final frameTop = visibleTop - (display.size.height - visibleHeight);+ if (frameTop > lowestFrameTop) lowestFrameTop = frameTop;+ }+ return lowestFrameTop;+ }++ // Nearest display by distance to its visible bounds, in both axes. The+ // visible rect excludes the menu bar and Dock strips, so a menubar click+ // is slightly outside every rect; nearest-rect matching absorbs that+ // without needing the exact strip sizes.+ Rect? _nearestDisplayBounds(Offset point, List<Display> displays) {+ Rect? best;+ double bestDistance = double.infinity;+ for (final display in displays) {+ final position = display.visiblePosition;+ final size = display.visibleSize ?? display.size;+ if (position == null) continue;+ final bounds =+ Rect.fromLTWH(position.dx, position.dy, size.width, size.height);+ final dx = point.dx < bounds.left+ ? bounds.left - point.dx+ : (point.dx > bounds.right ? point.dx - bounds.right : 0.0);+ final dy = point.dy < bounds.top+ ? bounds.top - point.dy+ : (point.dy > bounds.bottom ? point.dy - bounds.bottom : 0.0);+ final distance = dx * dx + dy * dy;+ if (distance < bestDistance) {+ bestDistance = distance;+ best = bounds;}- return fallback;- } catch (_) {- return null;}+ return best;}@override