Skip to content

Commit

Permalink
fix: 修复因数据存储目录不存在导致应用无法正常使用的问题 (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb authored Jan 14, 2025
1 parent bed14fa commit dc23885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exists, mkdir, writeFile } from "@tauri-apps/plugin-fs";
import { mkdir, writeFile } from "@tauri-apps/plugin-fs";
import { Flex } from "antd";
import clsx from "clsx";
import type { FC } from "react";
Expand Down Expand Up @@ -38,10 +38,6 @@ const File: FC<FileProps> = (props) => {
const getIconPath = async () => {
const iconPath = joinPath(getSaveIconPath(), `${getIconName()}.png`);

const existed = await exists(iconPath);

if (existed) return iconPath;

await mkdir(getSaveIconPath(), { recursive: true });

const bytes = await icon(path, 256);
Expand Down
18 changes: 8 additions & 10 deletions src/utils/store.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import type { Store } from "@/types/store";
import { getName, getVersion } from "@tauri-apps/api/app";
import { appDataDir } from "@tauri-apps/api/path";
import { exists, readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
import {
exists,
mkdir,
readTextFile,
writeTextFile,
} from "@tauri-apps/plugin-fs";
import { type } from "@tauri-apps/plugin-os";
import { omit } from "lodash-es";

/**
* 初始化配置项
*/
const initStore = async () => {
const { unit, duration } = clipboardStore.history;

if (unit !== 1) {
deepAssign(clipboardStore.history, {
unit: 1,
duration: duration * unit,
});
}

globalStore.appearance.language ??= await getLocale();
globalStore.env.platform = await type();
globalStore.env.appName = await getName();
globalStore.env.appVersion = await getVersion();
globalStore.env.saveDataDir ??= await appDataDir();

await mkdir(globalStore.env.saveDataDir, { recursive: true });
};

/**
Expand Down

0 comments on commit dc23885

Please sign in to comment.