Skip to content

Commit

Permalink
Merge pull request #29 from asika32764/idle-timeout
Browse files Browse the repository at this point in the history
fix(idle): Stop listening Idle-Timeout if user signed-out and screen locked.
  • Loading branch information
asika32764 authored Jun 23, 2024
2 parents 3e7fa1c + 756c6ec commit de9b76a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import electronService from '@/service/electron-service';
import {
currentPlatform,
currentPlatforms, idleTimeoutEnabled, isElectron,
currentPlatforms, idleTimeoutEnabled, isElectron, isLock,
isLogin,
isNative, lockAtStartup,
} from '@/store/main-store';
Expand Down Expand Up @@ -50,7 +50,7 @@ router.isReady().then(async () => {

app.mount('#app');

if (idleTimeoutEnabled) {
if (isLogin.value && !isLock.value) {
lockScreenService.listenIdleTimeout();
}

Expand Down
3 changes: 3 additions & 0 deletions src/service/auth-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import apiClient from '@/service/api-client';
import { sodiumCipher } from '@/service/cipher';
import encryptionService from '@/service/encryption-service';
import lockScreenService from '@/service/lock-screen-service';
import { srpClient } from '@/service/srp';
import userService from '@/service/user-service';
import { accessTokenStorage, kekStorage, refreshTokenStorage } from '@/store/main-store';
Expand Down Expand Up @@ -64,6 +65,8 @@ export default new class AuthService {
accessTokenStorage.value = data.accessToken;
refreshTokenStorage.value = data.refreshToken;

await lockScreenService.unlock();

return data;
}

Expand Down
34 changes: 25 additions & 9 deletions src/service/lock-screen-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
IDLE_TIMEOUT,
kekStorage,
noInstantUnlock,
idleTimeoutEnabled,
idleTimeoutEnabled, isLogin,
} from '@/store/main-store';
import { simpleAlert } from '@/utilities/alert';
import { alertController, modalController } from '@ionic/vue';
import idleTimeout from 'idle-timeout';
import type IdleTimeout from 'idle-timeout/dist/IdleTimeout';

Expand All @@ -18,23 +19,25 @@ export default new class {
async handleBeforeLock() {
isLock.value = true;
kekStorage.value = '';
const idleInstance = this.getIdleInstance();
idleInstance.pause();

this.stopListen();
}

async lock() {
await this.handleBeforeLock();

// Dismiss modal and others
modalController.dismiss();
alertController.dismiss();

events.emit(LockScreenEvent);
}

async unlock() {
isLock.value = false;
noInstantUnlock.value = false;

const idleInstance = this.getIdleInstance();
idleInstance.reset();
idleInstance.resume();
this.listenIdleTimeout();
}

async passwordAuthenticate(password: string) {
Expand Down Expand Up @@ -84,10 +87,23 @@ export default new class {
return;
}

const instance = this.getIdleInstance();
console.log('Listen idle-timeout');

instance.reset();
instance.resume();
const idleInstance = this.getIdleInstance();
idleInstance.reset();
idleInstance.resume();
}

stopListen() {
if (!idleTimeoutEnabled) {
return;
}

console.log('Stop listen idle-timeout');

const idleInstance = this.getIdleInstance();
idleInstance.reset();
idleInstance.resume();
}

getIdleInstance() {
Expand Down
4 changes: 4 additions & 0 deletions src/service/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import apiClient from '@/service/api-client';
import authService from '@/service/auth-service';
import events, { RootNavigationEvent } from '@/service/events';
import localAuthService from '@/service/local-auth-service';
import lockScreenService from '@/service/lock-screen-service';
import {
accessTokenStorage,
accountsLoaded,
Expand Down Expand Up @@ -41,6 +42,9 @@ export default new class UserService {

// Secrets
await this.clearUserSecrets();

// Stop Idle Timeout
lockScreenService.stopListen();
});

events.emit(RootNavigationEvent, { name: 'login' }, 'back', 'replace');
Expand Down

0 comments on commit de9b76a

Please sign in to comment.