change indentation and add import config

This commit is contained in:
2026-01-19 12:23:16 +01:00
parent 0b5ee51ebd
commit 11ac159909
5 changed files with 322 additions and 303 deletions

91
main.js
View File

@@ -7,74 +7,89 @@ const store = new Store();
const userSavePath = app.getPath('userData')
const createWindow = () => {
const win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
const win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('renderer/index.html')
win.loadFile('renderer/index.html')
}
app.whenReady().then(() => {
createWindow()
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
if (process.platform !== 'darwin') {
app.quit()
}
})
ipcMain.handle('save-path', (event, path) => {
store.set('silksong-path', path);
store.set('silksong-path', path);
});
ipcMain.handle('load-path', () => {
return store.get('silksong-path');
return store.get('silksong-path');
});
async function fileExists(filePath) {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
ipcMain.handle('file-exists', async (_, filePath) => {
return await fileExists(filePath);
return await fileExists(filePath);
});
ipcMain.handle('get-userSavePath', () => {
return userSavePath
return userSavePath
});
ipcMain.handle('delete-data', async (event, path) => {
await fs.unlink(path)
await fs.unlink(path)
});
ipcMain.handle('export-data', async () => {
const dataPath = `${userSavePath}\\config.json`
const dataPath = `${userSavePath}\\config.json`
const { canceled, filePath } = await dialog.showSaveDialog({
title: 'Export Data',
defaultPath: 'config.json',
filters: [
{ name: 'JSON', extensions: ['json'] }
]
})
const { canceled, filePath } = await dialog.showSaveDialog({
title: 'Export Data',
defaultPath: 'config.json',
filters: [
{ name: 'JSON', extensions: ['json'] }
]
})
if (canceled || !filePath) return
if (canceled || !filePath) return
await fs.copyFile(dataPath, filePath)
await fs.copyFile(dataPath, filePath)
})
ipcMain.handle('import-data', async () => {
const dataPath = `${userSavePath}\\config.json`
const { canceled, filePaths } = await dialog.showOpenDialog({
title: 'Import Data',
properties: ['openFile'],
filters: [{ name: 'JSON', extensions: ['json'] }]
})
if (canceled || !filePaths) return
await fs.unlink(dataPath)
await fs.copyFile(filePaths[0], dataPath,fs.constants.COPYFILE_EXCL)
})