Skip to content

Commit

Permalink
Add build hooks and allow for win on arm autoupdating
Browse files Browse the repository at this point in the history
  • Loading branch information
tazzben committed Aug 30, 2024
1 parent 74661b9 commit e7a7b6c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 49 deletions.
67 changes: 65 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { sign } = require('crypto');
const os = require('os');
const path = require('path');
const fs = require('fs');

require('dotenv').config({
path: path.join(os.homedir(), ".env")
Expand Down Expand Up @@ -38,7 +38,70 @@ let baseConfig = {
"darwin"
]
},
]
],
hooks: {
postMake: async (config, makeResults) => {
let fileRenameList = [];
for (const result of makeResults) {
for (const artifact of result.artifacts) {
const dirname = path.dirname(artifact);
const filename = path.basename(artifact);
let newFilename = filename.replace(/\s/, "_");
if(!(newFilename.includes(result.arch))){
const dashIndex = newFilename.indexOf("-");
if (dashIndex !== -1) {
newFilename = newFilename.substring(0, dashIndex) + "-" + result.arch + newFilename.substring(dashIndex);
}
}
if (!(newFilename.includes(result.platform))) {
const archIndex = newFilename.indexOf(result.arch);
if (archIndex !== -1) {
newFilename = newFilename.substring(0, archIndex) + result.platform + "-" + newFilename.substring(archIndex);
}
}
const newArtifact = path.join(dirname, newFilename);
fileRenameList.push({
artifact,
newArtifact,
arch: result.arch,
platform: result.platform
});
if (artifact !== newArtifact){
fs.renameSync(artifact, newArtifact);
}
}
}
let releaseFileList = [];
for (const fileRename of fileRenameList) {
if (path.basename(fileRename.newArtifact) == "RELEASES") {
let releaseFile = fs.readFileSync(fileRename.newArtifact, 'utf8');
const filFileRenameList = fileRenameList.filter(fR => fR.arch == fileRename.arch && fR.platform == fileRename.platform);
for (const fR of filFileRenameList){
if (fR.artifact != fR.newArtifact){
releaseFile = releaseFile.replace(path.basename(fR.artifact), path.basename(fR.newArtifact));
}
}
releaseFileList.push({
artifact: fileRename.newArtifact,
content: releaseFile,
arch: fileRename.arch,
platform: fileRename.platform
});
fs.writeFileSync(fileRename.newArtifact, releaseFile);
}
}
if (releaseFileList.length > 0){
const releaseContent = releaseFileList.map(file => file.content).join("\n");
const releaseFilePath = path.join(path.dirname(releaseFileList[0].artifact), "..", "RELEASES");
fs.writeFileSync(releaseFilePath, releaseContent);
}
const filteredFileRenameList = fileRenameList.filter(fR => path.basename(fR.newArtifact) != "RELEASES");
for (const fR of filteredFileRenameList){
const newLocation = path.join(path.dirname(fR.newArtifact), "..", path.basename(fR.newArtifact));
fs.renameSync(fR.newArtifact, newLocation);
}
}
}
};

module.exports = baseConfig;
45 changes: 9 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "assessment-disaggregation",
"productName": "Assessment Disaggregation",
"version": "1.6.3",
"version": "1.6.4",
"description": "Measure learning using a scientifically validated method using pretest and posttest files. The software automatically reads most exam output files (Akindi, Scantron, Canvas, ZipGrade, Moodle, Google Form quizzes) without modification.",
"main": "src/main.js",
"repository": {
Expand Down Expand Up @@ -31,8 +31,7 @@
"dotenv": "^16.4.5",
"electron-settings": "^4.0.4",
"electron-squirrel-startup": "^1.0.1",
"remove-bom-stream": "^2.0.0",
"update-electron-app": "^3.0.0"
"remove-bom-stream": "^2.0.0"
},
"devDependencies": {
"@electron-forge/cli": "^7.4.0",
Expand Down
20 changes: 12 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ const {
Menu,
dialog,
shell,
TouchBar
TouchBar,
autoUpdater
} = require('electron');
const os = require('os');
const {
TouchBarButton,
TouchBarSpacer
} = TouchBar;

if (require('electron-squirrel-startup')) app.quit();

// Disable the auto-updated for Windows on ARM

if (process.platform === 'darwin' || (process.platform === 'win32' && os.arch() === 'x64')) {
const { updateElectronApp } = require('update-electron-app');
updateElectronApp();
}
const autoUpdate = () => {
if (!(app.isPackaged)){
return;
}
const server = 'https://update.electronjs.org';
const feed = `${server}/tazzben/Assessment-Disaggregation/${process.platform}-${process.arch}/${app.getVersion()}`;
autoUpdater.setFeedURL(feed);
autoUpdater.checkForUpdates();
};

let settings = require('electron-settings');

Expand Down Expand Up @@ -140,6 +143,7 @@ const createWindow = () => {

mainWindow.once('ready-to-show', () => {
mainWindow.show();
autoUpdate();
});

mainWindow.webContents.once('dom-ready', () => {
Expand Down

0 comments on commit e7a7b6c

Please sign in to comment.