Skip to content

Commit

Permalink
Use osu-default-background as fallback in mediaSession
Browse files Browse the repository at this point in the history
Two very scuffed things I had to do in order to achieve this: First, for some god forsaken reason I can't import any images in the backend routers without adding a types file and explicitly saying I can add images. Second, I have no idea why, but sharp (library I'm using for resizing images) just WILL NOT let me use a buffer converted from base64 from the default image, so I had to manually resize the default image to 512x512, add it to the project, and import it.
  • Loading branch information
Plextora committed Oct 2, 2024
1 parent 0b9f3c2 commit 5d6ffe9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/router/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "*.jpg";
8 changes: 4 additions & 4 deletions src/main/router/resource-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from "../lib/route-pass/Router";
import { Storage } from "../lib/storage/Storage";
import { none, some } from "../lib/rust-like-utils-backend/Optional";
import { fail, ok } from "../lib/rust-like-utils-backend/Result";
import defaultBackground from "../../renderer/src/assets/osu-default-background-small.jpg";
import path from "path";
import sharp from "sharp";

Expand All @@ -21,17 +22,16 @@ Router.respond("resource::getPath", (_evt, id) => {
});

Router.respond("resource::getMediaSessionImage", async (_evt, bgPath) => {
if (bgPath === undefined) {
return some(defaultBackground);
}
const settings = Storage.getTable("settings");
const songsDir = settings.get("osuSongsDir");
if (songsDir.isNone) {
return none();
}

const pathToBg = path.join(songsDir.value, bgPath);
if (pathToBg === undefined) {
// handle no bg
return none();
}
const mimeType = `image/${path.extname(pathToBg).slice(1)}`;
const buffer = await sharp(pathToBg).resize(512, 512).toBuffer();

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5d6ffe9

Please sign in to comment.