init
Some checks failed
Build Electron / Build Dockerfile (push) Failing after 4s
Build Electron / Build Electron (push) Has been skipped

This commit is contained in:
2025-07-18 13:47:26 -04:00
commit d74d18a673
11 changed files with 2418 additions and 0 deletions

69
.github/workflows/build.yaml vendored Normal file
View File

@@ -0,0 +1,69 @@
name: Build Electron
run-name: Build Electron
on:
push:
jobs:
docker:
name: Build Dockerfile
runs-on: ubuntu-latest
container:
image: docker
volumes:
- /tmp/gitea:/tmp/gitea
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Clone Repository
uses: ztimson/actions/clone@develop
- name: Get Version
id: version
run: |
VERSION=$(cat server/package.json | grep version | grep -Eo '[0-9][[:alnum:]\.\/\-]+')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo $VERSION
- name: Build Image
run: |
cd electron
REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%)
docker build -t "$REGISTRY/momentum/electron-builder:${{github.ref_name}}" .
- name: Publish Branch Tag
run: |
REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%)
docker login -u ${{github.repository_owner}} -p ${{secrets.DEPLOY_TOKEN}} $REGISTRY
docker push "$REGISTRY/momentum/electron-builder:${{github.ref_name}}"
- name: Publish Latest Tag
run: |
if [ "${{github.ref_name}}" = "master" ]; then
REGISTRY=$(echo ${{github.server_url}} | sed s%http://%% | sed s%https://%%)
docker tag "$REGISTRY/momentum/electron-builder:${{github.ref_name}}" "$REGISTRY/momentum/electron-builder:latest"
docker push "$REGISTRY/momentum/electron-builder:latest"
fi
electron:
name: Build Electron
runs-on: ubuntu-latest
needs:
- docker
container:
image: git.zakscode.com/momentum/electron-builder:latest
env:
VERSION: ${{ needs.docker.outputs.version }}
steps:
- name: Build inside container
run: |
if [ "${{github.ref_name}}" = "master" ]; then
/app/entrypoint.sh
ls /out
curl -X PUT -H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" --upload-file /out/Momentum-darwin-x64.zip \
https://git.zakscode.com/api/packages/momentum/generic/electron/${{ env.VERSION }}/Momentum-darwin-x64.zip
curl -X PUT -H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" --upload-file /out/Momentum-linux-x64.zip \
https://git.zakscode.com/api/packages/momentum/generic/electron/${{ env.VERSION }}/Momentum-linux-x64.zip
curl -X PUT -H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" --upload-file /out/Momentum-win32-x64.zip \
https://git.zakscode.com/api/packages/momentum/generic/electron/${{ env.VERSION }}/Momentum-win32-x64.zip
fi

15
.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
# IDEs
.idea
.vscode
# Artifacts
**/dist
**/node_modules
coverage
# Logs
*.log
*.tsbuildinfo
# Environment files
*.local

32
Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
FROM node:22-bullseye
# Install build dependencies
RUN dpkg --add-architecture i386 && \
apt-get update && apt-get install -y \
wine64 \
wine32 \
unzip \
zip \
wget \
xvfb \
libx11-dev \
libxkbfile-dev \
libsecret-1-dev \
libgtk-3-dev \
build-essential \
python3 \
lib32z1 \
lib32ncurses6 \
lib32stdc++6 \
g++
# Build
COPY . /app/
WORKDIR /app
RUN chmod +x entrypoint.sh && \
npm i && \
rm -rf /root/.npm/* /root/.cache/* /tmp/*
# Start
ENTRYPOINT ["/bin/bash"]
CMD ["entrypoint.sh"]

8
entrypoint.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
cd /app
npm run build
mkdir -p /out
mv -f /app/dist/*.zip /out/

2185
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
package.json Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "@ztimson/momentum-electron",
"version": "0.53.2",
"description": "Enterprise Record Management",
"author": "ztimson",
"main": "src/main.js",
"scripts": {
"start": "electron src/main.js",
"build": "npm run build:darwin && npm run build:linux && npm run build:win32 && npm run zip",
"build:darwin": "electron-packager . Momentum --platform=darwin --arch=x64 --prune=true --overwrite --out=dist --entry=src/main.js",
"build:linux": "electron-packager . Momentum --platform=linux --arch=x64 --prune=true --overwrite --out=dist --entry=src/main.js",
"build:win32": "electron-packager . Momentum --platform=win32 --arch=x64 --prune=true --overwrite --out=dist --entry=src/main.js",
"zip": "cd dist && for d in Momentum-*; do zip -r \"$d.zip\" \"$d\"; done"
},
"dependencies": {},
"devDependencies": {
"electron": "^34.0.2",
"electron-packager": "^17.1.2"
}
}

3
src/config.json Normal file
View File

@@ -0,0 +1,3 @@
{
"url": "http://localhost:3000"
}

22
src/environment.js Normal file
View File

@@ -0,0 +1,22 @@
const { app } = require('electron');
const fs = require('fs');
const path = require('path');
const packageJson = require('../package.json');
let config, loaded = false, prod = app.isPackaged;
const configPath = path.join(__dirname,'./config.json');
try {
config = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(config);
loaded = true;
} catch {
config = {};
}
module.exports = Object.assign({
loaded,
path: configPath,
production: prod,
version: packageJson.version,
}, config);

BIN
src/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

61
src/main.js Normal file
View File

@@ -0,0 +1,61 @@
const dns = require('dns');
const env = require('./environment');
const electron = require('electron');
const fs = require('fs');
const http = require('http');
const https = require('https');
const path = require('path');
let win;
const iconPath = path.join(__dirname, 'favicon.png');
// Check internet connectivity
async function online() {
return new Promise(resolve => {
dns.lookup('google.com', err => resolve(!err));
});
}
// Download icon
async function downloadIcon() {
if(!await online()) return Promise.resolve();
const iconUrl = `${env.url}/favicon.png`;
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(iconPath);
const proto = env.url.startsWith('https://') ? https : http;
proto.get(iconUrl, res => {
if(res.statusCode !== 200) return; // Incase we are offline
res.pipe(file);
file.on('finish', () => file.close(resolve));
}).on('error', reject);
});
}
async function createWindow() {
await downloadIcon();
win = new electron.BrowserWindow({
width: 1000,
height: 800,
icon: iconPath,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false
}
});
win.setMenu(null);
electron.globalShortcut.register('Control+Shift+I', () => {
if (win) win.webContents.openDevTools();
});
electron.ipcMain.on('electron-environment', (event) => event.returnValue = env);
win.loadURL(env.url);
win.on('closed', () => win = null);
}
electron.app.on('ready', createWindow);
electron.app.on('activate', () => { if(win === null) createWindow(); });

3
src/preload.js Normal file
View File

@@ -0,0 +1,3 @@
const {contextBridge, ipcRenderer} = require('electron');
contextBridge.exposeInMainWorld('electronEnvironment', () => ipcRenderer.sendSync('electron-environment'));