diff --git a/src/main/IPCs.ts b/src/main/IPCs.ts index f2a28e4..6ae2406 100644 --- a/src/main/IPCs.ts +++ b/src/main/IPCs.ts @@ -2,12 +2,13 @@ import { ipcMain, shell, IpcMainEvent, dialog } from 'electron' import Constants from './utils/Constants' import { join, dirname } from 'path' import { - writeFileSync, - readFileSync, - existsSync, - ensureDirSync, - copyFileSync, - readdirSync + writeFile, + readFile, + pathExists, + ensureDir, + copy, + readdir, + stat, } from 'fs-extra' import { autoUpdater } from 'electron-updater' import { Template, TreeNode } from '../types' @@ -95,21 +96,19 @@ export default class IPCs { 'msgFindFilesInFolder', async (event: IpcMainEvent, folderPath: string) => { try { - const { readdirSync, statSync } = require('fs') - const { join } = require('path') const foundFiles: string[] = [] - const searchFiles = (dir: string) => { - const items = readdirSync(dir) + const searchFiles = async (dir: string) => { + const items = await readdir(dir) for (const item of items) { const fullPath = join(dir, item) - const stats = statSync(fullPath) + const stats = await stat(fullPath) if (stats.isDirectory()) { // Recursively search in subdirectories - searchFiles(fullPath) + await searchFiles(fullPath) } else if (stats.isFile()) { // Add file to the list foundFiles.push(fullPath) @@ -117,7 +116,7 @@ export default class IPCs { } } - searchFiles(folderPath) + await searchFiles(folderPath) return foundFiles } catch (error) { @@ -136,10 +135,10 @@ export default class IPCs { const filePath = join(userDataPath, fileName) // Ensure directory exists - ensureDirSync(userDataPath) + await ensureDir(userDataPath) - if (existsSync(filePath)) { - const data = readFileSync(filePath, 'utf-8') + if (await pathExists(filePath)) { + const data = await readFile(filePath, 'utf-8') return data } return null @@ -159,9 +158,9 @@ export default class IPCs { const filePath = join(userDataPath, fileName) // Ensure directory exists - ensureDirSync(userDataPath) + await ensureDir(userDataPath) - writeFileSync(filePath, data, 'utf-8') + await writeFile(filePath, data, 'utf-8') return true } catch (error) { console.error('Error saving data:', error) @@ -185,8 +184,8 @@ export default class IPCs { const filePath = join(userDataPath, 'templates.json') let templates: Template[] = [] - if (existsSync(filePath)) { - const templatesData = readFileSync(filePath, 'utf-8') + if (await pathExists(filePath)) { + const templatesData = await readFile(filePath, 'utf-8') templates = JSON.parse(templatesData) } @@ -202,7 +201,7 @@ export default class IPCs { // Create base directory const baseDirPath = join(targetPath, baseDirName) - ensureDirSync(baseDirPath) + await ensureDir(baseDirPath) // Helper function to traverse the tree and collect all nodes const collectAllNodes = (nodes: TreeNode[], allNodes: TreeNode[] = [], parent?: TreeNode) => { @@ -227,20 +226,20 @@ export default class IPCs { const nodePath = join(baseDirPath, node.path); if (node.type === 'directory') { - ensureDirSync(nodePath); + await ensureDir(nodePath); } else if (node.type === 'file') { const fileDir = dirname(nodePath); - ensureDirSync(fileDir); + await ensureDir(fileDir); if (node.sourceType === 'file') { - copyFileSync(node.sourcePath, nodePath); + await copy(node.sourcePath, nodePath); } else { // Write content directly - const files = readdirSync(node.sourcePath, { withFileTypes: true }) + const files = await readdir(node.sourcePath, { withFileTypes: true }) for (const file of files) { if (file.isFile() && file.name.startsWith(baseDirName)) { const filePath = join(node.sourcePath, file.name); - copyFileSync(filePath, nodePath); + await copy(filePath, nodePath); } } } diff --git a/src/renderer/components/TemplateCard.vue b/src/renderer/components/TemplateCard.vue index 3f29025..dee45d1 100644 --- a/src/renderer/components/TemplateCard.vue +++ b/src/renderer/components/TemplateCard.vue @@ -1,5 +1,5 @@