mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
fad49bb070
AudioMedia entity for loading & controlling a single audio media AudioMediaManagerService: Global audio state synchronization across tabs AudioAttachmentService + AudioAttachmentBlock for manipulating AttachmentBlock in affine - e.g., filling transcription (using mock endpoint for now) Added AudioBlock + AudioPlayer for rendering audio block in affine (new transcription block whose renderer is provided in affine) fix AF-2292 fix AF-2337
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import type { MediaStats } from '@toeverything/infra';
|
|
import { app } from 'electron';
|
|
|
|
import { logger } from './logger';
|
|
import { globalStateStorage } from './shared-storage/storage';
|
|
|
|
const beforeAppQuitRegistry: (() => void)[] = [];
|
|
const beforeTabCloseRegistry: ((tabId: string) => void)[] = [];
|
|
|
|
export function beforeAppQuit(fn: () => void) {
|
|
beforeAppQuitRegistry.push(fn);
|
|
}
|
|
|
|
export function beforeTabClose(fn: (tabId: string) => void) {
|
|
beforeTabCloseRegistry.push(fn);
|
|
}
|
|
|
|
app.on('before-quit', () => {
|
|
beforeAppQuitRegistry.forEach(fn => {
|
|
// some cleanup functions might throw on quit and crash the app
|
|
try {
|
|
fn();
|
|
} catch (err) {
|
|
logger.warn('cleanup error on quit', err);
|
|
}
|
|
});
|
|
});
|
|
|
|
export function onTabClose(tabId: string) {
|
|
beforeTabCloseRegistry.forEach(fn => {
|
|
try {
|
|
fn(tabId);
|
|
} catch (err) {
|
|
logger.warn('cleanup error on tab close', err);
|
|
}
|
|
});
|
|
}
|
|
|
|
app.on('ready', () => {
|
|
globalStateStorage.set('media:playback-state', null);
|
|
globalStateStorage.set('media:stats', null);
|
|
});
|
|
|
|
beforeAppQuit(() => {
|
|
globalStateStorage.set('media:playback-state', null);
|
|
globalStateStorage.set('media:stats', null);
|
|
});
|
|
|
|
// set audio play state
|
|
beforeTabClose(tabId => {
|
|
const stats = globalStateStorage.get<MediaStats | null>('media:stats');
|
|
if (stats && stats.tabId === tabId) {
|
|
globalStateStorage.set('media:playback-state', null);
|
|
globalStateStorage.set('media:stats', null);
|
|
}
|
|
});
|