mirror of
https://github.com/Gabi-Zar/Silk-Fly-Launcher.git
synced 2026-04-17 05:26:04 +02:00
change indentation and add import config
This commit is contained in:
91
main.js
91
main.js
@@ -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)
|
||||
})
|
||||
Reference in New Issue
Block a user