Skip to content

Commit 5738d47

Browse files
committed
enforceAutolock
1 parent a4cb6a6 commit 5738d47

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/background.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2525
message.info.windowWidth
2626
);
2727
} else if (message.action === "cachePassphrase") {
28-
document.cookie = `passphrase="${message.value}${getCookieExpiry()}"`;
2928
cachedPassphrase = message.value;
3029
clearTimeout(autolockTimeout);
3130
setAutolock();
@@ -405,25 +404,37 @@ chrome.commands.onCommand.addListener(async (command: string) => {
405404
}
406405
});
407406

408-
function setAutolock() {
407+
async function setAutolock() {
408+
const enforcedAutolock = Number(await ManagedStorage.get("enforceAutolock"));
409+
410+
if (enforcedAutolock) {
411+
if (enforcedAutolock > 0) {
412+
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry(
413+
enforcedAutolock
414+
)}"`;
415+
autolockTimeout = setTimeout(() => {
416+
cachedPassphrase = "";
417+
}, enforcedAutolock * 60000);
418+
return;
419+
}
420+
}
421+
409422
if (Number(localStorage.autolock) > 0) {
410-
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`;
423+
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry(
424+
Number(localStorage.autolock)
425+
)}"`;
411426
autolockTimeout = setTimeout(() => {
412427
cachedPassphrase = "";
413428
}, Number(localStorage.autolock) * 60000);
414429
}
415430
}
416431

417-
function getCookieExpiry() {
418-
if (localStorage.autolock && Number(localStorage.autolock) > 0) {
419-
const offset = Number(localStorage.autolock) * 60000;
420-
const now = new Date().getTime();
421-
const autolockExpiry = new Date(now + offset).toUTCString();
432+
function getCookieExpiry(time: number) {
433+
const offset = time * 60000;
434+
const now = new Date().getTime();
435+
const autolockExpiry = new Date(now + offset).toUTCString();
422436

423-
return `;expires=${autolockExpiry}`;
424-
} else {
425-
return "";
426-
}
437+
return `;expires=${autolockExpiry}`;
427438
}
428439

429440
function getCachedPassphrase() {

src/components/Popup/PrefrencesPage.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
min="0"
3333
style="width: 70px;"
3434
v-model="autolock"
35+
:disabled="Boolean(enforceAutolock)"
3536
/>
3637
<span style="margin-top: 10px;">{{ i18n.minutes }}</span>
3738
</div>
@@ -70,9 +71,16 @@ export default Vue.extend({
7071
encryption(): IEncryption {
7172
return this.$store.state.accounts.encryption;
7273
},
74+
enforceAutolock() {
75+
return this.$store.state.menu.enforceAutolock;
76+
},
7377
autolock: {
7478
get(): number {
75-
return this.$store.state.menu.autolock;
79+
if (this.$store.state.menu.enforceAutolock) {
80+
return this.$store.state.menu.enforceAutolock;
81+
} else {
82+
return this.$store.state.menu.autolock;
83+
}
7684
},
7785
set(autolock: number) {
7886
this.$store.commit("menu/setAutolock", autolock);

0 commit comments

Comments
 (0)