Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

refactor(desktop): rebase onto main, drop setScreenByName, and support latest upstream APIs

saivinay1805749b7fd64a2d
diff --git a/desktop/app/cpp/app_helpers.cpp b/desktop/app/cpp/app_helpers.cpp
index 0611bd7..619415c 100644
--- a/desktop/app/cpp/app_helpers.cpp
+++ b/desktop/app/cpp/app_helpers.cpp
@@ -3,13 +3,16 @@
#include "video_view.h"
#include <QtCore/QCoreApplication>
+#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QLibraryInfo>
#include <QtCore/QLocale>
#include <QtCore/QMimeData>
#include <QtCore/QPointer>
+#include <QtCore/QStorageInfo>
#include <QtCore/QStringList>
+#include <QtCore/QTimeZone>
#include <QtCore/QTranslator>
#include <QtCore/QUrl>
#include <QtCore/QtEnvironmentVariables>
@@ -506,3 +509,32 @@ bool mac_clipboard_write_text(rust::Str /*text*/, bool /*is_private*/)
return false;
}
#endif
+
+int64_t mac_local_offset_ms(int64_t at_ms)
+{
+ const QDateTime dt = QDateTime::fromMSecsSinceEpoch(at_ms, QTimeZone::systemTimeZone());
+ return static_cast<int64_t>(dt.offsetFromUtc()) * 1000;
+}
+
+uint64_t mac_free_space(rust::Str path, bool &ok)
+{
+ ok = false;
+ const std::string pathStr(path.data(), path.size());
+ QString qpath = QString::fromStdString(pathStr);
+ QFileInfo info(qpath);
+ while (!info.exists() && !qpath.isEmpty()) {
+ const QString parent = info.dir().absolutePath();
+ if (parent == qpath)
+ break;
+ qpath = parent;
+ info.setFile(qpath);
+ }
+ const QStorageInfo storage(qpath);
+ if (!storage.isValid() || !storage.isReady())
+ return 0;
+ const qint64 available = storage.bytesAvailable();
+ if (available < 0)
+ return 0;
+ ok = true;
+ return static_cast<uint64_t>(available);
+}
diff --git a/desktop/app/cpp/app_helpers.h b/desktop/app/cpp/app_helpers.h
index 478ea83..27da9f6 100644
--- a/desktop/app/cpp/app_helpers.h
+++ b/desktop/app/cpp/app_helpers.h
@@ -59,3 +59,6 @@ rust::Vec<uint8_t> decode_image(rust::Slice<const uint8_t> bytes);
int64_t mac_clipboard_change_count();
rust::String mac_clipboard_read_text(bool &is_private);
bool mac_clipboard_write_text(rust::Str text, bool is_private);
+
+int64_t mac_local_offset_ms(int64_t at_ms);
+uint64_t mac_free_space(rust::Str path, bool &ok);
diff --git a/desktop/app/cpp/native_window.cpp b/desktop/app/cpp/native_window.cpp
index 3c6ac40..1731550 100644
--- a/desktop/app/cpp/native_window.cpp
+++ b/desktop/app/cpp/native_window.cpp
@@ -355,15 +355,3 @@ bool NativeWindow::nativeEvent(const QByteArray &eventType, void *message, qintp
#endif
return QQuickWindow::nativeEvent(eventType, message, result);
}
-
-void NativeWindow::setScreenByName(const QString &screenName)
-{
- if (screenName.isEmpty())
- return;
- for (QScreen *s : QGuiApplication::screens()) {
- if (s->name() == screenName) {
- setScreen(s);
- break;
- }
- }
-}
diff --git a/desktop/app/cpp/native_window.h b/desktop/app/cpp/native_window.h
index c75e3e2..fc253b3 100644
--- a/desktop/app/cpp/native_window.h
+++ b/desktop/app/cpp/native_window.h
@@ -2,7 +2,6 @@
#pragma once
#include <QtCore/QPointer>
-#include <QtGui/QScreen>
#include <QtQml/qqmlregistration.h>
#include <QtQuick/QQuickItem>
#include <QtQuick/QQuickWindow>
@@ -56,8 +55,6 @@ public:
Q_INVOKABLE void addCaptionHole(QQuickItem *item);
Q_INVOKABLE void removeCaptionHole(QQuickItem *item);
- // Selects and sets the native QScreen matching screenName.
- Q_INVOKABLE void setScreenByName(const QString &screenName);
Q_INVOKABLE void toggleMaximized();
// Shows, restores and focuses the window, even when another app is in
// front (the caller must have the right to take the foreground).
diff --git a/desktop/app/src/bridge/native.rs b/desktop/app/src/bridge/native.rs
index 04af534..7903c20 100644
--- a/desktop/app/src/bridge/native.rs
+++ b/desktop/app/src/bridge/native.rs
@@ -63,5 +63,11 @@ pub mod ffi {
#[allow(dead_code)]
fn mac_clipboard_write_text(text: &str, is_private: bool) -> bool;
+
+ #[allow(dead_code)]
+ fn mac_local_offset_ms(at_ms: i64) -> i64;
+
+ #[allow(dead_code)]
+ fn mac_free_space(path: &str, ok: &mut bool) -> u64;
}
}
diff --git a/desktop/app/src/mac/mod.rs b/desktop/app/src/mac/mod.rs
index 1c135c4..eb9816c 100644
--- a/desktop/app/src/mac/mod.rs
+++ b/desktop/app/src/mac/mod.rs
@@ -30,6 +30,7 @@ pub mod tray;
pub mod vcam;
pub mod wallpaper;
pub mod widget;
+pub mod wifi;
pub mod window_capture;
pub mod wol;
@@ -109,6 +110,19 @@ pub fn work_area() -> Option<(i32, i32, i32, i32)> {
None
}
+/// How far this PC's time zone is from UTC at `at_ms` (Unix milliseconds).
+pub fn local_offset_ms(at_ms: i64) -> i64 {
+ crate::bridge::native::ffi::mac_local_offset_ms(at_ms)
+}
+
+/// Free bytes on the drive holding `path`.
+pub fn free_space(path: &std::path::Path) -> Option<u64> {
+ let s = path.to_str()?;
+ let mut ok = false;
+ let bytes = crate::bridge::native::ffi::mac_free_space(s, &mut ok);
+ ok.then_some(bytes)
+}
+
/// Fills `buf` from cryptographic randomness.
pub fn secure_random(buf: &mut [u8]) -> bool {
use std::io::Read;
@@ -125,3 +139,14 @@ pub fn with_com<T>(f: impl FnOnce() -> T) -> T {
pub(crate) fn reg_string(_root: u32, _key: &str, _value: &str) -> Option<String> {
None
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn free_space_returns_some_on_system_drive() {
+ let space = free_space(std::path::Path::new("/"));
+ assert!(space.is_some());
+ }
+}
diff --git a/desktop/app/src/mac/shell.rs b/desktop/app/src/mac/shell.rs
index 99348e6..5d0171f 100644
--- a/desktop/app/src/mac/shell.rs
+++ b/desktop/app/src/mac/shell.rs
@@ -44,7 +44,8 @@ pub fn run(program: &Path, arguments: &str) -> Result<(), String> {
/// Locks the Mac screen.
pub fn lock() -> Result<(), String> {
- // CGSession -suspend locks the screen directly without accessibility prompts.
+ // Legacy macOS (< Big Sur): CGSession -suspend locked the screen directly.
+ // Modern macOS (11+) removed CGSession, so it falls back to osascript.
let status = std::process::Command::new(
"/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession",
)
diff --git a/desktop/app/src/mac/wifi.rs b/desktop/app/src/mac/wifi.rs
new file mode 100644
index 0000000..2ee8991
--- /dev/null
+++ b/desktop/app/src/mac/wifi.rs
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+//! Wi-Fi stubs on macOS.
+
+/// Whether a Wi-Fi network is in range.
+#[allow(dead_code)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Reach {
+ NotInRange,
+ InRange,
+ Connected,
+}
+
+/// Saved Wi-Fi networks known to the OS.
+pub fn saved_networks() -> Vec<String> {
+ Vec::new()
+}
+
+/// Requests a background Wi-Fi scan.
+pub fn scan() {}
+
+/// Checks whether `profile` is in range or connected.
+pub fn reach(_profile: &str) -> Reach {
+ Reach::NotInRange
+}
+
+/// Connects to a saved Wi-Fi profile.
+pub fn connect(_profile: &str) -> Result<(), String> {
+ Err("Wi-Fi network connection is not supported on macOS".into())
+}