diff --git a/.env.electron b/.env.electron deleted file mode 100644 index b49ad90..0000000 --- a/.env.electron +++ /dev/null @@ -1,3 +0,0 @@ -# 데스크톱(Electron) 빌드 전용 — `vite build --mode electron` 이 로드. -# file:// 로 로드되므로 백엔드 절대 URL 을 지정한다. -VITE_API_BASE_URL=https://app.sblog.kr/api diff --git a/electron/main.cjs b/electron/main.cjs index faf484b..03685cb 100644 --- a/electron/main.cjs +++ b/electron/main.cjs @@ -1,7 +1,22 @@ // Slim Budget 데스크톱(Electron) 메인 프로세스. -// dist(웹 빌드, --mode electron)를 창에 로드한다. 백엔드는 https://app.sblog.kr/api 사용. +// 라이브 사이트(https://app.sblog.kr)를 직접 로드한다 → 프론트 변경이 자동 반영(재설치 불필요), +// 같은 출처라 CORS 우회도 불필요. 배포된 웹 게이트가 Electron 을 감지해 안내페이지 대신 전체 앱을 띄운다. const { app, BrowserWindow, shell } = require('electron') -const path = require('path') + +const APP_URL = 'https://app.sblog.kr' + +// 오프라인/로드 실패 시 안내 화면 (다시 시도 버튼) +function offlineHtml() { + const html = `Slim Budget + +

연결할 수 없습니다

인터넷 연결을 확인해 주세요.

+
` + return 'data:text/html;charset=utf-8,' + encodeURIComponent(html) +} function createWindow() { const win = new BrowserWindow({ @@ -14,20 +29,25 @@ function createWindow() { webPreferences: { contextIsolation: true, nodeIntegration: false, - // file:// 출처에서 자기 백엔드(https://app.sblog.kr/api) 호출 시 CORS 차단을 피한다. - // 신뢰된 로컬 dist + 자체 API 만 로드하는 데스크톱 클라이언트라 허용 가능한 완화. - webSecurity: false, }, }) // 기본 메뉴바 제거(앱 자체 내비게이션 사용) win.removeMenu() - win.loadFile(path.join(__dirname, '..', 'dist', 'index.html')) + win.loadURL(APP_URL) - // 외부 링크(target=_blank 등)는 기본 브라우저로 열기 + // 메인 프레임 로드 실패(오프라인 등) 시 안내 화면. -3(aborted, 리다이렉트 등)은 무시. + win.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL, isMainFrame) => { + if (isMainFrame && errorCode !== -3) win.loadURL(offlineHtml()) + }) + + // 외부(앱 외 도메인) 링크는 기본 브라우저로, 앱 내 링크는 창에서 처리 win.webContents.setWindowOpenHandler(({ url }) => { - if (/^https?:\/\//i.test(url)) shell.openExternal(url) - return { action: 'deny' } + if (/^https?:\/\//i.test(url) && !url.startsWith(APP_URL)) { + shell.openExternal(url) + return { action: 'deny' } + } + return { action: 'allow' } }) } diff --git a/package.json b/package.json index 5edf4c1..ca7e151 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,8 @@ "dev": "vite", "build": "vite build", "build:app": "vite build --mode capacitor", - "build:electron": "vite build --mode electron", - "electron:dev": "npm run build:electron && electron .", - "electron:build": "npm run build:electron && electron-builder --win", + "electron:dev": "electron .", + "electron:build": "electron-builder --win", "test": "vitest run", "test:watch": "vitest", "cap:sync": "npm run build:app && cap sync", @@ -27,7 +26,6 @@ "output": "release-desktop" }, "files": [ - "dist/**/*", "electron/**/*" ], "win": {