Skip to content

Commit

Permalink
request wake lock on web interface page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBond committed Jan 28, 2025
1 parent 20bc957 commit e194469
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { inputStreamingStateMachine } from './audio-input-streaming/sm';
import z from 'zod';
import { fetchConfig, FRONTEND_CONFIG_SCOPE } from './components/config/service';
import { streamingSupported } from './audio-input-streaming/streamingService';
import { enableWakeLock } from './components/wakeLock';


const FrontendConfig = z.object({
Expand All @@ -26,6 +27,7 @@ const FrontendConfig = z.object({
audioOutputEnabled: z.boolean().default(true),
microphoneSampleRate: z.number(),
hideConfiguration: z.boolean().default(false),
requestWakeLock: z.boolean().default(true),
});

const loadConfig: () => Promise<z.TypeOf<typeof FrontendConfig>> = () => new Promise(resolve => {
Expand Down Expand Up @@ -96,7 +98,11 @@ const getProtocolRequirements = ({
export const initApplication = async () => {
const config = await loadConfig();

const { microphoneSampleRate, hideConfiguration } = config;
const { microphoneSampleRate, hideConfiguration, requestWakeLock } = config;

if (requestWakeLock) {
enableWakeLock();
}

const app = createApp(App);

Expand Down
29 changes: 29 additions & 0 deletions frontend/src/components/wakeLock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let wakeLock: /*WakeLockSentinel*/ any | null = null;

async function requestWakeLock() {
try {
// TODO: Видимо, нужно обновить TS, чтобы типы, связанные с WakeLock определялись
const wl = await (window.navigator as any).wakeLock.request("screen");
if (wakeLock) {
wakeLock.release();
}
wakeLock = wl;
console.log("WakeLock получен");
} catch (err) {
console.log("Ошибка при получении WakeLock", err);
}
}

export function enableWakeLock() {
if (!(window.navigator as any).wakeLock) {
return;
}

requestWakeLock();

document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
requestWakeLock();
}
});
}
2 changes: 2 additions & 0 deletions irene_plugin_web_face_frontend/plugin_web_face_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'hideConfiguration': False,
'customCssPaths': ['{irene_home}/frontend/*.css'],
'customCss': '\n\n',
'requestWakeLock': True,
}

config_comment = """
Expand All @@ -43,6 +44,7 @@
только скрывает графический интерфейс на веб-странице.
- `customCssPaths` - шаблоны путей к файлам, содержащим пользовательские CSS-стили.
- `customCss` - пользовательские CSS-стили.
- `requestWakeLock` - включить запрос WakeLock (запретить браузеру блокировать экран пока открыта страница).
"""

_DIST_DIRS = [
Expand Down

0 comments on commit e194469

Please sign in to comment.