Skip to content

Commit 53e334e

Browse files
committed
✨ 支持CLI打开文件
1 parent 2dc81ed commit 53e334e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

app/src/main.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import { store } from "@/state";
1313
import { exit, writeStderr } from "@/utils/otherApi";
1414
import { getCurrentWindow, isDesktop, isMobile, isWeb } from "@/utils/platform";
1515
import { getMatches } from "@tauri-apps/plugin-cli";
16+
import { exists } from "@tauri-apps/plugin-fs";
1617
import "driver.js/dist/driver.css";
1718
import i18next from "i18next";
1819
import { Provider } from "jotai";
1920
import { createRoot } from "react-dom/client";
2021
import { initReactI18next } from "react-i18next";
22+
import { toast } from "sonner";
2123
import VConsole from "vconsole";
24+
import { URI } from "vscode-uri";
2225
import App from "./App";
26+
import { onOpenFile } from "./core/service/GlobalMenu";
2327
import "./css/index.css";
2428

2529
if (import.meta.env.DEV && isMobile) {
@@ -45,6 +49,7 @@ const el = document.getElementById("root")!;
4549
// 这些东西依赖上面的东西,所以单独一个Promise.all
4650
await Promise.all([loadLanguageFiles(), loadSyncModules()]);
4751
await renderApp(isCliMode);
52+
await loadStartFile();
4853
if (isCliMode) {
4954
try {
5055
await runCli(matches);
@@ -104,3 +109,16 @@ async function renderApp(cli: boolean = false) {
104109
);
105110
}
106111
}
112+
113+
async function loadStartFile() {
114+
const cliMatches = await getMatches();
115+
if (cliMatches.args.path.value) {
116+
const path = cliMatches.args.path.value as string;
117+
const isExists = await exists(path);
118+
if (isExists) {
119+
onOpenFile(URI.file(path), "CLI或双击文件");
120+
} else {
121+
toast.error("文件不存在");
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)