save last build dir
This commit is contained in:
1 parent
9af6aef614
commit
3a2f09541c
4 files changed
+28
-21
No files matched your search
@@ -58,9 +58,7 @@ export const Menu: FC<LayoutProps> = () => {
|
|||||||
);
|
);
|
||||||
const enabled = !!workspace.workdir;
|
const enabled = !!workspace.workdir;
|
||||||
const homedir = app.getPath("home");
|
const homedir = app.getPath("home");
|
||||||
const settings = {
|
const { settings } = useSetting(useShallow((state) => ({ settings: state.data })));
|
||||||
recent: useSetting((state) => state.recent),
|
|
||||||
};
|
|
||||||
|
|
||||||
const menuTemplate: MenuItemConstructorOptions[] = useMemo(() => {
|
const menuTemplate: MenuItemConstructorOptions[] = useMemo(() => {
|
||||||
const recentWorkspaces: MenuItemConstructorOptions[] = settings.recent.map((path, i) => ({
|
const recentWorkspaces: MenuItemConstructorOptions[] = settings.recent.map((path, i) => ({
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const Workspace: FC = () => {
|
|||||||
find: state.find,
|
find: state.find,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
const settings = useSetting(useShallow((state) => ({ recent: state.recent })));
|
const { settings } = useSetting(useShallow((state) => ({ settings: state.data })));
|
||||||
const [isShowingAlert, setShowingAlert] = useState(false);
|
const [isShowingAlert, setShowingAlert] = useState(false);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const forceUpdate = useForceUpdate();
|
const forceUpdate = useForceUpdate();
|
||||||
|
|||||||
@@ -7,47 +7,53 @@ const settingPath = app.getPath("userData") + "/settings.json";
|
|||||||
|
|
||||||
export type SettingModel = {
|
export type SettingModel = {
|
||||||
recent: string[];
|
recent: string[];
|
||||||
|
buildDir: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SettingStore = {
|
export type SettingStore = {
|
||||||
recent: string[];
|
data: SettingModel;
|
||||||
|
|
||||||
load: () => void;
|
load: () => void;
|
||||||
save: () => void;
|
save: () => void;
|
||||||
appendRecent: (path: string) => void;
|
appendRecent: (path: string) => void;
|
||||||
removeRecent: (path: string) => void;
|
removeRecent: (path: string) => void;
|
||||||
|
setBuildDir: (dir: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSetting = create<SettingStore>((set, get) => ({
|
export const useSetting = create<SettingStore>((set, get) => ({
|
||||||
|
data: {
|
||||||
recent: [],
|
recent: [],
|
||||||
|
buildDir: "",
|
||||||
|
},
|
||||||
load: () => {
|
load: () => {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(settingPath)) {
|
if (fs.existsSync(settingPath)) {
|
||||||
const settings = readJson(settingPath) as SettingModel;
|
const settings = readJson(settingPath) as SettingModel;
|
||||||
if (!(settings.recent instanceof Array)) {
|
set({ data: settings });
|
||||||
settings.recent = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
set({ recent: settings.recent });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
save: () => {
|
save: () => {
|
||||||
const settings = get();
|
writeJson(settingPath, get().data);
|
||||||
writeJson(settingPath, {
|
|
||||||
recent: settings.recent,
|
|
||||||
} as SettingModel);
|
|
||||||
},
|
},
|
||||||
appendRecent: (path: string) => {
|
appendRecent: (path: string) => {
|
||||||
const recent = get().recent.filter((v) => v !== path);
|
const { data, save } = get();
|
||||||
|
const recent = data.recent.filter((v) => v !== path);
|
||||||
recent.unshift(path);
|
recent.unshift(path);
|
||||||
set({ recent });
|
set({ data: { ...data, recent } });
|
||||||
get().save();
|
save();
|
||||||
},
|
},
|
||||||
removeRecent: (path: string) => {
|
removeRecent: (path: string) => {
|
||||||
const recent = get().recent.filter((v) => v !== path);
|
const { data, save } = get();
|
||||||
set({ recent });
|
const recent = data.recent.filter((v) => v !== path);
|
||||||
get().save();
|
set({ data: { ...data, recent } });
|
||||||
|
save();
|
||||||
|
},
|
||||||
|
setBuildDir: (dir: string) => {
|
||||||
|
const { data, save } = get();
|
||||||
|
set({ data: { ...data, buildDir: dir } });
|
||||||
|
save();
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -342,12 +342,14 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
|
|
||||||
buildProject: () => {
|
buildProject: () => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
if (workspace.path)
|
if (workspace.path) {
|
||||||
if (!buildDir) {
|
if (!buildDir) {
|
||||||
buildDir = dialog.showOpenDialogSync({
|
buildDir = dialog.showOpenDialogSync({
|
||||||
properties: ["openDirectory", "createDirectory"],
|
properties: ["openDirectory", "createDirectory"],
|
||||||
|
defaultPath: useSetting.getState().data.buildDir,
|
||||||
})?.[0];
|
})?.[0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (buildDir) {
|
if (buildDir) {
|
||||||
for (const editor of workspace.editors) {
|
for (const editor of workspace.editors) {
|
||||||
editor.dispatch("save");
|
editor.dispatch("save");
|
||||||
@@ -382,6 +384,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
} else {
|
} else {
|
||||||
message.success(i18n.t("buildCompleted"));
|
message.success(i18n.t("buildCompleted"));
|
||||||
}
|
}
|
||||||
|
useSetting.getState().setBuildDir(buildDir);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
message.error(i18n.t("buildFailed"));
|
message.error(i18n.t("buildFailed"));
|
||||||
|
|||||||
Reference in new issue
Block a user