Skip to content

Commit

Permalink
Move debug mode check to whewnready function
Browse files Browse the repository at this point in the history
Installation prompt comes after download and gives option to install immediately, or on exit.

Fixed a bug in progress tracker
  • Loading branch information
Mattk70 committed Oct 16, 2023
1 parent 6a9ce16 commit 6475f10
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 45 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,11 @@ <h5>Saved Records</h5>
<div class="col pe-0">
<div class="form-group rounded p-2 mb-2 text-bg-danger">
<span class="circle me-2"
title="Enter debug mode (requires Chirpity restart)">?</span>
title="Enter debug mode (requires Chirpity relaunch)">?</span>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox"
role="switch" id="debug-mode">
<label class="form-check-label" for="debug-mode">Debug mode (requires application restart)</label>
<label class="form-check-label" for="debug-mode">Debug mode (requires application relaunch)</label>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let seenTheDarkness = false, shownDaylightBanner = false, LOCATIONS, locationID = undefined;
const load0 = Date.now()
let labels = [];

const STATE = {
Expand Down Expand Up @@ -1365,6 +1364,7 @@ window.onload = async () => {
}
// switch off fullscreen mode - we don't want to persist that setting
config.fullscreen = false;
// switch off debug mode we don't want this to be remembered
// Initialize Spectrogram
initWavesurfer({});
// Set UI option state
Expand Down
77 changes: 38 additions & 39 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,66 +47,50 @@ log.info('App starting...');


autoUpdater.on('checking-for-update', function () {
sendStatusToWindow('Checking for update...');
logUpdateStatus('Checking for update...');
});

autoUpdater.on('update-available', async function (info) {
// Fetch release notes from GitHub API
const releaseNotes = await fetchReleaseNotes(info.version);
log.info(JSON.stringify(info))
// Display dialog to the user with release notes
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: `A new version (${info.version}) is available.\n\nRelease Notes:\n${releaseNotes}\n\nDo you want to install it now?`,
buttons: ['Yes', 'No']
}).then((result) => {
if (result.response === 0) {
// User clicked 'Yes', start the download
autoUpdater.downloadUpdate();
}
});
autoUpdater.downloadUpdate();
});

autoUpdater.on('update-not-available', function (info) {
sendStatusToWindow('Update not available.');
logUpdateStatus('Update not available.');
});

autoUpdater.on('error', function (err) {
sendStatusToWindow('Error in auto-updater.');
logUpdateStatus('Error in auto-updater.');
});

autoUpdater.on('download-progress', function (progressObj) {
mainWindow.webContents.send('download-progress', progressObj);
});


autoUpdater.on('update-downloaded', function (info) {
autoUpdater.on('update-downloaded', async function (info) {
// Fetch release notes from GitHub API
const releaseNotes = await fetchReleaseNotes(info.version);
log.info(JSON.stringify(info))
// Display dialog to the user with release notes
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: `A new version (${info.version}) is available.\n\nRelease Notes:\n${releaseNotes}\n\nDo you want to install it now?`,
buttons: ['Now', 'Install on Exit'],
defaultId: 1,
noLink: true
}).then((result) => {
if (result.response === 0) {
// User clicked 'Yes', start the download
autoUpdater.quitAndInstall();
}
});
});

function sendStatusToWindow(message) {
function logUpdateStatus(message) {
console.log(message);
}

// Debug mode
try {
// Specify the file path
const filePath = path.join(app.getPath('userData'), 'config.json');

// Read the contents of the file synchronously
const fileContent = fs.readFileSync(filePath, 'utf-8');
const config = JSON.parse(fileContent);
DEBUG = config.debug;
}
catch (error) {
// Handle errors, for example, file not found
console.error('Error reading file:', error.message);
}





process.stdin.resume();//so the program will not close instantly

Expand Down Expand Up @@ -165,6 +149,7 @@ async function exitHandler(options, exitCode) {
});
});
});
// Disable debug mode here?
} else {
console.log('no clean')

Expand Down Expand Up @@ -315,13 +300,27 @@ async function createWorker() {
console.log("worker created");
}

// This method will be called when Electron has finished
// This method will be called when Electron has finished loading
app.whenReady().then(async () => {
ipcMain.handle('getPath', () => app.getPath('userData'));
ipcMain.handle('getTemp', () => app.getPath('temp'));
ipcMain.handle('getVersion', () => app.getVersion());
ipcMain.handle('getAudio', () => path.join(__dirname.replace('app.asar', ''), 'Help', 'example.mp3'));

// Debug mode
try {
// Specify the file path
const filePath = path.join(app.getPath('userData'), 'config.json');

// Read the contents of the file synchronously
const fileContent = fs.readFileSync(filePath, 'utf-8');
const config = JSON.parse(fileContent);
DEBUG = config.debug;
}
catch (error) {
// Handle errors, for example, file not found
console.error('Error reading file:', error.message);
}
await createWorker();
await createWindow();

Expand Down
6 changes: 3 additions & 3 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ contextBridge.exposeInMainWorld('module', {
window.addEventListener('DOMContentLoaded', () => {
const tracking = document.getElementById('update-progress');
const updateProgressBar = document.getElementById('update-progress-bar');
ipcRenderer.on('download-progress', (_event, value) => {
console.log(value); // Log the message to the console
ipcRenderer.on('download-progress', (_event, progressObj) => {
console.log(progressObj.percent); // Log the message to the console
tracking.classList.remove('d-none')
// Update your UI with the progress information
updateProgressBar.value = value;
updateProgressBar.value = progressObj.percent;
// Hide progress when done
if (progressObj.percent > 99) tracking.classList.add('d-none')
});
Expand Down

0 comments on commit 6475f10

Please sign in to comment.