-
Notifications
You must be signed in to change notification settings - Fork 200
/
AppEvents.tsx
62 lines (49 loc) · 1.84 KB
/
AppEvents.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { useEffect } from 'react';
import player from '../../lib/player';
// import SettingsAPI from '../../stores/SettingsAPI';
// import type { Theme } from '../../types/museeks';
import { logAndNotifyError } from '../../lib/utils';
import { isDev, preventNativeDefault } from '../../lib/utils-events';
/**
* Handle app-level IPC Events init and cleanup
*/
function AppEvents() {
useEffect(() => {
// Prevent drop events on the window
window.addEventListener('dragover', preventNativeDefault, false);
window.addEventListener('drop', preventNativeDefault, false);
// Disable the default context menu on production builds
if (!isDev()) {
window.addEventListener('contextmenu', preventNativeDefault);
}
// TODO: fix that https://github.com/tauri-apps/tauri/issues/5279
// Auto-update theme if set to system and the native theme changes
// function updateTheme(_event: IpcRendererEvent, theme: unknown) {
// SettingsAPI.applyThemeToUI(theme as Theme);
// }
// ipcRenderer.on(channels.THEME_APPLY, updateTheme);
// Support for multiple audio output
async function updateOutputDevice() {
try {
await player.setOutputDevice('default');
} catch (err) {
logAndNotifyError(err);
}
}
navigator.mediaDevices.addEventListener('devicechange', updateOutputDevice);
return function cleanup() {
window.removeEventListener('dragover', preventNativeDefault, false);
window.removeEventListener('drop', preventNativeDefault, false);
if (!isDev()) {
window.removeEventListener('contextmenu', preventNativeDefault);
}
// ipcRenderer.off(channels.THEME_APPLY, updateTheme);
navigator.mediaDevices.removeEventListener(
'devicechange',
updateOutputDevice,
);
};
}, []);
return null;
}
export default AppEvents;