feat(linux): add sandboxed Flatpak packaging

This commit is contained in:
Yuri Karamian committed 2026-11-10 15:14:32 +04:00
1 parent b9074ec550
commit ceb3a7d647
9 files changed
+11676 -13

No files matched your search

+28 -13
View File
@@ -11,6 +11,7 @@ use crate::types::FileEvent;
use crate::vault::operations::{is_hidden, read_note_entry_fast};
const IOS_POLL_INTERVAL: Duration = Duration::from_secs(10);
const FLATPAK_POLL_INTERVAL: Duration = Duration::from_secs(2);
const NATIVE_POLL_INTERVAL: Duration = Duration::from_secs(1);
const EVENT_BATCH_INTERVAL: Duration = Duration::from_millis(50);
@@ -20,18 +21,21 @@ enum WatcherBackend {
Poll,
}
const fn watcher_backend_for_target(is_ios: bool) -> WatcherBackend {
if is_ios {
const fn watcher_backend_for_target(is_ios: bool, is_flatpak: bool) -> WatcherBackend {
if is_ios || is_flatpak {
WatcherBackend::Poll
} else {
WatcherBackend::Recommended
}
}
const fn poll_interval_for_backend(backend: WatcherBackend) -> Duration {
match backend {
WatcherBackend::Recommended => NATIVE_POLL_INTERVAL,
WatcherBackend::Poll => IOS_POLL_INTERVAL,
const fn poll_interval_for_target(is_ios: bool, is_flatpak: bool) -> Duration {
if is_ios {
IOS_POLL_INTERVAL
} else if is_flatpak {
FLATPAK_POLL_INTERVAL
} else {
NATIVE_POLL_INTERVAL
}
}
@@ -115,8 +119,12 @@ pub(crate) fn changed_entry(path: PathBuf, event_type: &str, vault_root: &Path)
pub fn start_watcher(app: AppHandle, vault_path: String) -> Result<VaultWatcher, String> {
let (tx, rx) = mpsc::channel();
let backend = watcher_backend_for_target(cfg!(target_os = "ios"));
let config = Config::default().with_poll_interval(poll_interval_for_backend(backend));
let is_ios = cfg!(target_os = "ios");
// Document-portal FUSE paths expose external changes without forwarding
// inotify events. Poll only in Flatpak, keeping native file watchers intact.
let is_flatpak = option_env!("HELIXNOTES_INSTALL_TYPE") == Some("flatpak");
let backend = watcher_backend_for_target(is_ios, is_flatpak);
let config = Config::default().with_poll_interval(poll_interval_for_target(is_ios, is_flatpak));
let mut watcher = match backend {
WatcherBackend::Recommended => VaultWatcher::Recommended(
RecommendedWatcher::new(tx, config).map_err(|e| e.to_string())?,
@@ -222,25 +230,32 @@ mod tests {
#[test]
fn ios_uses_polling_backend() {
assert_eq!(watcher_backend_for_target(true), WatcherBackend::Poll);
assert_eq!(
watcher_backend_for_target(true, false),
WatcherBackend::Poll
);
}
#[test]
fn other_platforms_keep_recommended_backend() {
assert_eq!(
watcher_backend_for_target(false),
watcher_backend_for_target(false, false),
WatcherBackend::Recommended
);
}
#[test]
fn watcher_backends_use_the_expected_intervals() {
fn watcher_targets_use_the_expected_intervals() {
assert_eq!(
poll_interval_for_backend(WatcherBackend::Poll),
poll_interval_for_target(true, false),
Duration::from_secs(10)
);
assert_eq!(
poll_interval_for_backend(WatcherBackend::Recommended),
poll_interval_for_target(false, true),
Duration::from_secs(2)
);
assert_eq!(
poll_interval_for_target(false, false),
Duration::from_secs(1)
);
}