Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a progress indication to main window when another window is being opened #1164

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
33 changes: 33 additions & 0 deletions __tests__/__main__/main-window.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getLeaveByInterval,
getMainWindow,
resetMainWindow,
toggleMainWindowWait,
triggerStartupDialogs
} from '../../js/main-window.mjs';

Expand Down Expand Up @@ -442,6 +443,38 @@ describe('main-window.mjs', () =>
});
});

describe('toggleMainWindowWait()', () =>
{
it('Starts without wait class', () =>
{
createWindow();
const mainWindow = getMainWindow();
mainWindow.webContents.ipc.on(IpcConstants.WindowReadyToShow, async() =>
{
const hasClass = await mainWindow.webContents.executeJavaScript('$("html").hasClass("wait")');
assert.strictEqual(hasClass, false, 'Starts without wait class');
});
});

it('Toggling wait state for the window', () =>
{
createWindow();
const mainWindow = getMainWindow();
mainWindow.webContents.ipc.on(IpcConstants.WindowReadyToShow, async() =>
{
toggleMainWindowWait(true);
await new Promise(r => setTimeout(r, 50));
let hasClass = await mainWindow.webContents.executeJavaScript('$("html").hasClass("wait")');
assert.strictEqual(hasClass, true, 'Now has wait class');

toggleMainWindowWait(false);
await new Promise(r => setTimeout(r, 50));
hasClass = await mainWindow.webContents.executeJavaScript('$("html").hasClass("wait")');
assert.strictEqual(hasClass, false, 'Back to not having wait class');
});
});
});

afterEach(() =>
{
resetMainWindow();
Expand Down
17 changes: 17 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ body {
}
}

html.wait {
cursor: wait;
transition: 0.4s;
}

html[data-theme="dark"].wait {
filter: opacity(0.95);
}

html[data-theme="cadent-star"].wait {
filter: opacity(0.75);
}

html[data-theme="light"].wait {
filter: brightness(0.75);
}

.dayheader {
text-align: center;
}
Expand Down
1 change: 1 addition & 0 deletions js/ipc-constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const IpcConstants = Object.freeze(
ShowDialogSync: 'SHOW_DIALOG_SYNC',
ShowDialog: 'SHOW_DIALOG',
SwitchView: 'SWITCH_VIEW',
ToggleMainWindowWait: 'TOGGLE_MAIN_WINDOW_WAIT',
ToggleTrayPunchTime: 'TOGGLE_TRAY_PUNCH_TIME',
WaiverSaved: 'WAIVER_SAVED',
WindowReadyToShow: 'WINDOW_READY_TO_SHOW',
Expand Down
11 changes: 11 additions & 0 deletions js/main-window.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ function createWindow()
});
}

/**
* Toggles the main window style to indicate an operation is processing
*
* @param {Boolean} enable Enable or not the style
*/
function toggleMainWindowWait(enable)
{
getMainWindow()?.webContents.send(IpcConstants.ToggleMainWindowWait, enable);
}

function triggerStartupDialogs()
{
if (UpdateManager.shouldCheckForUpdates())
Expand Down Expand Up @@ -215,5 +225,6 @@ export {
getLeaveByInterval,
getMainWindow,
resetMainWindow,
toggleMainWindowWait,
triggerStartupDialogs,
};
5 changes: 5 additions & 0 deletions js/windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';

import { appConfig, rootDir } from './app-config.mjs';
import { getDateStr } from './date-aux.mjs';
import { toggleMainWindowWait } from './main-window.mjs';
import { getSavedPreferences } from './saved-preferences.mjs';
import { getUserPreferences, savePreferences } from './user-preferences.mjs';
import IpcConstants from './ipc-constants.mjs';
Expand Down Expand Up @@ -54,6 +55,7 @@ class Windows
global.waiverWindow.loadURL(htmlPath);
global.waiverWindow.webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
toggleMainWindowWait(false /*enable*/);
global.waiverWindow.show();
});
global.waiverWindow.on('close', function()
Expand All @@ -68,6 +70,7 @@ class Windows
BrowserWindow.getFocusedWindow().webContents.toggleDevTools();
}
});
toggleMainWindowWait(true /*enable*/);
}

static openPreferencesWindow(mainWindow)
Expand Down Expand Up @@ -102,6 +105,7 @@ class Windows
global.prefWindow.loadURL(htmlPath);
global.prefWindow.webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
toggleMainWindowWait(false /*enable*/);
global.prefWindow.show();
});
global.prefWindow.on('close', function()
Expand All @@ -121,6 +125,7 @@ class Windows
BrowserWindow.getFocusedWindow().webContents.toggleDevTools();
}
});
toggleMainWindowWait(true /*enable*/);
}

/**
Expand Down
1 change: 1 addition & 0 deletions renderer/preload-scripts/calendar-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const calendarApi = {
handlePunchDate: (callback) => ipcRenderer.on(IpcConstants.PunchDate, callback),
handleThemeChange: (callback) => ipcRenderer.on(IpcConstants.ReloadTheme, callback),
handleLeaveBy: (callback) => ipcRenderer.on(IpcConstants.GetLeaveBy, callback),
handleToggleMainWindowWait: (callback) => ipcRenderer.on(IpcConstants.ToggleMainWindowWait, callback),
resizeMainWindow: () => resizeMainWindow(),
switchView: () => switchView(),
toggleTrayPunchTime: (enable) => toggleTrayPunchTime(enable),
Expand Down
20 changes: 20 additions & 0 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@
*/
window.calendarApi.handleLeaveBy(searchLeaveByElement);

/*
* Change the main window style to indicate an operation is processing.
*/
window.calendarApi.handleToggleMainWindowWait((event, enable) =>
{
console.log(enable);
const waitClass = 'wait';
if (enable)
{
if (!$('html').hasClass(waitClass))
{
$('html').addClass(waitClass);
}
}
else
{
$('html').removeClass(waitClass);
}
});

Check warning on line 92 in src/calendar.js

View check run for this annotation

Codecov / codecov/patch

src/calendar.js#L73-L92

Added lines #L73 - L92 were not covered by tests
// On page load, create the calendar and setup notification
$(() =>
{
Expand Down