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

adding a keyboard shortcut to use last used login #234

Open
wants to merge 1 commit into
base: master
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
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