Skip to content

Commit

Permalink
adding a keyboard shortcut to use last used login
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandimitrov8080 committed Feb 15, 2023
1 parent 1af409a commit d528513
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions manifests/chrome-manifest-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
"suggested_key": {
"default": "Ctrl+Shift+U"
}
},
"doLogin": {
"suggested_key": {
"default": "Ctrl+Shift+L"
},
"description": "Do Login"
}
},

Expand Down
23 changes: 23 additions & 0 deletions web-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function _processLoginTabMessage(entry, tab) {
if (response.username === urlDomain(tab.url)) {
throw new Error(i18n.getMessage('couldNotDetermineUsernameMessage'));
}
setLocalStorageKey(`${LAST_LOGIN_USED_PREFIX}${tab.url}`, entry);

return browser.tabs
.sendMessage(tab.id, {
Expand Down Expand Up @@ -212,8 +213,30 @@ function _resolveCurrentAuthRequest(result, senderUrl) {
}
}

function doInCurrentTab(tabCallback) {
chrome.tabs.query({ currentWindow: true, active: true }, function (tabArray) {
tabCallback(tabArray[0]);
});
}

function doLogin() {
doInCurrentTab(async (tab) => {
_processLoginTabMessage(await getLocalStorageKey(`${LAST_LOGIN_USED_PREFIX}${tab.url}`), tab);
});
}

function initCommands() {
const commandsMap = {
doLogin: doLogin,
};
chrome.commands.onCommand.addListener((command) => {
commandsMap[command]();
});
}

function initBackground() {
browser.runtime.onMessage.addListener(processMessageAndCatch);
initCommands();

browser.webRequest.onAuthRequired.addListener(
_onAuthRequired,
Expand Down
1 change: 1 addition & 0 deletions web-extension/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_SETTINGS = {

const LAST_DOMAIN_SEARCH_PREFIX = 'LAST_DOMAIN_SEARCH_';
const LAST_DETAIL_VIEW_PREFIX = 'LAST_DETAIL_VIEW_';
const LAST_LOGIN_USED_PREFIX = 'LAST_LOGIN_USED_';
const REQUIRED_GOPASS_VERSION = [1, 8, 5];

let versionOK = undefined;
Expand Down

0 comments on commit d528513

Please sign in to comment.