Move and open files
This commit is contained in:
parent
e583d4e4cb
commit
30c5c785f3
7 changed files with 152 additions and 6 deletions
45
src-tauri/Cargo.lock
generated
45
src-tauri/Cargo.lock
generated
|
|
@ -704,6 +704,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
|
"block2",
|
||||||
|
"libc",
|
||||||
"objc2",
|
"objc2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -905,6 +907,7 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
|
"tauri-plugin-dialog",
|
||||||
"tauri-plugin-fs",
|
"tauri-plugin-fs",
|
||||||
"tauri-plugin-opener",
|
"tauri-plugin-opener",
|
||||||
"tauri-plugin-os",
|
"tauri-plugin-os",
|
||||||
|
|
@ -2967,6 +2970,30 @@ dependencies = [
|
||||||
"web-sys",
|
"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]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
|
|
@ -3680,6 +3707,24 @@ dependencies = [
|
||||||
"walkdir",
|
"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]]
|
[[package]]
|
||||||
name = "tauri-plugin-fs"
|
name = "tauri-plugin-fs"
|
||||||
version = "2.4.5"
|
version = "2.4.5"
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,5 @@ serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
tauri-plugin-fs = "2.4.5"
|
tauri-plugin-fs = "2.4.5"
|
||||||
tauri-plugin-os = "2"
|
tauri-plugin-os = "2"
|
||||||
|
tauri-plugin-dialog = "2"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,16 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"os:default"
|
"os:default",
|
||||||
|
"opener:default",
|
||||||
|
{
|
||||||
|
"identifier": "opener:allow-open-path",
|
||||||
|
"allow": [
|
||||||
|
{
|
||||||
|
"path": "/**"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"dialog:default"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
src-tauri/package-lock.json
generated
20
src-tauri/package-lock.json
generated
|
|
@ -5,6 +5,8 @@
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@tauri-apps/plugin-dialog": "^2.6.0",
|
||||||
|
"@tauri-apps/plugin-opener": "^2.5.3",
|
||||||
"@tauri-apps/plugin-os": "^2.3.2"
|
"@tauri-apps/plugin-os": "^2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -18,6 +20,24 @@
|
||||||
"url": "https://opencollective.com/tauri"
|
"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": {
|
"node_modules/@tauri-apps/plugin-os": {
|
||||||
"version": "2.3.2",
|
"version": "2.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-os/-/plugin-os-2.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-os/-/plugin-os-2.3.2.tgz",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@tauri-apps/plugin-dialog": "^2.6.0",
|
||||||
|
"@tauri-apps/plugin-opener": "^2.5.3",
|
||||||
"@tauri-apps/plugin-os": "^2.3.2"
|
"@tauri-apps/plugin-os": "^2.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ fn rename(invoke_message: String) {
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_opener::init())
|
||||||
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.invoke_handler(tauri::generate_handler![rename])
|
.invoke_handler(tauri::generate_handler![rename])
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ const path = window.__TAURI__.path;
|
||||||
const fs = window.__TAURI__.fs;
|
const fs = window.__TAURI__.fs;
|
||||||
const { invoke } = window.__TAURI__.core;
|
const { invoke } = window.__TAURI__.core;
|
||||||
const os = window.__TAURI__.os;
|
const os = window.__TAURI__.os;
|
||||||
|
const dialog = window.__TAURI__.dialog;
|
||||||
|
const opener = window.__TAURI__.opener;
|
||||||
|
|
||||||
const separator = os.family() == "windows" ? "\\" : "/";
|
const separator = os.family() == "windows" ? "\\" : "/";
|
||||||
|
|
||||||
|
|
@ -109,9 +110,6 @@ app.ports.getDestinationSubdirectories.subscribe(function (directoryName) {
|
||||||
|
|
||||||
// Rename multiple files
|
// Rename multiple files
|
||||||
app.ports.renameFiles.subscribe(function (renamings) {
|
app.ports.renameFiles.subscribe(function (renamings) {
|
||||||
console.log(renamings);
|
|
||||||
// invoke("rename", { changes: renamings });
|
|
||||||
//
|
|
||||||
for(const renaming of renamings) {
|
for(const renaming of renamings) {
|
||||||
fs.rename(renaming.oldName, renaming.newName)
|
fs.rename(renaming.oldName, renaming.newName)
|
||||||
.then(() => {
|
.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue