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

DevTools shortcut on Preferences and Waiver windows #254

Merged
merged 4 commits into from
Jun 4, 2020
Merged
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
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
- Fix: [#252] Prevent multiple preferences and workday waiver windows to be opened
- Enhancement: [#228] Improved performance of TTL - Now moving through the calendar is much faster
- Enhancement: [#152] Adding a "Copy" option in the "About message", making it easier to copy information when opening an issue
- Enhancement: [#245] DevTools shortcut on Preferences and Waiver windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash this changelog commit with the first one? I think it also would be useful to say something like:

Suggested change
- Enhancement: [#245] DevTools shortcut on Preferences and Waiver windows
- Enhancement: [#245] DevTools shortcut (Ctrl+Shift+I) on Preferences and Waiver windows

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean not having a separate commit for the changelog?
When accepting the merge request are you not able to squash them on demand? (real question, I've never accepted one hahaha)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I mean, you're basically changing the changelog (duh ahah) because of the first commit, so it should go together with it.

We can either squash them all together or have them all separate via the GitHub interface. We can squash portions using the CLI

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the changelog directly in master after merging the PR by mistake. (sorry again)

- Enhancement: [#247] Day View - new minimalist view that shows the calendar day by day
- Enhancement: [#245] DevTools shortcut on Preferences and Waiver windows
- Upgrade: Upgrading jquery to 3.5.0
- Upgrade: [#236] Upgrade all dependencies

44 changes: 44 additions & 0 deletions js/window-aux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { remote } = require('electron');
const { BrowserWindow, dialog } = remote;

/**
* Binds to the JS "window" the shortcut CTRL+SHIFT+I to toggle Chrome Dev Tools.
* @param {Window} window
*/
function bindDevToolsShortcut(window) {
window.addEventListener('keyup', (event) => {
if (event.ctrlKey && event.shiftKey && (event.keyCode == 73 || event.keyCode == 105)) { // 'i' or 'I'
BrowserWindow.getFocusedWindow().webContents.toggleDevTools();
event.preventDefault();
return false;
}
}, true);
}

/**
* Opens an electron dialog, based on the options, and performs the successCallback after promise is resolved.
* @param {Object.<string, any>} options
* @param {function} successCallback
*/
function showDialog(options, successCallback) {
options['title'] = options['title'] || 'Time to Leave';
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options).then(successCallback);
araujoarthur0 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Opens an electron dialog just like a JS alert().
* @param {string} message
*/
function showAlert(message) {
let options = {
'title': 'Time to Leave',
'message': message
};
dialog.showMessageBoxSync(BrowserWindow.getFocusedWindow(), options);
}

module.exports = {
bindDevToolsShortcut,
showAlert,
showDialog
};
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function createWindow() {
resizable: true,
icon: iconpath,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true
} });
waiverWindow.setMenu(null);
Expand Down Expand Up @@ -202,6 +203,7 @@ function createWindow() {
resizable: true,
icon: iconpath,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true
} });
prefWindow.setMenu(null);
Expand Down
3 changes: 3 additions & 0 deletions src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { ipcRenderer } = require('electron');

const { getUserPreferences } = require('../js/user-preferences.js');
const { applyTheme } = require('../js/themes.js');
const { bindDevToolsShortcut } = require('../js/window-aux.js');

// Global values for preferences page
let usersStyles = getUserPreferences();
Expand Down Expand Up @@ -75,4 +76,6 @@ $(() => {
repetition.change(function() {
notificationsInterval.prop('disabled', !repetition.is(':checked'));
});

bindDevToolsShortcut(window);
});
2 changes: 1 addition & 1 deletion src/workday-waiver.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</tbody>
</table>
<br>
<button class="waive-button" id="waive-button">
<button class="waive-button" id="waive-button" type="button">
Waive
</button>
</form>
Expand Down
44 changes: 16 additions & 28 deletions src/workday-waiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { getUserPreferences, showDay } = require('../js/user-preferences.js');
const { validateTime, diffDays } = require('../js/time-math.js');
const { applyTheme } = require('../js/themes.js');
const { getDateStr } = require('../js/date-aux.js');
const { bindDevToolsShortcut, showAlert, showDialog } = require('../js/window-aux.js');

const waiverStore = new Store({name: 'waived-workdays'});

Expand Down Expand Up @@ -74,13 +75,8 @@ function addWaiver() {

let diff = diffDays(startDate, endDate);
if (diff < 0) {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(),
{
message: 'End date cannot be less than start date.'
}
).then(() => {
return;
});
showAlert('End date cannot be less than start date.');
return;
}

let tempDate = new Date(startDate);
Expand All @@ -90,26 +86,16 @@ function addWaiver() {
let [tempYear, tempMonth, tempDay] = getDateFromISOStr(tempDateStr);
noWorkingDaysOnRange &= !showDay(tempYear, tempMonth-1, tempDay) && !waiverStore.has(tempDateStr);
if (waiverStore.has(tempDateStr)) {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(),
{
message: `You already have a waiver on ${tempDateStr}. Remove it before adding a new one.`
}
).then(() => {
return;
});
showAlert(`You already have a waiver on ${temp_date_str}. Remove it before adding a new one.`);
return;
}

tempDate.setDate(tempDate.getDate() + 1);
}

if (noWorkingDaysOnRange) {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(),
{
message: 'Cannot add waiver. Range does not contain any working day.'
}
).then(() => {
return;
});
showAlert('Cannot add waiver. Range does not contain any working day.');
return;
}

tempDate = new Date(startDate);
Expand All @@ -134,13 +120,13 @@ function deleteEntryOnClick(event) {
let deleteButton = $(event.target);
let day = deleteButton.data('day');

dialog.showMessageBox(BrowserWindow.getFocusedWindow(),
{
title: 'Time to Leave',
message: 'Are you sure you want to delete waiver on day ' + day + '?',
type: 'info',
buttons: ['Yes', 'No']
}).then((result) => {
let options = {
title: 'Time to Leave',
message: `Are you sure you want to delete waiver on day ${day} ?`,
type: 'info',
buttons: ['Yes', 'No']
};
showDialog(options, (result) => {
const buttonId = result.response;
if (buttonId === 1) {
return;
Expand Down Expand Up @@ -169,4 +155,6 @@ $(() => {
$('#waive-button').on('click', () => {
addWaiver();
});

bindDevToolsShortcut(window);
});