Skip to content

Commit

Permalink
chore(build): windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mayneyao committed Oct 12, 2024
1 parent b9e40c4 commit d895508
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 6 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build-and-release-windows-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build Windows App

on:
release:
types: [prereleased]

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20.16.0"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

#TODO - Remove this once https://github.com/electron-userland/electron-builder/issues/6933#issuecomment-1213438889 is resolved
- name: Tweak pnpm.cjs
run: sed -i 's/\/usr\/bin\/env node/node/g' /c/Users/runneradmin/setup-pnpm/node_modules/.pnpm/[email protected]/node_modules/pnpm/bin/pnpm.cjs
shell: bash

- name: Download and extract libsimple
run: |
curl -L https://github.com/wangfenjin/simple/releases/latest/download/libsimple-windows-x64.zip -o libsimple.zip
Expand-Archive libsimple.zip -DestinationPath . -Force
$libsimple_dir = Get-ChildItem -Directory | Where-Object { $_.Name -like "libsimple*" } | Select-Object -First 1
if ($libsimple_dir) {
Move-Item $libsimple_dir.FullName dist-simple
} else {
New-Item -ItemType Directory -Name dist-simple
Move-Item libsimple* dist-simple/
}
# rename simple.dll to libsimple.dll
Rename-Item -Path "dist-simple/simple.dll" -NewName "libsimple.dll"
Get-ChildItem -Recurse dist-simple
shell: pwsh

- name: Install dependencies
run: pnpm install

- name: Build application
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: pnpm run build:desktop

- name: Build without Signing
run: pnpm run pkg:desktop

- name: List dist-app contents
run: Get-ChildItem -Path dist-app -Force

- name: Update Release
uses: softprops/action-gh-release@v2
with:
files: |
dist-app/*.exe
dist-app/*.zip
dist-app/latest*.yml
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
36 changes: 32 additions & 4 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MsgType } from '@/lib/const';
import { handleFunctionCall } from '@/lib/rpc';
import { app, BrowserWindow, dialog, ipcMain } from 'electron';
import { app, BrowserWindow, dialog, ipcMain, Tray, Menu, nativeImage } from 'electron';
import path from 'path';
import { getDataSpace, getOrSetDataSpace } from './data-space';
import { startServer } from './server/server';
Expand All @@ -10,8 +10,8 @@ import { log } from 'electron-log';
import { AppUpdater } from './updater';

export let win: BrowserWindow | null

let appUpdater: AppUpdater;
let tray: Tray | null

export const PORT = 13127;

Expand Down Expand Up @@ -112,17 +112,45 @@ app.on('before-quit', () => {
forceQuit = true;
});

function createTray() {
try {
const iconPath = path.join(process.env.VITE_PUBLIC, '512.png');
log('Tray icon path:', iconPath);

const icon = nativeImage.createFromPath(iconPath);
tray = new Tray(icon);

const contextMenu = Menu.buildFromTemplate([
{ label: 'show', click: () => win?.show() },
{ label: 'exit', click: () => { forceQuit = true; app.quit(); } }
]);

tray.setToolTip('Eidos');
tray.setContextMenu(contextMenu);

log('Tray created successfully');
} catch (error) {
log('Error creating tray:', error);
}
}

app.whenReady().then(() => {
win = createWindow()
createTray();

win.on('close', (event) => {
if (!forceQuit) {
event.preventDefault();
win?.hide();
if (process.platform === 'darwin') {
win?.hide();
} else {
win?.minimize();
}
}
});
appUpdater = new AppUpdater(win);
appUpdater.checkForUpdates();
})
});

app.on('activate', () => {
if (win) {
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
}
],
"win": {
"target": "nsis"
"target": [
"nsis",
"zip"
],
"icon": "dist/512.png"
},
"afterSign": "scripts/notarize.cjs",
"mac": {
Expand Down Expand Up @@ -293,4 +297,4 @@
]
}
}
}
}

0 comments on commit d895508

Please sign in to comment.