mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 05:25:53 +08:00
feat(editor): audio block (#10947)
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
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
import type { MediaStats } from '@toeverything/infra';
|
||||
import { app } from 'electron';
|
||||
|
||||
import { logger } from './logger';
|
||||
import { globalStateStorage } from './shared-storage/storage';
|
||||
|
||||
const cleanupRegistry: (() => void)[] = [];
|
||||
const beforeAppQuitRegistry: (() => void)[] = [];
|
||||
const beforeTabCloseRegistry: ((tabId: string) => void)[] = [];
|
||||
|
||||
export function beforeAppQuit(fn: () => void) {
|
||||
cleanupRegistry.push(fn);
|
||||
beforeAppQuitRegistry.push(fn);
|
||||
}
|
||||
|
||||
export function beforeTabClose(fn: (tabId: string) => void) {
|
||||
beforeTabCloseRegistry.push(fn);
|
||||
}
|
||||
|
||||
app.on('before-quit', () => {
|
||||
cleanupRegistry.forEach(fn => {
|
||||
beforeAppQuitRegistry.forEach(fn => {
|
||||
// some cleanup functions might throw on quit and crash the app
|
||||
try {
|
||||
fn();
|
||||
@@ -18,3 +25,32 @@ app.on('before-quit', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user