fix: switched file explorer implementation to rust
adds select highlight in file explorer
mellbacon committed
May 30, 2023 at 10:26 UTC
b8ab61da2a01674d85800707d99a273ad4721e28
5 files changed
+22
-42
src-tauri/Cargo.lock
-22
@@ -1653,16 +1653,6 @@ dependencies = [
1653
"windows-sys 0.42.0",
1654
]
1655
1656
-[[package]]
1657
-name = "os_pipe"
1658
-version = "1.1.4"
1659
-source = "registry+https://github.com/rust-lang/crates.io-index"
1660
-checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177"
1661
-dependencies = [
1662
- "libc",
1663
- "windows-sys 0.48.0",
1664
-]
1665
-
1656
[[package]]
1657
name = "overload"
1658
version = "0.1.1"
@@ -2339,16 +2329,6 @@ dependencies = [
2329
"lazy_static",
2330
]
2331
2342
-[[package]]
2343
-name = "shared_child"
2344
-version = "1.0.0"
2345
-source = "registry+https://github.com/rust-lang/crates.io-index"
2346
-checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
2347
-dependencies = [
2348
- "libc",
2349
- "winapi",
2350
-]
2351
-
2332
[[package]]
2333
name = "simd-adler32"
2334
version = "0.3.5"
@@ -2578,7 +2558,6 @@ dependencies = [
2558
"objc",
2559
"once_cell",
2560
"open",
2581
- "os_pipe",
2561
"percent-encoding",
2562
"rand 0.8.5",
2563
"raw-window-handle",
@@ -2589,7 +2568,6 @@ dependencies = [
2568
"serde_json",
2569
"serde_repr",
2570
"serialize-to-javascript",
2592
- "shared_child",
2571
"state",
2572
"tar",
2573
"tauri-macros",
src-tauri/Cargo.toml
+1
-1
@@ -15,7 +15,7 @@ tauri-build = { version = "1.2.1", features = [] }
15
[dependencies]
16
serde_json = "1.0"
17
serde = { version = "1.0", features = ["derive"] }
18
-tauri = { version = "1.2.5", features = ["clipboard-write-text", "dialog-ask", "dialog-confirm", "dialog-open", "dialog-save", "fs-read-dir", "fs-read-file", "fs-rename-file", "fs-write-file", "path-all", "shell-execute", "shell-open", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-print", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-icon", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
18
+tauri = { version = "1.2.5", features = ["clipboard-write-text", "dialog-ask", "dialog-confirm", "dialog-open", "dialog-save", "fs-read-dir", "fs-read-file", "fs-rename-file", "fs-write-file", "path-all", "shell-open", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-print", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-icon", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
19
tauri-plugin-fs-watch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
20
21
[dev-dependencies]
src-tauri/src/main.rs
+17
-1
@@ -3,9 +3,25 @@
3
windows_subsystem = "windows"
4
)]
5
6
+use std::env;
7
+use std::process::Command;
8
+
9
+#[tauri::command]
10
+fn open_in_explorer(path: &str) {
11
+ // FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
12
+ // REF - https://github.com/tauri-apps/tauri/issues/4062
13
+ // TARGET - WINDOWS
14
+ if env::consts::OS == "windows" {
15
+ Command::new("explorer")
16
+ .args(["/select,", path])
17
+ .spawn()
18
+ .unwrap();
19
+ }
20
+}
21
+
22
fn main() {
23
tauri::Builder::default()
8
- .invoke_handler(tauri::generate_handler![])
24
+ .invoke_handler(tauri::generate_handler![open_in_explorer])
25
.plugin(tauri_plugin_fs_watch::init())
26
.run(tauri::generate_context!())
27
.expect("error while running tauri application");
src-tauri/tauri.conf.json
+1
-9
@@ -15,15 +15,7 @@
15
"all": false,
16
"shell": {
17
"all": false,
18
- "open": true,
19
- "execute": true,
20
- "scope": [
21
- {
22
- "name": "explorer",
23
- "cmd": "explorer",
24
- "args": [{ "validator": "\\S+" }]
25
- }
26
- ]
18
+ "open": true
19
},
20
"clipboard": {
21
"all": false,
src/lib/File.ts
+3
-9
@@ -1,8 +1,7 @@
1
-import { dialog, fs, path } from "@tauri-apps/api";
1
+import { dialog, fs, path, invoke } from "@tauri-apps/api";
2
import { get, writable } from 'svelte/store';
3
import { tabs, addEditorTab } from "./EditorTabList.svelte";
4
import { filetree } from "./FileTree.svelte";
5
-import { Command } from '@tauri-apps/api/shell';
5
import { watch } from "tauri-plugin-fs-watch-api";
6
7
export async function openFile() {
@@ -134,11 +133,6 @@ export function updateSaveState(saved = true) {
133
tab.setActive(tab.id);
134
}
135
137
-export async function openInExplorer(path) {
138
- const explorer = new Command("explorer", path);
139
- try {
140
- await explorer.spawn();
141
- } catch (error) {
142
- console.error(error);
143
- }
136
+export async function openInExplorer(path: string) {
137
+ invoke("open_in_explorer",{ path: path});
138
}
\ No newline at end of file