Skip to content

Commit e269acc

Browse files
author
NellowTCS
committed
SATORIII
1 parent 2298d76 commit e269acc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+463
-154
lines changed

Build/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@fontsource/inter": "^5.2.8",
3535
"@fontsource/jetbrains-mono": "^5.2.8",
3636
"@fontsource/poppins": "^5.2.7",
37-
"@nisoku/satori-log": "^0.1.2",
37+
"@nisoku/satori": "^0.1.3",
3838
"@radix-ui/react-collapsible": "^1.1.12",
3939
"@radix-ui/react-dialog": "^1.1.15",
4040
"@radix-ui/react-dropdown-menu": "^2.1.16",

Build/src/constants/pip.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export const PIP_WINDOW_WIDTH = 400;
2+
export const PIP_WINDOW_HEIGHT = 70;
3+
export const PIP_STYLE_DELAY_MS = 300;
4+
5+
export const PIP_THEME_VARIABLES = [
6+
"--themecolor",
7+
"--themecolor2",
8+
"--themecolor3",
9+
"--themecolor4",
10+
"--themegradient",
11+
"--themecolor-transparent",
12+
"--themecolor2-transparent",
13+
"--themecolor3-transparent",
14+
"--foreground",
15+
"--foreground-strong",
16+
"--foreground-stronger",
17+
"--foreground-muted",
18+
"--foreground-subtle",
19+
"--background",
20+
"--surface",
21+
"--surface-foreground",
22+
"--surface-transparent-05",
23+
"--surface-transparent-1",
24+
"--surface-transparent-2",
25+
"--primary",
26+
"--primary-foreground",
27+
"--primary-transparent",
28+
"--primary-border",
29+
"--primary-border-strong",
30+
"--secondary",
31+
"--secondary-foreground",
32+
"--menu-background",
33+
"--spacing-1",
34+
"--spacing-2",
35+
"--spacing-3",
36+
"--spacing-4",
37+
"--radius",
38+
"--radius-lg",
39+
] as const;

Build/src/helpers/importAudioFiles.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toast } from "sonner";
2+
import { logger } from "./logger";
23
import {
34
createMetadataExtractor,
45
createFloMetadataExtractor,
@@ -32,7 +33,11 @@ async function extractAudioMetadata(
3233
try {
3334
albumArt = await compressAlbumArt(albumArt);
3435
} catch (e) {
35-
console.warn("Failed to compress album art:", e);
36+
if (e instanceof Error) {
37+
logger.warn("Failed to compress album art:", { error: e.message });
38+
} else {
39+
logger.warn("Failed to compress album art");
40+
}
3641
}
3742
}
3843

@@ -104,7 +109,7 @@ export async function importAudioFiles(
104109
{ type: "audio/wav" },
105110
);
106111
processedMimeType = "audio/wav";
107-
console.log(`Pre-decoded flo to WAV for Safari: ${file.name}`);
112+
logger.info(`Pre-decoded flo to WAV for Safari: ${file.name}`);
108113
} else {
109114
// Non-Safari: Pre-decode to PCM for Web Audio API
110115
const { decodeFloToAudioBuffer } =
@@ -148,13 +153,14 @@ export async function importAudioFiles(
148153
// Close the temporary AudioContext
149154
await audioContext.close();
150155

151-
console.log(`Pre-decoded flo to PCM: ${file.name}`);
156+
logger.info(`Pre-decoded flo to PCM: ${file.name}`);
152157
}
153158
} catch (error) {
154-
console.warn(
155-
"Failed to pre-decode flo file, storing original:",
156-
error,
157-
);
159+
if (error instanceof Error) {
160+
logger.warn("Failed to pre-decode flo file, storing original:", { error: error.message });
161+
} else {
162+
logger.warn("Failed to pre-decode flo file, storing original");
163+
}
158164
// Keep original file if pre-decoding fails
159165
processedMimeType = "audio/x-flo";
160166
}
@@ -192,7 +198,11 @@ export async function importAudioFiles(
192198

193199
successCount++;
194200
} catch (error) {
195-
console.error("Failed to process song:", error);
201+
if (error instanceof Error) {
202+
logger.error("Failed to process song:", { error: error.message });
203+
} else {
204+
logger.error("Failed to process song");
205+
}
196206
errorCount++;
197207
}
198208
}

Build/src/helpers/logger.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { createSatori, type SatoriInstance } from "@nisoku/satori";
2+
3+
export const satori: SatoriInstance = createSatori({
4+
logLevel: "debug",
5+
rateLimiting: {
6+
enabled: true,
7+
maxEventsPerSecond: 100,
8+
},
9+
});
10+
11+
export const logger = {
12+
debug: (message: string, data?: Record<string, unknown>) => {
13+
satori.rootLogger.debug(message, data ? { state: data } : undefined);
14+
},
15+
info: (message: string, data?: Record<string, unknown>) => {
16+
satori.rootLogger.info(message, data ? { state: data } : undefined);
17+
},
18+
warn: (message: string, data?: Record<string, unknown>) => {
19+
satori.rootLogger.warn(message, data ? { state: data } : undefined);
20+
},
21+
error: (message: string, data?: Record<string, unknown>) => {
22+
satori.rootLogger.error(message, data ? { state: data } : undefined);
23+
},
24+
};
25+
26+
export const createLogger = (scope: string) => {
27+
const scoped = satori.createLogger(scope);
28+
return {
29+
debug: (message: string, data?: Record<string, unknown>) => {
30+
scoped.debug(message, data ? { state: data } : undefined);
31+
},
32+
info: (message: string, data?: Record<string, unknown>) => {
33+
scoped.info(message, data ? { state: data } : undefined);
34+
},
35+
warn: (message: string, data?: Record<string, unknown>) => {
36+
scoped.warn(message, data ? { state: data } : undefined);
37+
},
38+
error: (message: string, data?: Record<string, unknown>) => {
39+
scoped.error(message, data ? { state: data } : undefined);
40+
},
41+
};
42+
};
43+
44+
export const throwError = (message: string, data?: Record<string, unknown>): never => {
45+
satori.rootLogger.error(message, { state: { ...data, fatal: true } });
46+
throw new Error(message);
47+
};

Build/src/hooks/useFileHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
type FileHandlerResult,
66
} from "../platform/storage/fileHandler";
77
import type { Track } from "../core/engine/types";
8+
import { createLogger } from "../helpers/logger";
9+
10+
const logger = createLogger("useFileHandler");
811

912
export function useFileHandler(
1013
addSong: (song: Track) => Promise<void>,
@@ -65,7 +68,7 @@ export function useFileHandler(
6568
);
6669
})
6770
.catch((error) => {
68-
console.error("Failed to process queued files:", error);
71+
logger.error("Failed to process queued files:", { error: String(error) });
6972
toast.error(
7073
t("filePicker.failedImport", { count: filesToProcess.length }),
7174
);

Build/src/hooks/useKeyboardShortcuts.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
type ShortcutConfig,
66
} from "../platform/storage/shortcuts";
77
import type { UseKomorebiReturn } from "./useKomorebi";
8+
import { createLogger } from "../helpers/logger";
9+
10+
const logger = createLogger("keyboardShortcuts");
811

912
interface UseKeyboardShortcutsProps {
1013
komorebi: UseKomorebiReturn;
@@ -30,7 +33,7 @@ export const useKeyboardShortcuts = ({
3033
});
3134

3235
useEffect(() => {
33-
shortcutsDb.getAllShortcuts().then(setShortcuts).catch(console.error);
36+
shortcutsDb.getAllShortcuts().then(setShortcuts).catch((e) => logger.error("Failed to load shortcuts", { error: String(e) }));
3437
}, []);
3538

3639
useEffect(() => {

Build/src/hooks/useKomorebi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { HTMLAudioBackend } from "../platform/audio/backends/HTMLBackend";
1111
import { LibraryManager } from "../platform/library/library";
1212
import { libraryPersistence } from "../platform/library/persistence";
1313
import { SettingsManager } from "../platform/settings/settings";
14+
import { createLogger } from "../helpers/logger";
15+
16+
const logger = createLogger("useKomorebi");
1417

1518
export interface UseKomorebiOptions {
1619
autoPlay?: boolean;
@@ -191,7 +194,7 @@ export function useKomorebi(
191194
});
192195
}
193196
} catch (err) {
194-
console.error("Failed to load library:", err);
197+
logger.error("Failed to load library:", { error: String(err) });
195198
}
196199
};
197200

Build/src/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"common": {
1212
"cancel": "Cancel",
13+
"confirm": "Confirm",
1314
"close": "Close",
1415
"create": "Create",
1516
"delete": "Delete",

Build/src/locales/fr/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"common": {
1212
"cancel": "Annuler",
13+
"confirm": "Confirmer",
1314
"close": "Fermer",
1415
"create": "Créer",
1516
"delete": "Supprimer",

0 commit comments

Comments
 (0)