Skip to content

Commit

Permalink
Revert cdc0524 and instead allow customizing enabled shortcuts (closes
Browse files Browse the repository at this point in the history
…#223, closes #234)
  • Loading branch information
filips123 committed Oct 17, 2022
1 parent cdc0524 commit ac5032f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
4 changes: 4 additions & 0 deletions native/userchrome/profile/chrome/pwa/chrome.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class ChromeLoader {
static PREF_ENABLE_TABS_MODE = 'firefoxpwa.enableTabsMode';
static PREF_ENABLE_HIDING_ICON_BAR = 'firefoxpwa.enableHidingIconBar';
static PREF_ALLOWED_DOMAINS = 'firefoxpwa.allowedDomains';
static PREF_SHORTCUTS_CLOSE_TAB = 'firefoxpwa.shortcuts.closeTab';
static PREF_SHORTCUTS_CLOSE_WINDOW = 'firefoxpwa.shortcuts.closeWindow';
static PREF_SHORTCUTS_QUIT_APPLICATION = 'firefoxpwa.shortcuts.quitApplication';
static PREF_SHORTCUTS_PRIVATE_BROWSING = 'firefoxpwa.shortcuts.privateBrowsing';

static INITIALIZED_BROWSER = false;
static INITIALIZED_PREFERENCES = false;
Expand Down
18 changes: 16 additions & 2 deletions native/userchrome/profile/chrome/pwa/content/browser.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PwaBrowser {
this.handleRegisteringProtocols();
this.handleOutOfScopeNavigation();
this.handleOpeningNewWindow();
this.handleDisablingShortcuts();
setTimeout(() => { this.handleHiddenTitlebar() });
setTimeout(() => { this.handleTabsMode() });
setTimeout(() => { this.handleLinkTargets() });
Expand Down Expand Up @@ -456,6 +457,14 @@ class PwaBrowser {
});
}

handleDisablingShortcuts () {
const getPref = (pref) => xPref.get(pref, false, true);
if (!getPref(ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB)) document.getElementById('key_close').remove();
if (!getPref(ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW)) document.getElementById('key_closeWindow').remove();
if (!getPref(ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION)) document.getElementById('key_quitApplication').remove();
if (!getPref(ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING)) document.getElementById('key_privatebrowsing').remove();
}

handleHiddenTitlebar () {
// This can be unstable feature and is only meant for tiling window manager users
// So it is disabled by default and can be enabled using about:config preference
Expand Down Expand Up @@ -705,11 +714,10 @@ class PwaBrowser {
}

disableNewTabShortcuts () {
// New tab and close tab shortcuts are useless when tabs mode is disabled
// New tab shortcuts are useless when the tabs mode is disabled
if (!xPref.get(ChromeLoader.PREF_ENABLE_TABS_MODE)) {
document.getElementById('cmd_newNavigatorTab').remove();
document.getElementById('cmd_newNavigatorTabNoEvent').remove();
document.getElementById('key_close').remove();
}
}

Expand Down Expand Up @@ -1738,6 +1746,12 @@ class PwaBrowser {
// Determines which domains should always be allowed to open in the PWA browser
// This is a comma-separated list of domains
xPref.set(ChromeLoader.PREF_ALLOWED_DOMAINS, '', true);

// Determines whether specific shortcuts are enabled or not
xPref.set(ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB, true, true);
xPref.set(ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW, true, true);
xPref.set(ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION, true, true);
xPref.set(ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING, true, true);
}

disableOnboarding () {
Expand Down
29 changes: 25 additions & 4 deletions native/userchrome/profile/chrome/pwa/content/preferences.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ class PwaPreferences {
{ id: ChromeLoader.PREF_OPEN_IN_EXISTING_WINDOW, type: 'bool' },
{ id: ChromeLoader.PREF_ENABLE_TABS_MODE, type: 'bool' },
{ id: ChromeLoader.PREF_ALLOWED_DOMAINS, type: 'wstring' },
{ id: ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB, type: 'bool' },
{ id: ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW, type: 'bool' },
{ id: ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION, type: 'bool' },
{ id: ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING, type: 'bool' },
]);
}

addPreferenceElements () {
const group = MozXULElement.parseXULToFragment(`
const firefoxpwaGroup = MozXULElement.parseXULToFragment(`
<groupbox id="firefoxpwaGroup" data-category="paneGeneral">
<label>
<html:h2>Progressive Web Apps</html:h2>
Expand Down Expand Up @@ -93,11 +97,28 @@ class PwaPreferences {
</vbox>
</vbox>
</groupbox>
`);
`).firstChild;

const shortcutsGroup = MozXULElement.parseXULToFragment(`
<groupbox id="shortcutsGroup" data-category="paneGeneral">
<label>
<html:h2>Keyboard Shortcuts</html:h2>
<description>You may need to restart the browser to apply these settings</description>
</label>
<vbox id="colorsBox" style="padding-top: 1rem;">
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_CLOSE_TAB}" label="Close tab (Ctrl+W)" />
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_CLOSE_WINDOW}" label="Close window (Ctrl+Shift+W)" />
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_QUIT_APPLICATION}" label="Quit application (Ctrl+Shift+Q)" />
<checkbox preference="${ChromeLoader.PREF_SHORTCUTS_PRIVATE_BROWSING}" label="Private browsing (Ctrl+Shift+P)" />
</vbox>
</groupbox>
`).firstChild;

const startupGroup = document.getElementById('startupGroup');
if (startupGroup.hidden) group.firstChild.hidden = true;
startupGroup.nextElementSibling.after(group.firstChild);
if (startupGroup.hidden) firefoxpwaGroup.hidden = true;
if (startupGroup.hidden) shortcutsGroup.hidden = true;
startupGroup.nextElementSibling.after(firefoxpwaGroup);
startupGroup.nextElementSibling.nextElementSibling.after(shortcutsGroup);
}

handleOutOfScopePreferenceSwitch () {
Expand Down

0 comments on commit ac5032f

Please sign in to comment.