Move to npm for development and packaging

I had to hack the package.json to force `electron-prebuilt` to use a 32-bit binary - everything else should be fairly out of the box
This commit is contained in:
CakeLancelot 2021-04-28 12:37:22 -05:00
parent f321ebdf56
commit 5d5dce9647
68 changed files with 3729 additions and 8 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
npm_config_arch=ia32

View File

Before

Width:  |  Height:  |  Size: 692 KiB

After

Width:  |  Height:  |  Size: 692 KiB

View File

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 141 KiB

View File

Before

Width:  |  Height:  |  Size: 829 KiB

After

Width:  |  Height:  |  Size: 829 KiB

View File

Before

Width:  |  Height:  |  Size: 123 B

After

Width:  |  Height:  |  Size: 123 B

View File

Before

Width:  |  Height:  |  Size: 123 B

After

Width:  |  Height:  |  Size: 123 B

View File

Before

Width:  |  Height:  |  Size: 123 B

After

Width:  |  Height:  |  Size: 123 B

View File

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 176 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 722 KiB

After

Width:  |  Height:  |  Size: 722 KiB

BIN
build/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

View File

@ -9,6 +9,76 @@ var mainWindow = null;
app.commandLine.appendSwitch('--enable-npapi');
// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
function handleSquirrelEvent() {
"use strict"
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;
}
};
// Node version is too old to have a built-in function
function copyFile(src, dst) {
fs.createReadStream(src).pipe(fs.createWriteStream(dst));
@ -23,9 +93,9 @@ function initialSetup() {
child.on('exit', function() {
console.log("Unity installed.");
// Copy over files with default values
copyFile(__dirname+"\\default_config.json", app.getPath('userData')+"\\config.json");
copyFile(__dirname+"\\default_servers.json", app.getPath('userData')+"\\servers.json");
copyFile(__dirname+"\\default_versions.json", app.getPath('userData')+"\\versions.json");
copyFile(__dirname+"\\defaults\\config.json", app.getPath('userData')+"\\config.json");
copyFile(__dirname+"\\default\\servers.json", app.getPath('userData')+"\\servers.json");
copyFile(__dirname+"\\default\\versions.json", app.getPath('userData')+"\\versions.json");
console.log("JSON files copied.");
setupWindow.destroy();
showMainWindow();
@ -94,5 +164,15 @@ function showMainWindow() {
mainWindow.webContents.executeJavaScript("loadServerList();");
});
mainWindow.webContents.on('plugin-crashed', function() {
console.log("Unity Web Player crashed.");
});
mainWindow.webContents.on('will-navigate', function(evt, url) {
evt.preventDefault();
console.log(url);
});
//mainWindow.webContents.openDevTools()
}

3587
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

45
package.json Normal file
View File

@ -0,0 +1,45 @@
{
"name": "openfusionclient",
"version": "1.3.1",
"description": "OpenFusionClient",
"main": "index.js",
"scripts": {
"postinstall": "npx patch-package && npm explore electron-prebuilt -- npm run postinstall",
"start": "electron .",
"build": "node build.js",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"author": "OpenFusion Contributors",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "^0.31.2",
"patch-package": "^6.4.7",
"electron-builder": "^22.10.5"
},
"build": {
"appId": "xyz.openfusion.client",
"productName": "OpenFusionClient",
"copyright": "© 2020-2021 OpenFusion Contributors",
"electronDownload": {
"version": "0.31.2",
"platform": "win32",
"arch": "ia32"
},
"electronVersion": "0.31.2",
"win": {
"asar": false
},
"files": [
"!patches${/*}",
"!default_app${/*}",
"!.npmrc"
],
"extraFiles": [
{
"from": "build/utils",
"to": "utils"
}
]
}
}

View File

@ -0,0 +1,13 @@
diff --git a/node_modules/electron-prebuilt/install.js b/node_modules/electron-prebuilt/install.js
index 3261c69..3fcb876 100644
--- a/node_modules/electron-prebuilt/install.js
+++ b/node_modules/electron-prebuilt/install.js
@@ -24,7 +24,7 @@ var paths = {
if (!paths[platform]) throw new Error('Unknown platform: ' + platform)
// downloads if not cached
-download({version: version}, extractFile)
+download({version: version, arch: 'ia32', platform: 'win32'}, extractFile)
// unzips and makes path.txt point at the correct executable
function extractFile (err, zipPath) {

View File

@ -1,5 +0,0 @@
{
"name" : "OpenFusionClient",
"version" : "1.3.0",
"main" : "index.js"
}

Binary file not shown.