Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
out
dist
puppeteer
puppeteer
release-builds
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/icons/.DS_Store
Binary file not shown.
Binary file added assets/icons/mac/icon.icns
Binary file not shown.
Binary file added assets/icons/png/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/win/icon.ico
Binary file not shown.
Binary file added installers/.DS_Store
Binary file not shown.
65 changes: 65 additions & 0 deletions installers/setupEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const electron = require('electron')
const app = electron.app

module.exports = {
handleSquirrelEvent: function() {
if (process.argv.length === 1) {
return false;
}

const ChildProcess = require('child_process');
const path = require('path');

const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);
const spawn = function(command, args) {
let spawnedProcess, error;

try {
spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
} catch (error) {}

return spawnedProcess;
};

const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};

const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus

// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);

setTimeout(app.quit, 1000);
return true;

case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers

// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);

setTimeout(app.quit, 1000);
return true;

case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated

app.quit();
return true;
}
}
}
25 changes: 25 additions & 0 deletions installers/windows/createinstaller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
const path = require('path')

getInstallerConfig()
.then(createWindowsInstaller)
.catch((error) => {
console.error(error.message || error)
process.exit(1)
})

function getInstallerConfig () {
console.log('creating windows installer')
const rootPath = path.join('./')
const outPath = path.join(rootPath, 'release-builds')

return Promise.resolve({
appDirectory: path.join(outPath, 'timetable-grabber-sit-win32-ia32/'),
authors: 'Brandon Lim',
noMsi: true,
outputDirectory: path.join(outPath, 'windows-installer'),
exe: 'timetable-grabber-sit.exe',
setupExe: 'timetable-grabber-sit-installer.exe',
setupIcon: path.join(rootPath, 'assets', 'icons', 'win', 'icon.ico')
})
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"build": "tsc && tailwindcss -i ./src/common/common.css -o ./out/common/common.css"
"build": "tsc && tailwindcss -i ./src/common/common.css -o ./out/common/common.css",
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
"package-win": "electron-packager . timetable-grabber-sit --overwrite --asar --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"timetable-grabber-sit\"",
"package-linux": "electron-packager . timetable-grabber-sit --overwrite --asar --platform=linux --arch=x64 --icon=assets/icons/png/icon.png --prune=true --out=release-builds",
"create-installer-win": "node installers/windows/createinstaller.js"
},
"devDependencies": {
"@electron-forge/cli": "^6.4.1",
Expand All @@ -25,11 +29,14 @@
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"electron": "^21.3.1",
"electron": "^26.1.0",
"electron-winstaller": "^5.1.0",
"eslint": "^8.28.0",
"typescript": "^4.9.3"
},
"dependencies": {
"asar": "^3.2.0",
"electron-packager": "^17.1.2",
"electron-squirrel-startup": "^1.0.0",
"ics": "^2.41.0",
"postcss": "^8.0.9",
Expand Down
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import * as ics from "ics";
import * as fs from "fs";
import WebSocket from 'ws';

// Handle setupevents as quickly as possible
const setupEvents = require('./installers/setupEvents');
if (setupEvents.handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
process.exit(0);
}
// Example IPC communication
ipcMain.on('some-event', (event, data) => {
// Handle the received data
});
// Continue with the rest of your Electron code here



// Setup websocket for feedback on frontend.
// const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
Expand Down
Loading