diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 492bf4a4..f3308f78 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -622,7 +622,10 @@ export class BrowserWindow { const wpBase64: string = await readFileSync(wpPath, 'base64') // add the data:image properties const wpData: string = `data:image/png;base64,${wpBase64}` - event.returnValue = wpData; + event.returnValue = { + path: wpPath, + data: wpData + }; }) ipcMain.handle("reinstall-widevine-cdm", () => { diff --git a/src/renderer/main/mica.js b/src/renderer/main/mica.js index a27161f7..189c9cee 100644 --- a/src/renderer/main/mica.js +++ b/src/renderer/main/mica.js @@ -1,7 +1,9 @@ +import { CiderCache } from "./cidercache.js" + async function spawnMica() { - if(typeof window.micaSpawned !== "undefined") { + if (typeof window.micaSpawned !== "undefined") { return - }else{ + } else { window.micaSpawned = true } const micaDiv = document.createElement('div'); @@ -19,20 +21,38 @@ async function spawnMica() { let lastScreenWidth; let lastScreenHeight; + let regen = true let imgSrc = await ipcRenderer.sendSync("get-wallpaper") + + let micaCache = await CiderCache.getCache("mica-cache") + if (!micaCache) { + micaCache = { + path: "", + data: "" + } + } + if (micaCache.path == imgSrc.path) { + regen = false + imgSrc = micaCache + } let canvas = document.createElement('canvas'); let ctx = canvas.getContext('2d'); let img = new Image(); - img.src = imgSrc; + img.src = imgSrc.data; img.onload = function () { canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); - for (let i = 0; i < blurIterations; i++) { - StackBlur.canvasRGB(canvas, 0, 0, img.width, img.height, 128); + if (regen) { + for (let i = 0; i < blurIterations; i++) { + StackBlur.canvasRGB(canvas, 0, 0, img.width, img.height, 128); + } + micaCache.path = imgSrc.path + micaCache.data = canvas.toDataURL() + CiderCache.putCache("mica-cache", micaCache) } let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); - micaDiv.style.backgroundImage = `url(${canvas.toDataURL()})`; + micaDiv.style.backgroundImage = `url(${micaCache.data})`; document.body.appendChild(micaDiv); // on animation finished set animation to unset micaDiv.addEventListener('animationend', function () { @@ -84,4 +104,4 @@ async function spawnMica() { return true } -export {spawnMica} \ No newline at end of file +export { spawnMica } \ No newline at end of file