mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
120 in printWidth since rocky got md
This commit is contained in:
1 parent
f552c1212c
commit
d27aeb3b0e
90 files changed
+398
-1146
No files matched your search
@@ -21,16 +21,7 @@ const useSound = (url: string, options: ISoundOptions = DEFAULT_OPTIONS) => {
|
||||
|
||||
const [isPlaying, setPlaying] = useState<boolean>(false);
|
||||
|
||||
const {
|
||||
mount,
|
||||
play,
|
||||
stop,
|
||||
playing,
|
||||
volume,
|
||||
loop,
|
||||
remove,
|
||||
isMounted,
|
||||
} = useSoundProvider();
|
||||
const { mount, play, stop, playing, volume, loop, remove, isMounted } = useSoundProvider();
|
||||
|
||||
const previousInterrupt = usePreviousState(interrupt);
|
||||
const previousUrl = usePreviousState(url);
|
||||
@@ -50,20 +41,7 @@ const useSound = (url: string, options: ISoundOptions = DEFAULT_OPTIONS) => {
|
||||
}
|
||||
volume(url, vol);
|
||||
loop(url, isLoop);
|
||||
}, [
|
||||
url,
|
||||
vol,
|
||||
isLoop,
|
||||
isMounted,
|
||||
volume,
|
||||
loop,
|
||||
mount,
|
||||
previousUrl,
|
||||
stop,
|
||||
remove,
|
||||
isPlaying,
|
||||
play,
|
||||
]);
|
||||
}, [url, vol, isLoop, isMounted, volume, loop, mount, previousUrl, stop, remove, isPlaying, play]);
|
||||
|
||||
useEffect(() => {
|
||||
if (interrupt) {
|
||||
|
||||
@@ -7,12 +7,7 @@ interface IMountResponse {
|
||||
}
|
||||
|
||||
interface ISoundContext {
|
||||
mount(
|
||||
url: string,
|
||||
volume?: number,
|
||||
loop?: boolean,
|
||||
autoplay?: boolean,
|
||||
): Promise<IMountResponse>;
|
||||
mount(url: string, volume?: number, loop?: boolean, autoplay?: boolean): Promise<IMountResponse>;
|
||||
play(url?: string, volume?: number, loop?: boolean): void;
|
||||
stop(url: string): void;
|
||||
remove(url: string): boolean;
|
||||
@@ -31,55 +26,47 @@ export const SoundProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
soundRefs.current = new Map();
|
||||
}, []);
|
||||
|
||||
const mount = useCallback(
|
||||
(
|
||||
url: string,
|
||||
volume: number = 1,
|
||||
loop: boolean = false,
|
||||
autoplay: boolean = false,
|
||||
) => {
|
||||
return new Promise<IMountResponse>((res) => {
|
||||
if (!soundRefs.current) {
|
||||
soundRefs.current = new Map();
|
||||
const mount = useCallback((url: string, volume: number = 1, loop: boolean = false, autoplay: boolean = false) => {
|
||||
return new Promise<IMountResponse>((res) => {
|
||||
if (!soundRefs.current) {
|
||||
soundRefs.current = new Map();
|
||||
}
|
||||
|
||||
const find = soundRefs.current.get(url);
|
||||
|
||||
if (find) {
|
||||
find.howl.volume(volume);
|
||||
find.howl.loop(loop);
|
||||
if (autoplay) {
|
||||
find.howl.play();
|
||||
}
|
||||
return res({ howl: find.howl, url });
|
||||
}
|
||||
|
||||
const find = soundRefs.current.get(url);
|
||||
|
||||
if (find) {
|
||||
find.howl.volume(volume);
|
||||
find.howl.loop(loop);
|
||||
if (autoplay) {
|
||||
find.howl.play();
|
||||
}
|
||||
return res({ howl: find.howl, url });
|
||||
}
|
||||
|
||||
const instance = new Howl({
|
||||
src: url,
|
||||
loop,
|
||||
volume,
|
||||
autoplay,
|
||||
});
|
||||
|
||||
soundRefs.current.set(url, { howl: instance, volume });
|
||||
|
||||
instance.once('load', () => {
|
||||
console.log('ready', instance);
|
||||
res({ howl: instance, url });
|
||||
});
|
||||
|
||||
const onError = (_id, e) => {
|
||||
res(null);
|
||||
console.error('Howler Error \n', e, '\nid: ', _id, '\nsrc: ', url);
|
||||
};
|
||||
|
||||
instance.once('loaderror', onError);
|
||||
|
||||
instance.once('playerror', onError);
|
||||
const instance = new Howl({
|
||||
src: url,
|
||||
loop,
|
||||
volume,
|
||||
autoplay,
|
||||
});
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
soundRefs.current.set(url, { howl: instance, volume });
|
||||
|
||||
instance.once('load', () => {
|
||||
console.log('ready', instance);
|
||||
res({ howl: instance, url });
|
||||
});
|
||||
|
||||
const onError = (_id, e) => {
|
||||
res(null);
|
||||
console.error('Howler Error \n', e, '\nid: ', _id, '\nsrc: ', url);
|
||||
};
|
||||
|
||||
instance.once('loaderror', onError);
|
||||
|
||||
instance.once('playerror', onError);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const play = useCallback(
|
||||
(url: string, volume: number, loop: boolean) => {
|
||||
@@ -167,9 +154,7 @@ export const SoundProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<soundContext.Provider
|
||||
value={{ mount, play, stop, playing, remove, volume, loop, isMounted }}
|
||||
>
|
||||
<soundContext.Provider value={{ mount, play, stop, playing, remove, volume, loop, isMounted }}>
|
||||
{children}
|
||||
</soundContext.Provider>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { IPhoneSettings } from '../../../apps/settings/hooks/useSettings';
|
||||
import {
|
||||
getNotificationPath,
|
||||
getRingtonePath,
|
||||
} from '../../../apps/settings/utils/getRingtonePath';
|
||||
import { getNotificationPath, getRingtonePath } from '../../../apps/settings/utils/getRingtonePath';
|
||||
|
||||
const getPath = {
|
||||
ringtone: getRingtonePath,
|
||||
@@ -12,11 +9,7 @@ const getPath = {
|
||||
/**
|
||||
* Gets the configuration for SoundProvider based on settings and apps
|
||||
*/
|
||||
export const getSoundSettings = (
|
||||
type: 'ringtone' | 'notification',
|
||||
settings: IPhoneSettings,
|
||||
app?: string,
|
||||
) => {
|
||||
export const getSoundSettings = (type: 'ringtone' | 'notification', settings: IPhoneSettings, app?: string) => {
|
||||
try {
|
||||
return app
|
||||
? {
|
||||
|
||||
Reference in new issue
Block a user