112 lines
No EOL
2.4 KiB
TypeScript
112 lines
No EOL
2.4 KiB
TypeScript
import { PUBLIC_BASE_URL } from '$env/static/public';
|
|
import { baseUrl } from './env';
|
|
|
|
/**
|
|
* Sets custom text to display on the clock
|
|
*/
|
|
export const setCustomText = (newText: string) => {
|
|
return fetch(`${baseUrl}/api/show/text/${newText}`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Updates the LED colors
|
|
*/
|
|
export const setLEDcolor = (ledStatus: { hex: string }[]) => {
|
|
return fetch(`${baseUrl}/api/lights/set`, {
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
method: 'PATCH',
|
|
body: JSON.stringify(ledStatus)
|
|
}).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Turns off all LEDs
|
|
*/
|
|
export const turnOffLeds = () => {
|
|
return fetch(`${baseUrl}/api/lights/off`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Restarts the clock
|
|
*/
|
|
export const restartClock = () => {
|
|
return fetch(`${baseUrl}/api/restart`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Forces a full refresh of the clock
|
|
*/
|
|
export const forceFullRefresh = () => {
|
|
return fetch(`${baseUrl}/api/full_refresh`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Generates a random color hex code
|
|
*/
|
|
export const generateRandomColor = () => {
|
|
return `#${Math.floor(Math.random() * 16777215)
|
|
.toString(16)
|
|
.padStart(6, '0')}`;
|
|
};
|
|
|
|
/**
|
|
* Sets the active screen
|
|
*/
|
|
export const setActiveScreen = async (screenId: string) => {
|
|
return fetch(`${baseUrl}/api/show/screen/${screenId}`);
|
|
}
|
|
|
|
/**
|
|
* Sets the active currency
|
|
*/
|
|
export const setActiveCurrency = async (currency: string) => {
|
|
return fetch(`${baseUrl}/api/show/currency/${currency}`);
|
|
}
|
|
|
|
/**
|
|
* Turns on the frontlight
|
|
*/
|
|
export const turnOnFrontlight = () => {
|
|
return fetch(`${baseUrl}/api/frontlight/on`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Flashes the frontlight
|
|
*/
|
|
export const flashFrontlight = () => {
|
|
return fetch(`${baseUrl}/api/frontlight/flash`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Turns off the frontlight
|
|
*/
|
|
export const turnOffFrontlight = () => {
|
|
return fetch(`${baseUrl}/api/frontlight/off`).catch(() => {});
|
|
};
|
|
|
|
/**
|
|
* Toggles the timer
|
|
*/
|
|
export const toggleTimer = (currentStatus: boolean) => (e: Event) => {
|
|
e.preventDefault();
|
|
if (currentStatus) {
|
|
fetch(`${baseUrl}/api/action/pause`);
|
|
} else {
|
|
fetch(`${baseUrl}/api/action/timer_restart`);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Toggles the do not disturb mode
|
|
*/
|
|
export const toggleDoNotDisturb = (currentStatus: boolean) => (e: Event) => {
|
|
e.preventDefault();
|
|
console.log(currentStatus);
|
|
if (!currentStatus) {
|
|
fetch(`${baseUrl}/api/dnd/enable`);
|
|
} else {
|
|
fetch(`${baseUrl}/api/dnd/disable`);
|
|
}
|
|
}; |