Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
feat(desktop): choose any folders to sync
Bee05144169e8da
diff --git a/desktop/app/qml/pages/SettingsPage.qml b/desktop/app/qml/pages/SettingsPage.qmlindex 4eb596f..1ade667 100644--- a/desktop/app/qml/pages/SettingsPage.qml+++ b/desktop/app/qml/pages/SettingsPage.qml@@ -257,6 +257,13 @@ Item {onAccepted: PhotoBackup.chooseFolder(deviceId, selectedFolder.toString())}+ FolderDialog {+ id: folderSyncPcPicker+ title: qsTr("Sync into")+ // file:///C:/x becomes C:/x on Windows, file:///home/x /home/x on Linux.+ onAccepted: folderSyncSheet.pcFolder = decodeURIComponent(selectedFolder.toString().replace(/^file:\/\/(\/(?=[A-Za-z]:))?/, ""))+ }+FolderDialog {id: recordingsFolderPickertitle: qsTr("Save recordings in")@@ -2316,13 +2323,13 @@ Item {variant: "tonal"size: "sm"iconPath: Icons.plus- text: qsTr("Add DCIM → Pictures")+ text: qsTr("Add folder")// For the phone selected in the app: a rule needs one.readonly property string phoneId: DeviceList.count > 0? DeviceList.deviceIdAt(Math.min(Math.max(0, AppController.currentDevice), DeviceList.count - 1)) || "": ""enabled: phoneId.length > 0- onClicked: Preferences.addFolderSyncRule(phoneId, "DCIM/Camera", Preferences.recordingsFolder.replace(/[\\\/][^\\\/]+[\\\/]?$/, "") + "/Pictures/Phone Camera", false)+ onClicked: folderSyncSheet.openFor(phoneId)}}}@@ -3408,6 +3415,141 @@ Item {Behavior on opacity { NumberAnimation { duration: Theme.fadeFast } }}+ // Synced folders: which phone folder, where on this PC, and which way.+ Sheet {+ id: folderSyncSheet+ property string phoneId+ property string phoneFolder+ property string pcFolder+ property bool twoWay: false+ // The PC folder follows the phone folder until the user picks one.+ property bool pcChosen: false+ readonly property var common: ["DCIM/Camera", "Pictures/Screenshots", "Download", "Documents", "Music", "Movies", "Recordings"]+ readonly property string tidyPhoneFolder: phoneFolder.split(/[\/\\]/).map(p => p.trim()).filter(p => p.length > 0 && p !== ".").join("/")+ readonly property bool phoneFolderOk: tidyPhoneFolder.length > 0 && tidyPhoneFolder.split("/").indexOf("..") < 0+ cardWidth: 480++ function openFor(id) {+ phoneId = id+ twoWay = false+ pcChosen = false+ choosePhoneFolder("DCIM/Camera")+ open()+ }+ function choosePhoneFolder(folder) {+ phoneFolder = folder+ if (phoneFolderInput.text !== folder)+ phoneFolderInput.text = folder+ if (!pcChosen)+ pcFolder = Preferences.suggestedSyncFolder(folder)+ }++ Column {+ width: parent.width+ spacing: 12+ Txt { width: parent.width; text: qsTr("Sync a folder"); role: "headline"; wrapMode: Text.WordWrap }+ Txt {+ width: parent.width+ wrapMode: Text.WordWrap+ role: "body"+ muted: true+ text: qsTr("The phone needs to let NectarLink read this folder: All files access, or this folder under Selected folders, in NectarLink's settings on the phone.")+ }++ Txt { text: qsTr("Folder on the phone"); role: "label" }+ Flow {+ width: parent.width+ spacing: 6+ Repeater {+ model: folderSyncSheet.common+ delegate: Chip {+ required property string modelData+ text: modelData+ interactive: true+ selected: folderSyncSheet.tidyPhoneFolder === modelData+ onClicked: folderSyncSheet.choosePhoneFolder(modelData)+ }+ }+ }+ Rectangle {+ width: parent.width+ height: 40+ radius: Theme.radiusMd+ color: Theme.surfaceContainerHighest+ border.width: phoneFolderInput.activeFocus ? 2 : 1+ border.color: phoneFolderInput.activeFocus ? Theme.primary : Theme.outlineVariant+ TextInput {+ id: phoneFolderInput+ anchors.fill: parent+ anchors.margins: 10+ color: Theme.surfaceContent+ font.pixelSize: 14+ selectByMouse: true+ clip: true+ Accessible.role: Accessible.EditableText+ Accessible.name: qsTr("Folder on the phone")+ onTextEdited: folderSyncSheet.choosePhoneFolder(text)+ }+ }++ Txt { text: qsTr("Folder on this PC"); role: "label" }+ Row {+ width: parent.width+ spacing: 8+ Txt {+ width: parent.width - choosePcFolder.width - 8+ anchors.verticalCenter: parent.verticalCenter+ text: folderSyncSheet.pcFolder+ elide: Text.ElideMiddle+ role: "body"+ }+ Button {+ id: choosePcFolder+ variant: "text"+ size: "sm"+ text: qsTr("Choose…")+ onClicked: {+ folderSyncSheet.pcChosen = true+ folderSyncPcPicker.open()+ }+ }+ }++ Segmented {+ options: [+ { value: "one", label: qsTr("Phone to PC") },+ { value: "two", label: qsTr("Both ways") }+ ]+ value: folderSyncSheet.twoWay ? "two" : "one"+ onPicked: (v) => folderSyncSheet.twoWay = v === "two"+ }+ Txt {+ width: parent.width+ wrapMode: Text.WordWrap+ role: "body"+ muted: true+ text: folderSyncSheet.twoWay+ ? qsTr("Changes on either side are copied to the other. When a file changed on both, both versions are kept.")+ : qsTr("New and changed files on the phone are copied to the PC. Nothing on the PC goes to the phone.")+ }++ Row {+ anchors.right: parent.right+ spacing: 10+ Button { variant: "text"; text: qsTr("Cancel"); onClicked: folderSyncSheet.close() }+ Button {+ text: qsTr("Add")+ enabled: folderSyncSheet.phoneFolderOk && folderSyncSheet.pcFolder.length > 0+ onClicked: {+ Preferences.addFolderSyncRule(folderSyncSheet.phoneId, folderSyncSheet.tidyPhoneFolder,+ folderSyncSheet.pcFolder, folderSyncSheet.twoWay)+ folderSyncSheet.close()+ }+ }+ }+ }+ }+Sheet {id: hotspotSheetproperty string deviceIddiff --git a/desktop/app/src/bridge/prefs.rs b/desktop/app/src/bridge/prefs.rsindex aaecb4a..ee8a926 100644--- a/desktop/app/src/bridge/prefs.rs+++ b/desktop/app/src/bridge/prefs.rs@@ -200,6 +200,11 @@ pub mod qobject {pc_folder: &QString,two_way: bool,);+ /// Where a phone folder could go on this PC (the user's Pictures,+ /// Music, Videos or Documents), for the Add folder sheet.+ #[qinvokable]+ #[cxx_name = "suggestedSyncFolder"]+ fn suggested_sync_folder(self: &Preferences, phone_folder: &QString) -> QString;/// Removes a folder sync rule by ID.#[qinvokable]fn remove_folder_sync_rule(self: Pin<&mut Preferences>, rule_id: &QString);@@ -904,7 +909,9 @@ impl qobject::Preferences {.filter(|s| !s.is_empty()).unwrap_or_else(|| String::from(pc_folder));let pc_trimmed = raw_pc.trim();- let phone_trimmed = String::from(phone_folder).trim().to_owned();+ let Some(phone_trimmed) = crate::folder_sync::phone_folder_path(&String::from(phone_folder)) else {+ return;+ };let phone_id = String::from(device_id).trim().to_owned();if pc_trimmed.is_empty() || phone_trimmed.is_empty() || phone_id.is_empty() {return;@@ -932,6 +939,11 @@ impl qobject::Preferences {self.save();}+ pub fn suggested_sync_folder(&self, phone_folder: &QString) -> QString {+ let path = crate::folder_sync::suggested_pc_folder(&String::from(phone_folder));+ QString::from(&path.map(|p| p.to_string_lossy().into_owned()).unwrap_or_default())+ }+pub fn remove_folder_sync_rule(mut self: Pin<&mut Self>, rule_id: &QString) {let id = String::from(rule_id);let mut rules = crate::settings::folder_sync_rules();diff --git a/desktop/app/src/folder_sync.rs b/desktop/app/src/folder_sync.rsindex 2a68409..ffc728a 100644--- a/desktop/app/src/folder_sync.rs+++ b/desktop/app/src/folder_sync.rs@@ -52,6 +52,34 @@ type RuleBaselineMap = HashMap<String, HashMap<String, (u64, i64)>>;static LAST_SYNCED: OnceLock<Mutex<RuleBaselineMap>> = OnceLock::new();+/// A phone folder as typed or picked (`DCIM/Camera`, `/Download/`,+/// `Documents\Notes`), relative to the phone's storage and tidied; `None`+/// for an empty path or one that climbs out with `..`.+pub fn phone_folder_path(raw: &str) -> Option<String> {+ let parts: Vec<&str> =+ raw.split(['/', '\\']).map(str::trim).filter(|p| !p.is_empty() && *p != ".").collect();+ (!parts.is_empty() && !parts.contains(&"..")).then(|| parts.join("/"))+}++/// Where `phone_folder` could go on this PC: photos and screenshots in+/// Pictures, music in Music, videos in Videos, anything else in Documents,+/// each in a "Phone <name>" folder.+pub fn suggested_pc_folder(phone_folder: &str) -> Option<PathBuf> {+ let path = phone_folder_path(phone_folder)?;+ let lower = path.to_ascii_lowercase();+ let name = path.rsplit('/').next().unwrap_or(&path);+ let base = if lower.starts_with("dcim") || lower.starts_with("pictures") {+ dirs::picture_dir()+ } else if lower.starts_with("music") {+ dirs::audio_dir()+ } else if lower.starts_with("movies") {+ dirs::video_dir()+ } else {+ dirs::document_dir()+ }?;+ Some(base.join(format!("Phone {name}")))+}+/// Drops what a removed rule last synced.pub fn forget_rule(rule_id: &str) {baselines().lock().unwrap_or_else(|e| e.into_inner()).remove(rule_id);@@ -716,4 +744,29 @@ mod tests {assert!(!bad_dest.exists());assert!(!temp_part_path(&bad_dest).unwrap().exists());}++ #[test]+ fn phone_folders_are_tidied_and_kept_inside_storage() {+ assert_eq!(phone_folder_path("DCIM/Camera").as_deref(), Some("DCIM/Camera"));+ assert_eq!(phone_folder_path(" /Download/ ").as_deref(), Some("Download"));+ assert_eq!(phone_folder_path(r"Documents\Notes\.").as_deref(), Some("Documents/Notes"));+ assert_eq!(+ phone_folder_path("WhatsApp/Media/ WhatsApp Images ").as_deref(),+ Some("WhatsApp/Media/WhatsApp Images")+ );+ assert_eq!(phone_folder_path(""), None);+ assert_eq!(phone_folder_path(" / "), None);+ assert_eq!(phone_folder_path("Download/../../data"), None);+ }++ #[test]+ fn suggested_folders_follow_the_kind_of_folder() {+ let Some(pictures) = dirs::picture_dir() else { return };+ assert_eq!(suggested_pc_folder("DCIM/Camera"), Some(pictures.join("Phone Camera")));+ assert_eq!(suggested_pc_folder("Pictures/Screenshots"), Some(pictures.join("Phone Screenshots")));+ if let Some(documents) = dirs::document_dir() {+ assert_eq!(suggested_pc_folder("Download"), Some(documents.join("Phone Download")));+ }+ assert_eq!(suggested_pc_folder(".."), None);+ }}diff --git a/docs/guide/files-and-transfers.md b/docs/guide/files-and-transfers.mdindex f02363f..d08c38a 100644--- a/docs/guide/files-and-transfers.md+++ b/docs/guide/files-and-transfers.md@@ -86,7 +86,7 @@ You can browse your phone's internal storage or selected folders directly insideTo keep a phone folder (such as `DCIM/Camera` or a notes directory) synchronized with a folder on your PC:1. On your PC, open **Settings › Files & Sync** and scroll to the **Synced folders** card.-2. Click **Add DCIM to Pictures** (or configure a custom phone folder and PC folder pair) and choose between:+2. Click **Add folder**, pick the folder on the phone (DCIM/Camera, Screenshots, Download and others are one tap away, or type any path such as `WhatsApp/Media`), choose where it goes on the PC, and choose between:- **One-way (phone to PC)**: Mirrors new and updated files from the phone folder (and subfolders up to 3 levels deep) into the PC folder without pushing PC changes back to the phone.- **Two-way sync**: Synchronizes additions and updates in both directions. If the same file is modified on both devices between syncs, NectarLink preserves both versions by saving a conflict copy rather than overwriting your work.3. Every synced file streams to a temporary `.nectarlink.part` file and verifies its byte length and **BLAKE3** hash before replacing the destination file. Click **Sync now** to run all enabled rules immediately, or toggle individual rules on and off.