fix: stop duplicate infotainment popups

This commit is contained in:
Youwen Wu 2024-02-24 20:53:53 -08:00
parent 37bf24c076
commit 5f8a166cae

View file

@ -14,47 +14,47 @@ Sequences should be either event-driven or periodic. In the case of periodic
sequences, invoke them in the periodicSequence function sequences, invoke them in the periodicSequence function
*/ */
import { Notifications } from "../Notifications/notifications"; import { Notifications } from '../Notifications/notifications'
import { sequenceStore } from "../stores/sequenceStore"; import { sequenceStore } from '../stores/sequenceStore'
import { settingsStore } from "../stores/settingsStore"; import { settingsStore } from '../stores/settingsStore'
import { get } from "svelte/store"; import { get } from 'svelte/store'
import getVoicePath from "../utils/getVoicePath"; import getVoicePath from '../utils/getVoicePath'
import { tick } from "svelte"; import { tick } from 'svelte'
// await a "tick" (a svelte update frame) at the start of every sequence so that // await a "tick" (a svelte update frame) at the start of every sequence so that
// state is synced and no weird side effects occur // state is synced and no weird side effects occur
export const initializationSequence = async () => { export const initializationSequence = async () => {
await tick(); await tick()
Notifications.info("Jankboard initialized!", { Notifications.info('Jankboard initialized!', {
withAudio: true, withAudio: true,
src: getVoicePath("jankboard-initialized", "en"), src: getVoicePath('jankboard-initialized', 'en'),
}); })
setTimeout(() => { setTimeout(() => {
if (get(settingsStore).goWoke) return; if (get(settingsStore).goWoke) return
Notifications.success("LittenOS is online", { Notifications.success('LittenOS is online', {
withAudio: true, withAudio: true,
src: getVoicePath("littenos-is-online", "en"), src: getVoicePath('littenos-is-online', 'en'),
}); })
setTimeout(() => { setTimeout(() => {
Notifications.warn("Breaching Monte Vista codebase", { Notifications.warn('Breaching Monte Vista codebase', {
withAudio: true, withAudio: true,
src: getVoicePath("breaching-monte-vista", "en"), src: getVoicePath('breaching-monte-vista', 'en'),
}); })
setTimeout(() => { setTimeout(() => {
Notifications.playAudio( Notifications.playAudio(
getVoicePath("hello-virtual-assistant", "en"), getVoicePath('hello-virtual-assistant', 'en'),
() => { () => {
sequenceStore.update("initializationComplete", true); sequenceStore.update('initializationComplete', true)
periodicSequence(); periodicSequence()
}
)
}, 3000)
}, 3000)
}, 3000)
} }
);
}, 3000);
}, 3000);
}, 3000);
};
let counter = 1; let counter = 1
/** /**
* Special sequence that plays invokes itself periodically, started automatically * Special sequence that plays invokes itself periodically, started automatically
* at the end of the initializationSequence * at the end of the initializationSequence
@ -64,7 +64,7 @@ let counter = 1;
* @return void * @return void
*/ */
const periodicSequence = async () => { const periodicSequence = async () => {
await tick(); await tick()
/** /**
* Returns either true or false based on the provided probability * Returns either true or false based on the provided probability
@ -74,11 +74,11 @@ const periodicSequence = async () => {
*/ */
const chance = (probability: number) => { const chance = (probability: number) => {
if (probability < 0 || probability > 1) { if (probability < 0 || probability > 1) {
throw new Error("Probability must be between 0 and 1"); throw new Error('Probability must be between 0 and 1')
} }
return Math.random() < probability; return Math.random() < probability
}; }
/** /**
* Calls a callback function at regular intervals. * Calls a callback function at regular intervals.
@ -87,134 +87,138 @@ const periodicSequence = async () => {
* @param callback - the function to call * @param callback - the function to call
*/ */
const every = (seconds: number, callback: () => void) => { const every = (seconds: number, callback: () => void) => {
if (counter % seconds === 0) callback(); if (counter % seconds === 0) callback()
}; }
// add your periodic sequences here // add your periodic sequences here
every(15, () => { every(15, () => {
if (chance(0.2)) breaching1323Sequence(); if (chance(0.2)) breaching1323Sequence()
else if (chance(0.2)) breaching254Sequence(); else if (chance(0.2)) breaching254Sequence()
else if (chance(0.05)) bullyingRohanSequence(); else if (chance(0.05)) bullyingRohanSequence()
else if (chance(0.1)) bypassCoprocessorRestrictionsSequence(); else if (chance(0.1)) bypassCoprocessorRestrictionsSequence()
}); })
// Dont touch // Dont touch
counter++; counter++
setTimeout(periodicSequence, 1000); setTimeout(periodicSequence, 1000)
}; }
export const criticalFailureIminentSequence = async () => { export const criticalFailureIminentSequence = async () => {
await tick(); await tick()
Notifications.error("Critical robot failure imminent", { Notifications.error('Critical robot failure imminent', {
withAudio: true, withAudio: true,
src: getVoicePath("critical-robot-failure", "en"), src: getVoicePath('critical-robot-failure', 'en'),
}); })
}; }
export const collisionDetectedSequence = async () => { export const collisionDetectedSequence = async () => {
await tick(); await tick()
Notifications.error("Collision detected", { Notifications.error('Collision detected', {
withAudio: true, withAudio: true,
src: getVoicePath("collision-detected", "en"), src: getVoicePath('collision-detected', 'en'),
}); })
}; }
export const collisionImminentSequence = async () => { export const collisionImminentSequence = async () => {
await tick(); await tick()
Notifications.error("Collision imminent", { Notifications.error('Collision imminent', {
withAudio: true, withAudio: true,
src: getVoicePath("collision-imminent", "en"), src: getVoicePath('collision-imminent', 'en'),
}); })
}; }
export const cruiseControlEngagedSequence = async () => { export const cruiseControlEngagedSequence = async () => {
if (get(settingsStore).disableAnnoyances) return; if (get(settingsStore).disableAnnoyances) return
await tick(); await tick()
Notifications.success("Cruise control engaged", { Notifications.success('Cruise control engaged', {
withAudio: true, withAudio: true,
src: getVoicePath("cruise-control-engaged", "en"), src: getVoicePath('cruise-control-engaged', 'en'),
}); })
}; }
export const retardSequence = async () => { export const retardSequence = async () => {
if (get(settingsStore).goWoke) return; if (get(settingsStore).goWoke) return
await tick(); await tick()
Notifications.warn("Retard", { Notifications.warn('Retard', {
withAudio: true, withAudio: true,
src: getVoicePath("retard", "en"), src: getVoicePath('retard', 'en'),
}); })
}; }
const breaching254Sequence = async () => { const breaching254Sequence = async () => {
if (get(settingsStore).disableAnnoyances) return; if (get(settingsStore).disableAnnoyances) return
await tick(); await tick()
Notifications.warn("Breaching 254 mainframe", { Notifications.warn('Breaching 254 mainframe', {
withAudio: true, withAudio: true,
src: getVoicePath("breaching-254-mainframe", "en"), src: getVoicePath('breaching-254-mainframe', 'en'),
}); })
}; }
const breaching1323Sequence = async () => { const breaching1323Sequence = async () => {
if (get(settingsStore).disableAnnoyances) return; if (get(settingsStore).disableAnnoyances) return
await tick(); await tick()
Notifications.warn("Breaching 1323 mainframe", { Notifications.warn('Breaching 1323 mainframe', {
withAudio: true, withAudio: true,
src: getVoicePath("breaching-1323-mainframe", "en"), src: getVoicePath('breaching-1323-mainframe', 'en'),
}); })
}; }
const bullyingRohanSequence = async () => { const bullyingRohanSequence = async () => {
if (get(settingsStore).disableAnnoyances) return; if (get(settingsStore).disableAnnoyances) return
await tick(); await tick()
Notifications.info("Bullying Rohan", { Notifications.info('Bullying Rohan', {
withAudio: true, withAudio: true,
src: getVoicePath("bullying-rohan", "en"), src: getVoicePath('bullying-rohan', 'en'),
}); })
}; }
export const userErrorDetectedSequence = async () => { export const userErrorDetectedSequence = async () => {
await tick(); await tick()
Notifications.error("User error detected", { Notifications.error('User error detected', {
withAudio: true, withAudio: true,
src: getVoicePath("user-error-detected", "en"), src: getVoicePath('user-error-detected', 'en'),
}); })
}; }
// hacky way to prevent duplicate infotainment bootups
let infotainmentStarted = false
export const infotainmentBootupSequence = async () => { export const infotainmentBootupSequence = async () => {
if ( if (
get(sequenceStore).infotainmentStartedFirstTime || get(sequenceStore).infotainmentStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances ||
infotainmentStarted
) )
return; return
await tick(); infotainmentStarted = true
await tick()
const sequence = () => { const sequence = () => {
Notifications.info("Infotainment system buffering", { Notifications.info('Infotainment system buffering', {
withAudio: true, withAudio: true,
src: getVoicePath("infotainment-system-buffering", "en"), src: getVoicePath('infotainment-system-buffering', 'en'),
}); })
setTimeout(() => { setTimeout(() => {
Notifications.success("Infotainment system online", { Notifications.success('Infotainment system online', {
withAudio: true, withAudio: true,
src: getVoicePath("infotainment-system-online", "en"), src: getVoicePath('infotainment-system-online', 'en'),
onComplete: () => { onComplete: () => {
sequenceStore.update("infotainmentStartedFirstTime", true); sequenceStore.update('infotainmentStartedFirstTime', true)
}, },
}); })
}, 3000); }, 3000)
}; }
if (!get(sequenceStore).initializationComplete) { if (!get(sequenceStore).initializationComplete) {
const unsubscribe = sequenceStore.subscribe((data) => { const unsubscribe = sequenceStore.subscribe(data => {
if (data.initializationComplete) { if (data.initializationComplete) {
sequence(); sequence()
unsubscribe(); unsubscribe()
} }
}); })
} else { } else {
sequence(); sequence()
}
} }
};
/** /**
* Waits for the infotainment system to boot up before executing the given sequence. * Waits for the infotainment system to boot up before executing the given sequence.
@ -225,77 +229,77 @@ export const infotainmentBootupSequence = async () => {
*/ */
const waitForInfotainmentBootup = (sequence: () => void) => { const waitForInfotainmentBootup = (sequence: () => void) => {
if (!get(sequenceStore).infotainmentStartedFirstTime) { if (!get(sequenceStore).infotainmentStartedFirstTime) {
const unsubscribe = sequenceStore.subscribe((data) => { const unsubscribe = sequenceStore.subscribe(data => {
if (data.infotainmentStartedFirstTime) { if (data.infotainmentStartedFirstTime) {
sequence(); sequence()
unsubscribe(); unsubscribe()
} }
}); })
} else { } else {
sequence(); sequence()
}
} }
};
export const musicPlayerBootupSequence = async () => { export const musicPlayerBootupSequence = async () => {
if ( if (
get(sequenceStore).musicStartedFirstTime || get(sequenceStore).musicStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return; return
await tick(); await tick()
sequenceStore.update("musicStartedFirstTime", true); sequenceStore.update('musicStartedFirstTime', true)
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.info("Downloading copyrighted music...", { Notifications.info('Downloading copyrighted music...', {
withAudio: true, withAudio: true,
src: getVoicePath("downloading-copyrighted-music", "en"), src: getVoicePath('downloading-copyrighted-music', 'en'),
}); })
}); })
}; }
export const gbaEmulatorBootupSequence = async () => { export const gbaEmulatorBootupSequence = async () => {
if ( if (
get(sequenceStore).gbaEmulatorStartedFirstTime || get(sequenceStore).gbaEmulatorStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return; return
await tick(); await tick()
sequenceStore.update("gbaEmulatorStartedFirstTime", true); sequenceStore.update('gbaEmulatorStartedFirstTime', true)
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.info("Loading pirated Nintendo ROMs", { Notifications.info('Loading pirated Nintendo ROMs', {
withAudio: true, withAudio: true,
src: getVoicePath("loading-pirated-nintendo", "en"), src: getVoicePath('loading-pirated-nintendo', 'en'),
}); })
}); })
}; }
export const doomBootupSequence = async () => { export const doomBootupSequence = async () => {
if ( if (
get(sequenceStore).doomStartedFirstTime || get(sequenceStore).doomStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return; return
await tick(); await tick()
sequenceStore.update("doomStartedFirstTime", true); sequenceStore.update('doomStartedFirstTime', true)
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.success("Doom Engaged", { Notifications.success('Doom Engaged', {
withAudio: true, withAudio: true,
src: getVoicePath("doom-engaged", "en"), src: getVoicePath('doom-engaged', 'en'),
}); })
}); })
}; }
const bypassCoprocessorRestrictionsSequence = async () => { const bypassCoprocessorRestrictionsSequence = async () => {
if (get(settingsStore).disableAnnoyances) return; if (get(settingsStore).disableAnnoyances) return
await tick(); await tick()
Notifications.warn("Bypassing coprocessor restrictions", { Notifications.warn('Bypassing coprocessor restrictions', {
withAudio: true, withAudio: true,
src: getVoicePath("bypassing-coprocessor-restrictions", "en"), src: getVoicePath('bypassing-coprocessor-restrictions', 'en'),
}); })
}; }