diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 41e654e..b2507a3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -704,6 +704,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ "bitflags 2.10.0", + "block2", + "libc", "objc2", ] @@ -905,6 +907,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-dialog", "tauri-plugin-fs", "tauri-plugin-opener", "tauri-plugin-os", @@ -2967,6 +2970,30 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rfd" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15ad77d9e70a92437d8f74c35d99b4e4691128df018833e99f90bcd36152672" +dependencies = [ + "block2", + "dispatch2", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "log", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.60.2", +] + [[package]] name = "rustc_version" version = "0.4.1" @@ -3680,6 +3707,24 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-dialog" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9204b425d9be8d12aa60c2a83a289cf7d1caae40f57f336ed1155b3a5c0e359b" +dependencies = [ + "log", + "raw-window-handle", + "rfd", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "tauri-plugin-fs", + "thiserror 2.0.17", + "url", +] + [[package]] name = "tauri-plugin-fs" version = "2.4.5" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3a5aaa1..6724c76 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -24,4 +24,5 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" tauri-plugin-fs = "2.4.5" tauri-plugin-os = "2" +tauri-plugin-dialog = "2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index ef20adc..c78b417 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -24,6 +24,16 @@ } ] }, - "os:default" + "os:default", + "opener:default", + { + "identifier": "opener:allow-open-path", + "allow": [ + { + "path": "/**" + } + ] + }, + "dialog:default" ] -} \ No newline at end of file +} diff --git a/src-tauri/package-lock.json b/src-tauri/package-lock.json index 71bdda8..1513cbd 100644 --- a/src-tauri/package-lock.json +++ b/src-tauri/package-lock.json @@ -5,6 +5,8 @@ "packages": { "": { "dependencies": { + "@tauri-apps/plugin-dialog": "^2.6.0", + "@tauri-apps/plugin-opener": "^2.5.3", "@tauri-apps/plugin-os": "^2.3.2" } }, @@ -18,6 +20,24 @@ "url": "https://opencollective.com/tauri" } }, + "node_modules/@tauri-apps/plugin-dialog": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.6.0.tgz", + "integrity": "sha512-q4Uq3eY87TdcYzXACiYSPhmpBA76shgmQswGkSVio4C82Sz2W4iehe9TnKYwbq7weHiL88Yw19XZm7v28+Micg==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.8.0" + } + }, + "node_modules/@tauri-apps/plugin-opener": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.3.tgz", + "integrity": "sha512-CCcUltXMOfUEArbf3db3kCE7Ggy1ExBEBl51Ko2ODJ6GDYHRp1nSNlQm5uNCFY5k7/ufaK5Ib3Du/Zir19IYQQ==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.8.0" + } + }, "node_modules/@tauri-apps/plugin-os": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-os/-/plugin-os-2.3.2.tgz", diff --git a/src-tauri/package.json b/src-tauri/package.json index 5a839e0..4d91c55 100644 --- a/src-tauri/package.json +++ b/src-tauri/package.json @@ -1,5 +1,7 @@ { "dependencies": { + "@tauri-apps/plugin-dialog": "^2.6.0", + "@tauri-apps/plugin-opener": "^2.5.3", "@tauri-apps/plugin-os": "^2.3.2" } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d9f9600..3361654 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -12,6 +12,8 @@ fn rename(invoke_message: String) { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .plugin(tauri_plugin_opener::init()) + .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_os::init()) .invoke_handler(tauri::generate_handler![rename]) .plugin(tauri_plugin_fs::init()) diff --git a/src/wrapper.js b/src/wrapper.js index 29ccf68..a9f8d21 100644 --- a/src/wrapper.js +++ b/src/wrapper.js @@ -3,7 +3,8 @@ const path = window.__TAURI__.path; const fs = window.__TAURI__.fs; const { invoke } = window.__TAURI__.core; const os = window.__TAURI__.os; - +const dialog = window.__TAURI__.dialog; +const opener = window.__TAURI__.opener; const separator = os.family() == "windows" ? "\\" : "/"; @@ -109,9 +110,6 @@ app.ports.getDestinationSubdirectories.subscribe(function (directoryName) { // Rename multiple files app.ports.renameFiles.subscribe(function (renamings) { - console.log(renamings); - // invoke("rename", { changes: renamings }); - // for(const renaming of renamings) { fs.rename(renaming.oldName, renaming.newName) .then(() => { @@ -130,3 +128,71 @@ app.ports.renameFiles.subscribe(function (renamings) { } }); + +// Moves a list of files to the given directory +app.ports.moveFiles.subscribe(function (params) { + let sourceFiles = params[0]; + let directoryName = params[1]; + console.log("move", params); + for(const sourceFile of sourceFiles) { + const lastSeparatorIndex = sourceFile.lastIndexOf(separator); + const dir = sourceFile.substring(0, lastSeparatorIndex + 1); + const fileName = sourceFile.substring(lastSeparatorIndex + 1); + const destinationFile = directoryName + separator + fileName; + fs.rename(sourceFile, destinationFile) + .then(() => { + getFileMetadata(directoryName, fileName).then((fileInfo)=> { + fileInfo.PreviousName = sourceFile; + app.ports.receiveMovedFiles.send([fileInfo]); + }); + }) + .catch((msg) => { + console.error(msg); + app.ports.receiveError.send(msg); + }); + + } +}); + +// Open file chooser to select a source directory +app.ports.selectSourceDirectory.subscribe(function (directoryName, title) { + dialog.open({ + multiple: false, + directory: true, + defaultPath: directoryName, + title: title, + }) + .then((result) => { + app.ports.receiveSelectedSourceDirectory.send(result); + }) + .catch((msg) => { + console.error(msg); + app.ports.receiveError.send(msg); + }); +}); + +// Open file chooser to select a destination directory +app.ports.selectDestinationDirectory.subscribe(function (directoryName, title) { + dialog.open({ + multiple: false, + directory: true, + defaultPath: directoryName, + title: title, + }) + .then((result) => { + app.ports.receiveSelectedDestinationDirectory.send(result); + }) + .catch((msg) => { + console.error(msg); + app.ports.receiveError.send(msg); + }); +}); + +// Open a file using the default app +app.ports.openFile.subscribe(function (filePath) { + opener.openPath(filePath).catch((msg) => { + console.error(msg); + app.ports.receiveError.send(msg); + }); +}); +