Skip to content

Commit 36b61cd

Browse files
committed
feat: 新增工作区功能
1 parent 5c07b42 commit 36b61cd

9 files changed

Lines changed: 381 additions & 14 deletions

File tree

lang/index.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,5 +3790,85 @@
37903790
"ru": "",
37913791
"en": "",
37923792
"fr": ""
3793+
},
3794+
"e524j3": {
3795+
"zh-cn": "工作区",
3796+
"ja": "",
3797+
"ko": "",
3798+
"ru": "",
3799+
"en": "",
3800+
"fr": ""
3801+
},
3802+
"mjd0oik": {
3803+
"zh-cn": "设置启动时自动打开的文件夹与左侧边栏状态",
3804+
"ja": "",
3805+
"ko": "",
3806+
"ru": "",
3807+
"en": "",
3808+
"fr": ""
3809+
},
3810+
"e5yyyxb": {
3811+
"zh-cn": "选择启动时打开的工作区",
3812+
"ja": "",
3813+
"ko": "",
3814+
"ru": "",
3815+
"en": "",
3816+
"fr": ""
3817+
},
3818+
"f6hxpy5": {
3819+
"zh-cn": "启动工作区",
3820+
"ja": "",
3821+
"ko": "",
3822+
"ru": "",
3823+
"en": "",
3824+
"fr": ""
3825+
},
3826+
"ahzl2qi": {
3827+
"zh-cn": "未设置,软件启动时不会自动打开文件夹",
3828+
"ja": "",
3829+
"ko": "",
3830+
"ru": "",
3831+
"en": "",
3832+
"fr": ""
3833+
},
3834+
"ikw1xd4": {
3835+
"zh-cn": "选择位置",
3836+
"ja": "",
3837+
"ko": "",
3838+
"ru": "",
3839+
"en": "",
3840+
"fr": ""
3841+
},
3842+
"he57l4": {
3843+
"zh-cn": " 清除 ",
3844+
"ja": "",
3845+
"ko": "",
3846+
"ru": "",
3847+
"en": "",
3848+
"fr": ""
3849+
},
3850+
"c6pvhz4": {
3851+
"zh-cn": "左侧边栏",
3852+
"ja": "",
3853+
"ko": "",
3854+
"ru": "",
3855+
"en": "",
3856+
"fr": ""
3857+
},
3858+
"rwhea1g": {
3859+
"zh-cn": "启动时自动展开文件夹 / 大纲栏",
3860+
"ja": "",
3861+
"ko": "",
3862+
"ru": "",
3863+
"en": "",
3864+
"fr": ""
3865+
},
3866+
"wv7y05": {
3867+
"zh-cn": "路径不存在",
3868+
"ja": "",
3869+
"ko": "",
3870+
"ru": "",
3871+
"en": "",
3872+
"fr": ""
37933873
}
37943874
}

src/main/ipcBridge.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,15 @@ export function registerGlobalIpcHandlers() {
11301130
}
11311131
});
11321132

1133+
ipcMain.handle("workspace:exists", async (_event, dirPath: string) => {
1134+
try {
1135+
if (!dirPath) return false;
1136+
return fs.existsSync(dirPath);
1137+
} catch {
1138+
return false;
1139+
}
1140+
});
1141+
11331142
// 监听文件变化
11341143
ipcMain.on("file:watch", (event, filePaths: string[]) => {
11351144
// 更新主进程的文件打开索引(用于跨窗口文件去重 O(1) 查询)

src/preload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
8787
// 文件夹相关
8888
getDirectoryFiles: (dirPath: string) =>
8989
ipcRenderer.invoke("workspace:getDirectoryFiles", dirPath),
90+
workspaceExists: (dirPath: string) => ipcRenderer.invoke("workspace:exists", dirPath),
9091
// 监听文件变化
9192
watchFiles: (filePaths: string[]) => ipcRenderer.send("file:watch", filePaths),
9293

src/renderer/App.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<script setup lang="ts">
22
import emitter from "@/renderer/events";
33
import { useContext } from "@/renderer/hooks/useContext";
4+
import { useConfig } from "@/renderer/hooks/useConfig";
45
import useFont from "@/renderer/hooks/useFont";
56
import useOtherConfig from "@/renderer/hooks/useOtherConfig";
6-
import { isShowOutline } from "@/renderer/hooks/useOutline";
7+
import { isShowOutline, toggleShowOutline } from "@/renderer/hooks/useOutline";
78
import { useSaveConfirmDialog } from "@/renderer/hooks/useSaveConfirmDialog";
89
import useSourceCode from "@/renderer/hooks/useSourceCode";
910
import useSpellCheck from "@/renderer/hooks/useSpellCheck";
1011
import useTab from "@/renderer/hooks/useTab";
1112
import useTheme from "@/renderer/hooks/useTheme";
1213
import { useUpdateDialog } from "@/renderer/hooks/useUpdateDialog";
14+
import useWorkSpace from "@/renderer/hooks/useWorkSpace";
1315
import SaveConfirmDialog from "./components/dialogs/SaveConfirmDialog.vue";
1416
import UpdateConfirmDialog from "./components/dialogs/UpdateConfirmDialog.vue";
1517
import MilkupEditor from "./components/editor/MilkupEditor.vue";
@@ -24,6 +26,8 @@ useContext();
2426
const { init: initTheme } = useTheme();
2527
const { init: initFont } = useFont();
2628
const { init: initOtherConfig } = useOtherConfig();
29+
const { config } = useConfig();
30+
const { openWorkSpaceByPath } = useWorkSpace();
2731
const { isShowSource } = useSourceCode(); // 用于控制大纲显示
2832
const { init: initSpellCheck } = useSpellCheck();
2933
const {
@@ -135,6 +139,15 @@ onMounted(() => {
135139
initFont();
136140
initOtherConfig();
137141
initSpellCheck();
142+
toggleShowOutline(Boolean(config.value.workspace?.autoExpandSidebar));
143+
const startupPath = config.value.workspace?.startupPath;
144+
if (startupPath) {
145+
window.electronAPI.workspaceExists(startupPath).then((exists) => {
146+
if (exists) {
147+
openWorkSpaceByPath(startupPath);
148+
}
149+
});
150+
}
138151
emitter.on("update:available", onUpdateAvailable);
139152
});
140153
onUnmounted(() => {

src/renderer/components/settings/SettingBase.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AppIcon from "@/renderer/components/ui/AppIcon.vue";
33
import AISetting from "./AISetting.vue";
44
import ImageConfig from "./ImageConfig.vue";
55
import SpellCheckSetter from "./SpellCheckSetter.vue";
6+
import WorkspaceSetting from "./WorkspaceSetting.vue";
67
78
const settingSections = [
89
{
@@ -23,6 +24,12 @@ const settingSections = [
2324
icon: "magic-wand",
2425
component: AISetting,
2526
},
27+
{
28+
title: "工作区",
29+
desc: "设置启动时自动打开的文件夹与左侧边栏状态",
30+
icon: "folder-opened",
31+
component: WorkspaceSetting,
32+
},
2633
] as const;
2734
</script>
2835

0 commit comments

Comments
 (0)