Skip to content

Commit ac5032f

Browse files
committed
Revert cdc0524 and instead allow customizing enabled shortcuts (closes #223, closes #234)
1 parent cdc0524 commit ac5032f

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

native/userchrome/profile/chrome/pwa/chrome.jsm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class ChromeLoader {
4040
static PREF_ENABLE_TABS_MODE = 'firefoxpwa.enableTabsMode';
4141
static PREF_ENABLE_HIDING_ICON_BAR = 'firefoxpwa.enableHidingIconBar';
4242
static PREF_ALLOWED_DOMAINS = 'firefoxpwa.allowedDomains';
43+
static PREF_SHORTCUTS_CLOSE_TAB = 'firefoxpwa.shortcuts.closeTab';
44+
static PREF_SHORTCUTS_CLOSE_WINDOW = 'firefoxpwa.shortcuts.closeWindow';
45+
static PREF_SHORTCUTS_QUIT_APPLICATION = 'firefoxpwa.shortcuts.quitApplication';
46+
static PREF_SHORTCUTS_PRIVATE_BROWSING = 'firefoxpwa.shortcuts.privateBrowsing';
4347

4448
static INITIALIZED_BROWSER = false;
4549
static INITIALIZED_PREFERENCES = false;

native/userchrome/profile/chrome/pwa/content/browser.jsm

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class PwaBrowser {
3535
this.handleRegisteringProtocols();
3636
this.handleOutOfScopeNavigation();
3737
this.handleOpeningNewWindow();
38+
this.handleDisablingShortcuts();
3839
setTimeout(() => { this.handleHiddenTitlebar() });
3940
setTimeout(() => { this.handleTabsMode() });
4041
setTimeout(() => { this.handleLinkTargets() });
@@ -456,6 +457,14 @@ class PwaBrowser {
456457
});
457458
}
458459

460+
handleDisablingShortcuts () {
461+
const getPref = (pref) => xPref.get(pref, false, true);
462+
if (!getPref(ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB)) document.getElementById('key_close').remove();
463+
if (!getPref(ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW)) document.getElementById('key_closeWindow').remove();
464+
if (!getPref(ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION)) document.getElementById('key_quitApplication').remove();
465+
if (!getPref(ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING)) document.getElementById('key_privatebrowsing').remove();
466+
}
467+
459468
handleHiddenTitlebar () {
460469
// This can be unstable feature and is only meant for tiling window manager users
461470
// So it is disabled by default and can be enabled using about:config preference
@@ -705,11 +714,10 @@ class PwaBrowser {
705714
}
706715

707716
disableNewTabShortcuts () {
708-
// New tab and close tab shortcuts are useless when tabs mode is disabled
717+
// New tab shortcuts are useless when the tabs mode is disabled
709718
if (!xPref.get(ChromeLoader.PREF_ENABLE_TABS_MODE)) {
710719
document.getElementById('cmd_newNavigatorTab').remove();
711720
document.getElementById('cmd_newNavigatorTabNoEvent').remove();
712-
document.getElementById('key_close').remove();
713721
}
714722
}
715723

@@ -1738,6 +1746,12 @@ class PwaBrowser {
17381746
// Determines which domains should always be allowed to open in the PWA browser
17391747
// This is a comma-separated list of domains
17401748
xPref.set(ChromeLoader.PREF_ALLOWED_DOMAINS, '', true);
1749+
1750+
// Determines whether specific shortcuts are enabled or not
1751+
xPref.set(ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB, true, true);
1752+
xPref.set(ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW, true, true);
1753+
xPref.set(ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION, true, true);
1754+
xPref.set(ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING, true, true);
17411755
}
17421756

17431757
disableOnboarding () {

native/userchrome/profile/chrome/pwa/content/preferences.jsm

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ class PwaPreferences {
2828
{ id: ChromeLoader.PREF_OPEN_IN_EXISTING_WINDOW, type: 'bool' },
2929
{ id: ChromeLoader.PREF_ENABLE_TABS_MODE, type: 'bool' },
3030
{ id: ChromeLoader.PREF_ALLOWED_DOMAINS, type: 'wstring' },
31+
{ id: ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB, type: 'bool' },
32+
{ id: ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW, type: 'bool' },
33+
{ id: ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION, type: 'bool' },
34+
{ id: ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING, type: 'bool' },
3135
]);
3236
}
3337

3438
addPreferenceElements () {
35-
const group = MozXULElement.parseXULToFragment(`
39+
const firefoxpwaGroup = MozXULElement.parseXULToFragment(`
3640
<groupbox id="firefoxpwaGroup" data-category="paneGeneral">
3741
<label>
3842
<html:h2>Progressive Web Apps</html:h2>
@@ -93,11 +97,28 @@ class PwaPreferences {
9397
</vbox>
9498
</vbox>
9599
</groupbox>
96-
`);
100+
`).firstChild;
101+
102+
const shortcutsGroup = MozXULElement.parseXULToFragment(`
103+
<groupbox id="shortcutsGroup" data-category="paneGeneral">
104+
<label>
105+
<html:h2>Keyboard Shortcuts</html:h2>
106+
<description>You may need to restart the browser to apply these settings</description>
107+
</label>
108+
<vbox id="colorsBox" style="padding-top: 1rem;">
109+
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB}" label="Close tab (Ctrl+W)" />
110+
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW}" label="Close window (Ctrl+Shift+W)" />
111+
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION}" label="Quit application (Ctrl+Shift+Q)" />
112+
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING}" label="Private browsing (Ctrl+Shift+P)" />
113+
</vbox>
114+
</groupbox>
115+
`).firstChild;
97116

98117
const startupGroup = document.getElementById('startupGroup');
99-
if (startupGroup.hidden) group.firstChild.hidden = true;
100-
startupGroup.nextElementSibling.after(group.firstChild);
118+
if (startupGroup.hidden) firefoxpwaGroup.hidden = true;
119+
if (startupGroup.hidden) shortcutsGroup.hidden = true;
120+
startupGroup.nextElementSibling.after(firefoxpwaGroup);
121+
startupGroup.nextElementSibling.nextElementSibling.after(shortcutsGroup);
101122
}
102123

103124
handleOutOfScopePreferenceSwitch () {

0 commit comments

Comments
 (0)