-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25ad446
commit f6ff3c5
Showing
12 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
import { dialog, ipcMain } from "electron"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import os from "node:os"; | ||
import { isEmptyDir } from "./utils"; | ||
|
||
/** | ||
* 打开文件 | ||
*/ | ||
ipcMain.handle("open-file", () => { | ||
const root = dialog.showOpenDialogSync({ | ||
// 用户目录 | ||
defaultPath: os.homedir(), | ||
// 只能选择文件夹 | ||
properties: ["openDirectory"], | ||
}); | ||
if (root && Array.isArray(root) && root.length > 0) { | ||
return root[0]; | ||
// 查看当前根目录的文件 | ||
const filesWithType = fs.readdirSync(root[0], { withFileTypes: true }); | ||
// 判断每一个子文件是否是文件夹,如果是文件夹,则判断是否是空文件夹 | ||
const files: FileInfo[] = []; | ||
filesWithType.forEach((file) => { | ||
const isDir = file.isDirectory(); | ||
files.push({ | ||
name: file.name, | ||
parentPath: root[0], | ||
path: path.join(root[0], file.name), | ||
isDir: isDir, | ||
isEmpty: isDir ? isEmptyDir(path.join(root[0], file.name)) : false, | ||
}); | ||
}); | ||
|
||
return files; | ||
} | ||
return ""; | ||
return []; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import fs from "node:fs"; | ||
/** | ||
* 判断一个文件夹是否为空 | ||
* @param dir 文件夹路径 | ||
* @returns 是否为空 | ||
*/ | ||
export function isEmptyDir(dir: string) { | ||
return fs.readdirSync(dir).length === 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as IconFont } from "./icon-font"; | ||
export { default as Tabbar } from "./tabbar"; | ||
export { default as MainEmpty } from "./main-empty"; | ||
export { default as Slider } from "./slider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useProjectFiles } from "@/store"; | ||
import IconFont from "../icon-font"; | ||
|
||
export default function Slider() { | ||
const files = useProjectFiles((state) => state.files); | ||
return ( | ||
<div className="p-4 h-full overflow-y-auto"> | ||
{files.map((file) => { | ||
return ( | ||
<div key={file.name} className="flex items-center gap-2"> | ||
<IconFont | ||
name={file.isDir ? "dir" : "file"} | ||
className="text-white" | ||
/> | ||
<span className="flex-1 text-white whitespace-nowrap overflow-hidden"> | ||
{file.name} | ||
</span> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { create } from "zustand"; | ||
|
||
interface UseProjectFilesState { | ||
files: FileInfo[]; | ||
} | ||
interface UseProjectFilesActions { | ||
setFiles: (files: FileInfo[]) => void; | ||
} | ||
|
||
export const useProjectFiles = create< | ||
UseProjectFilesState & UseProjectFilesActions | ||
>()((set, get) => ({ | ||
files: [], | ||
setFiles: (files: FileInfo[]) => set({ files }), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters