feat: add disableMediaControls function to prevent media key actions
This commit is contained in:
2 files changed
+39
-1
No files matched your search
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
import { active_custom_theme, custom_themes } from './global';
|
import { active_custom_theme, custom_themes } from './global';
|
||||||
import { setGlobalVolume } from './utils';
|
import { disableMediaControls, setGlobalVolume } from './utils';
|
||||||
import { betterFetch } from '@better-fetch/fetch';
|
import { betterFetch } from '@better-fetch/fetch';
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
@@ -268,6 +268,7 @@ export const loadTheme = async (theme: Theme, themeContainer: HTMLElement, volum
|
|||||||
themeScript.mountTheme(themeContainer, { assets: theme.assets });
|
themeScript.mountTheme(themeContainer, { assets: theme.assets });
|
||||||
}
|
}
|
||||||
setGlobalVolume(volume);
|
setGlobalVolume(volume);
|
||||||
|
disableMediaControls();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteTheme = async (themeToUninstall: Theme) => {
|
export const deleteTheme = async (themeToUninstall: Theme) => {
|
||||||
|
|||||||
@@ -203,6 +203,43 @@ export function trackMediaContainer(node: HTMLElement) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MEDIA_ACTIONS: MediaSessionAction[] = [
|
||||||
|
'play',
|
||||||
|
'pause',
|
||||||
|
'stop',
|
||||||
|
'previoustrack',
|
||||||
|
'nexttrack',
|
||||||
|
'seekbackward',
|
||||||
|
'seekforward',
|
||||||
|
];
|
||||||
|
|
||||||
|
export function disableMediaControls() {
|
||||||
|
const mediaElements: NodeListOf<HTMLMediaElement> = document.querySelectorAll('audio, video');
|
||||||
|
|
||||||
|
if ('mediaSession' in navigator) {
|
||||||
|
MEDIA_ACTIONS.forEach((action) => {
|
||||||
|
try {
|
||||||
|
navigator.mediaSession.setActionHandler(action, () => {});
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener(
|
||||||
|
'keydown',
|
||||||
|
(e: KeyboardEvent) => {
|
||||||
|
if (e.key.startsWith('Media')) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
mediaElements.forEach((el) => {
|
||||||
|
el.disableRemotePlayback = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function calculateGitBlobSha(fileBuffer: Buffer): string {
|
export function calculateGitBlobSha(fileBuffer: Buffer): string {
|
||||||
const header = Buffer.from(`blob ${fileBuffer.length}\0`);
|
const header = Buffer.from(`blob ${fileBuffer.length}\0`);
|
||||||
const store = Buffer.concat([header, fileBuffer]);
|
const store = Buffer.concat([header, fileBuffer]);
|
||||||
|
|||||||
Reference in new issue
Block a user