Files
sb-front/electron/main.cjs
T
ByungCheol 9de26cf417
CI / build (push) Failing after 14m5s
feat: 데스크톱 클라이언트가 라이브 사이트 직접 로드 — 프론트 변경 자동 반영(재설치 불필요)
- electron/main.cjs: dist 번들 → https://app.sblog.kr 직접 로드
  · 같은 출처라 webSecurity:false(CORS 우회) 제거, 오프라인 시 '다시 시도' 안내 화면
  · 앱 외 도메인 링크만 기본 브라우저로
- package.json: 설치파일에 dist 미포함·build:electron 제거(원격 로드라 불필요)
- .env.electron 삭제

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 16:39:28 +09:00

64 lines
2.5 KiB
JavaScript

// Slim Budget 데스크톱(Electron) 메인 프로세스.
// 라이브 사이트(https://app.sblog.kr)를 직접 로드한다 → 프론트 변경이 자동 반영(재설치 불필요),
// 같은 출처라 CORS 우회도 불필요. 배포된 웹 게이트가 Electron 을 감지해 안내페이지 대신 전체 앱을 띄운다.
const { app, BrowserWindow, shell } = require('electron')
const APP_URL = 'https://app.sblog.kr'
// 오프라인/로드 실패 시 안내 화면 (다시 시도 버튼)
function offlineHtml() {
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Slim Budget</title>
<style>html,body{height:100%;margin:0;display:flex;align-items:center;justify-content:center;
background:#1a1a1a;color:#eee;font-family:system-ui,'Segoe UI',sans-serif}
.box{text-align:center}h2{margin:0 0 8px}p{opacity:.7;margin:0}
button{margin-top:18px;padding:10px 22px;border:0;border-radius:8px;background:#00bc7e;color:#fff;
font-size:15px;font-weight:600;cursor:pointer}</style></head>
<body><div class="box"><h2>연결할 수 없습니다</h2><p>인터넷 연결을 확인해 주세요.</p>
<button onclick="location.href='${APP_URL}'">다시 시도</button></div></body></html>`
return 'data:text/html;charset=utf-8,' + encodeURIComponent(html)
}
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 820,
minWidth: 360,
minHeight: 560,
backgroundColor: '#1a1a1a',
title: 'Slim Budget',
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
},
})
// 기본 메뉴바 제거(앱 자체 내비게이션 사용)
win.removeMenu()
win.loadURL(APP_URL)
// 메인 프레임 로드 실패(오프라인 등) 시 안내 화면. -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) && !url.startsWith(APP_URL)) {
shell.openExternal(url)
return { action: 'deny' }
}
return { action: 'allow' }
})
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})