fixes #4 : files will highlighed when opened in Explorer
Anmol Gupta committed
Oct 2, 2022 at 13:15 UTC
3e5276e1ca4939582a4b560b5f53112882bbea53
4 files changed
+28
-10
src-tauri/src/main.rs
+18
@@ -3,8 +3,26 @@
3
windows_subsystem = "windows"
4
)]
5
6
+use std::process::Command;
7
+use std::env;
8
+#[tauri::command]
9
+fn open_in_explorer(path: &str){
10
+ // FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
11
+ // REF - https://github.com/tauri-apps/tauri/issues/4062
12
+ // TARGET - WINDOWS
13
+ if env:: consts:: OS == "windows" {
14
+ Command::new("explorer")
15
+ .args(["/select,",path])
16
+ .spawn()
17
+ .unwrap();
18
+ }
19
+}
20
+
21
fn main() {
22
tauri::Builder::default()
23
+ .invoke_handler(tauri::generate_handler![
24
+ open_in_explorer
25
+ ])
26
.run(tauri::generate_context!())
27
.expect("error while running tauri application");
28
}
src/components/Content/Editor/TabMenu.svelte
+3
-4
@@ -3,7 +3,7 @@
3
import ContextMenu from "../../ContextMenu/ContextMenu.svelte";
4
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
5
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
6
- import { clipboard, shell, path } from "@tauri-apps/api";
6
+ import { clipboard, path, invoke } from "@tauri-apps/api";
7
import { closeTab, setActive } from "./Tabs";
8
export let id: number;
9
export let target;
@@ -47,9 +47,8 @@
47
</ContextMenuOption>
48
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
49
let dir = filepath.split(path.sep);
50
- dir.pop();
51
- dir = dir.join(path.sep);
52
- shell.open(dir);
50
+ let explorerPath = dir.join(path.sep);
51
+ invoke("open_in_explorer",{ path:explorerPath})
52
}}></ContextMenuOption>
53
</ContextMenu>
54
src/components/FileTree/LeafNodeMenu.svelte
+3
-4
@@ -5,7 +5,7 @@
5
import CopyFile from "carbon-icons-svelte/lib/CopyFile.svelte";
6
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
7
import Script from "carbon-icons-svelte/lib/Script.svelte";
8
- import { fs, clipboard, shell, path } from "@tauri-apps/api";
8
+ import { fs, clipboard, path, invoke } from "@tauri-apps/api";
9
export let target;
10
export let filename;
11
export let filepath;
@@ -40,9 +40,8 @@
40
</ContextMenuOption>
41
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
42
let dir = filepath.split(path.sep);
43
- dir.pop();
44
- dir = dir.join(path.sep);
45
- shell.open(dir);
43
+ let explorerPath = dir.join(path.sep);
44
+ invoke("open_in_explorer",{ path:explorerPath})
45
}}></ContextMenuOption>
46
47
<ContextMenuDivider></ContextMenuDivider>
src/components/FileTree/ParentNodeMenu.svelte
+4
-2
@@ -5,7 +5,7 @@
5
import Paste from "carbon-icons-svelte/lib/Paste.svelte";
6
import Cut from "carbon-icons-svelte/lib/Cut.svelte";
7
import RenameModel from "../Modal/RenameModel.svelte";
8
- import { fs, clipboard, shell, path } from "@tauri-apps/api";
8
+ import { fs, clipboard, invoke, path } from "@tauri-apps/api";
9
export let target;
10
export let filename;
11
export let filepath;
@@ -41,7 +41,9 @@
41
</ContextMenuOption>
42
</ContextMenuOption>
43
<ContextMenuOption labelText="Show in Explorer" on:click={() => {
44
- shell.open(filepath);
44
+ let dir = filepath.split(path.sep);
45
+ let explorerPath = dir.join(path.sep);
46
+ invoke("open_in_explorer",{ path:explorerPath})
47
}}></ContextMenuOption>
48
<ContextMenuDivider></ContextMenuDivider>
49
<ContextMenuOption labelText="Delete..." on:click={ async() => {