Skip to content

Commit

Permalink
Update application active state
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanchauict committed Dec 13, 2024
1 parent 4c34a7e commit af5af58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions monosketch-svelte/src/lib/mono/window/window-viewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { Flow } from '$libs/flow';

export namespace WindowViewModel {
export const windowSizeUpdateEventFlow = new Flow<boolean>(true);

export const applicationActiveStateFlow = new Flow<boolean>(true);
}
14 changes: 13 additions & 1 deletion monosketch-svelte/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import '$assets/fonts/stylesheet.css';
import '$style/main.scss';
import App from './App.svelte';
import { AppContext } from '$app/app-context';
import { APP_CONTEXT } from '$mono/common/constant';
import { WindowViewModel } from '$mono/window/window-viewmodel';
import App from './App.svelte';

const appContext = new AppContext();
const context = new Map();
Expand All @@ -13,6 +13,18 @@ window.onresize = () => {
WindowViewModel.windowSizeUpdateEventFlow.value = true;
};

window.onfocus = () => {
WindowViewModel.applicationActiveStateFlow.value = true;
}

Check failure on line 18 in monosketch-svelte/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

window.onblur = () => {
WindowViewModel.applicationActiveStateFlow.value = false;
}

Check failure on line 22 in monosketch-svelte/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

document.addEventListener('visibilitychange', () => {
WindowViewModel.applicationActiveStateFlow.value = document['visibilityState'] === 'visible';
});

const app = new App({
// @ts-expect-error - Safe to ignore
target: document.getElementById('app'),
Expand Down

0 comments on commit af5af58

Please sign in to comment.