앱을 종료할 때 - 전체 화면 모드 상태 여부, 화면 크기, 화면 위치 정보를 저장
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const { app } = require('electron');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const configPath = path.join(app.getPath('userData'), 'config.json');
|
||||
|
||||
function readConfig() {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeConfig(data) {
|
||||
try {
|
||||
fs.writeFileSync(configPath, JSON.stringify(data, null, 2));
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function updateConfig(updater) {
|
||||
const cfg = readConfig();
|
||||
updater(cfg);
|
||||
writeConfig(cfg);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
readConfig,
|
||||
updateConfig,
|
||||
writeConfig,
|
||||
};
|
||||
+44
-3
@@ -1,15 +1,19 @@
|
||||
const { app, BrowserWindow } = require('electron');
|
||||
const { app, BrowserWindow, screen } = require('electron');
|
||||
const path = require('path');
|
||||
const { registerAll } = require('./ipc');
|
||||
const { readConfig, updateConfig } = require('./config');
|
||||
|
||||
app.setName('Photo Renamer');
|
||||
|
||||
let mainWindow;
|
||||
|
||||
function createWindow() {
|
||||
const windowState = getSavedWindowState();
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 820,
|
||||
x: windowState.bounds?.x,
|
||||
y: windowState.bounds?.y,
|
||||
width: windowState.bounds?.width || 1200,
|
||||
height: windowState.bounds?.height || 820,
|
||||
minWidth: 900,
|
||||
minHeight: 600,
|
||||
titleBarStyle: 'hiddenInset',
|
||||
@@ -27,8 +31,11 @@ function createWindow() {
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow.show();
|
||||
if (windowState.isFullScreen) mainWindow.setFullScreen(true);
|
||||
});
|
||||
|
||||
mainWindow.on('close', saveWindowState);
|
||||
|
||||
mainWindow.on('enter-full-screen', () => {
|
||||
mainWindow.webContents.send('fullscreen-change', true);
|
||||
});
|
||||
@@ -37,6 +44,40 @@ function createWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
function getSavedWindowState() {
|
||||
const cfg = readConfig();
|
||||
const state = cfg.windowState || {};
|
||||
const bounds = isUsableBounds(state.bounds) ? state.bounds : null;
|
||||
return {
|
||||
bounds,
|
||||
isFullScreen: state.isFullScreen === true,
|
||||
};
|
||||
}
|
||||
|
||||
function isUsableBounds(bounds) {
|
||||
if (!bounds) return false;
|
||||
const values = [bounds.x, bounds.y, bounds.width, bounds.height];
|
||||
if (!values.every(Number.isFinite)) return false;
|
||||
if (bounds.width < 900 || bounds.height < 600) return false;
|
||||
return screen.getAllDisplays().some(display => rectanglesOverlap(bounds, display.workArea));
|
||||
}
|
||||
|
||||
function rectanglesOverlap(a, b) {
|
||||
return a.x < b.x + b.width &&
|
||||
a.x + a.width > b.x &&
|
||||
a.y < b.y + b.height &&
|
||||
a.y + a.height > b.y;
|
||||
}
|
||||
|
||||
function saveWindowState() {
|
||||
if (!mainWindow) return;
|
||||
const isFullScreen = mainWindow.isFullScreen();
|
||||
const bounds = isFullScreen ? mainWindow.getNormalBounds() : mainWindow.getBounds();
|
||||
updateConfig(cfg => {
|
||||
cfg.windowState = { isFullScreen, bounds };
|
||||
});
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
registerAll(mainWindow);
|
||||
|
||||
+5
-19
@@ -1,16 +1,8 @@
|
||||
const { ipcMain, dialog, app, shell } = require('electron');
|
||||
const { ipcMain, dialog, shell } = require('electron');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
|
||||
const configPath = path.join(app.getPath('userData'), 'config.json');
|
||||
|
||||
function readConfig() {
|
||||
try { return JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch { return {}; }
|
||||
}
|
||||
function writeConfig(data) {
|
||||
try { fs.writeFileSync(configPath, JSON.stringify(data, null, 2)); } catch {}
|
||||
}
|
||||
const { readConfig, updateConfig } = require('../config');
|
||||
|
||||
function register(mainWindow) {
|
||||
ipcMain.handle('select-folder', async () => {
|
||||
@@ -33,9 +25,7 @@ function register(mainWindow) {
|
||||
});
|
||||
|
||||
ipcMain.handle('set-last-folder', (_e, folderPath) => {
|
||||
const cfg = readConfig();
|
||||
cfg.lastFolder = folderPath;
|
||||
writeConfig(cfg);
|
||||
updateConfig(cfg => { cfg.lastFolder = folderPath; });
|
||||
});
|
||||
|
||||
ipcMain.handle('list-directories', (_e, folderPath) => {
|
||||
@@ -64,9 +54,7 @@ function register(mainWindow) {
|
||||
});
|
||||
|
||||
ipcMain.handle('set-preview-on', (_e, on) => {
|
||||
const cfg = readConfig();
|
||||
cfg.previewOn = on;
|
||||
writeConfig(cfg);
|
||||
updateConfig(cfg => { cfg.previewOn = on; });
|
||||
});
|
||||
|
||||
ipcMain.handle('get-sidebar-width', () => {
|
||||
@@ -75,9 +63,7 @@ function register(mainWindow) {
|
||||
});
|
||||
|
||||
ipcMain.handle('set-sidebar-width', (_e, width) => {
|
||||
const cfg = readConfig();
|
||||
cfg.sidebarWidth = width;
|
||||
writeConfig(cfg);
|
||||
updateConfig(cfg => { cfg.sidebarWidth = width; });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user