-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Electron support for desktop app (#3)
- Loading branch information
Showing
15 changed files
with
3,020 additions
and
1,944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Build and Release Electron App | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
os: [macos-latest, ubuntu-latest] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22' | ||
|
||
- name: Install dependencies | ||
run: npm i | ||
|
||
- name: Build app | ||
run: npm run build | ||
|
||
- name: Package Electron app | ||
run: npm run electron-pack | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: app | ||
path: dist/ | ||
|
||
release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: app | ||
path: dist/ | ||
|
||
- name: Create GitHub Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
artifacts: "dist/*" | ||
draft: true | ||
makeLatest: true | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,7 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# Electron build artifacts | ||
/dist/ | ||
*.asar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.cs.allow-jit</key> | ||
<true /> | ||
<key>com.apple.security.network.client</key> | ||
<true /> | ||
<key>com.apple.security.network.server</key> | ||
<true /> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const { app, BrowserWindow } = require('electron'); | ||
const path = require('path'); | ||
const { title } = require('process'); | ||
|
||
function createWindow() { | ||
const win = new BrowserWindow({ | ||
width: 1920, | ||
height: 1640, | ||
movable: true, | ||
// frame: false, | ||
icon: path.join(__dirname, 'assets/icon.png'), | ||
zoomToPageWidth: true, | ||
title: 'LLM Parameter Playground', | ||
minWidth: 1660, | ||
minHeight: 1080, | ||
roundedCorners: true, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
nodeIntegration: true, | ||
nodeIntegrationInWorker: true, | ||
contextIsolation: true, | ||
webSecurity: true | ||
} | ||
}); | ||
|
||
const startUrl = `file://${path.join(app.getAppPath(), 'out/index.html')}`; | ||
|
||
win.loadURL(startUrl); | ||
|
||
// Enable devtools | ||
// win.webContents.openDevTools(); | ||
|
||
win.once('ready-to-show', () => { | ||
win.show() | ||
}) | ||
|
||
} | ||
|
||
const { session } = require('electron') | ||
|
||
app.whenReady().then(() => { | ||
// allow all cors | ||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => { | ||
details.requestHeaders['Origin'] = '*'; | ||
callback({ requestHeaders: details.requestHeaders }); | ||
}); | ||
|
||
|
||
session.defaultSession.webRequest.onHeadersReceived((details, callback) => { | ||
if (details.responseHeaders) { | ||
details.responseHeaders['Access-Control-Allow-Origin'] = ['*']; | ||
} | ||
callback({ responseHeaders: details.responseHeaders }); | ||
}); | ||
|
||
createWindow(); | ||
}); | ||
|
||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
app.on('activate', () => { | ||
if (BrowserWindow.getAllWindows().length === 0) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
// improve performance of first launch by caching the app | ||
app.commandLine.appendSwitch('js-flags', '--no-lazy'); | ||
|
||
//hot reload | ||
try { | ||
require('electron-reloader')(module) | ||
} catch (_) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// module.exports = { | ||
// output: 'export', | ||
// images: { | ||
// unoptimized: true, | ||
// }, | ||
// } | ||
module.exports = { | ||
output: 'export', | ||
images: { | ||
unoptimized: true, | ||
}, | ||
assetPrefix: './', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.