Skip to content

Commit

Permalink
releasing v1 for desktop with update
Browse files Browse the repository at this point in the history
  • Loading branch information
hannydevelop committed Dec 31, 2023
1 parent e07ce5b commit 08a0159
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 319 deletions.
15 changes: 10 additions & 5 deletions main/index.js

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

116 changes: 55 additions & 61 deletions main/updater.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
const autoUpdater = require('electron-updater');
const { autoUpdater } = require("electron-updater");
const { dialog, BrowserWindow, ipcMain } = require('electron');
const log = require('electron-log');

let downloadProgress;
log.transports.file.level = "debug";
autoUpdater.autoUpdater.logger = log;
autoUpdater.logger = log;

autoUpdater.autoUpdater.autoDownload = false;
autoUpdater.autoDownload = false;

autoUpdater.autoUpdater.setFeedURL({
autoUpdater.setFeedURL({
provider: "github",
owner: "hannydevelop",
repo: "peppubuild-desktop",
});

function check() {
autoUpdater.autoUpdater.checkForUpdates();

autoUpdater.autoUpdater.on('checking-for-update', () => {
const response = dialog.showMessageBox(null);
console.log(response);
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of app is available. Do you want to update now?',
buttons: ['Update', 'No']
}, (index) => {
if (index) {
return;
} else {
autoUpdater.autoUpdater.downloadUpdate();

let proWin = new BrowserWindow({
width: 350,
height: 35,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false,
title: 'Downloading Update'
});
proWin.loadURL(`file://$(__dirname)/progress`);

proWin.on('closed', () => {
proWin = null;
});

ipcMain.on('download-progress-request', (e) => {
e.returnValue = downloadProgress;
});

autoUpdater.autoUpdater.on('download-progress', (d) => {
downloadProgress = d.percent;
autoUpdater.autoUpdater.logger.info(downloadProgress);
});

autoUpdater.autoUpdater.on('update-downloaded', () => {
if (progressWindow) progressWindow.close();
autoUpdater.setFeedURL({
provider: "github",
owner: "hannydevelop",
repo: "peppubuild-desktop",
});

autoUpdater.on("checking-for-update", function (_arg1) {
return log.info("Checking for update...");
});
autoUpdater.on("update-available", function (_arg2) {
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of Peppubuild is available. Do you want to update now?',
buttons: ['Update', 'No']
}).then((response) => {
if (process.platform == "darwin" && response.response == 0) {
dialog.showMessageBox({
type: 'info',
title: 'Update Ready',
message: 'A new version of app is ready. Quit and Install now?',
buttons: ['Yes', 'Later']
}, (index) => {
if (!index) {
autoUpdater.autoUpdater.quitAndInstall();
}
});
});
}
type: 'error',
title: 'Auto Update Unsucessful',
message: 'Auto-update prohibited for MacOS. You can download latest version from https://github.com/hannydevelop/peppubuild-desktop/releases/latest ',
buttons: ['Okay']
})
} else if (response.response == 1) {
return
} else {
autoUpdater.downloadUpdate();
}
})
});
});
autoUpdater.on("update-not-available", function (_arg3) {
return log.info("Update not available.");
});
autoUpdater.on("error", function (err) {
return log.info("Error in auto-updater. " + err);
});
autoUpdater.on("download-progress", function (progressObj) {
return log.info("downloading update");
});
autoUpdater.on("update-downloaded", function (_arg4) {
if (progressWindow) progressWindow.close();

dialog.showMessageBox({
type: 'info',
title: 'Update Ready',
message: 'A new version of Peppubuild is ready. Quit and Install now?',
buttons: ['Yes', 'Later']
}, (index) => {
if (!index) {
autoUpdater.quitAndInstall();
}
});
});

}

module.exports.check = check;
Loading

0 comments on commit 08a0159

Please sign in to comment.