mica improvements

- moved mica rendering to backend
- improvements to spanning wallpapers
This commit is contained in:
booploops 2022-06-02 21:10:17 -07:00
parent c255420169
commit 0803252018
4 changed files with 107 additions and 109 deletions

View file

@ -1,5 +1,5 @@
import {join} from "path";
import {app, BrowserWindow as bw, ipcMain, ShareMenu, shell} from "electron";
import {app, BrowserWindow as bw, ipcMain, ShareMenu, shell, screen} from "electron";
import * as windowStateKeeper from "electron-window-state";
import * as express from "express";
import * as getPort from "get-port";
@ -745,15 +745,28 @@ export class BrowserWindow {
return json;
})
ipcMain.on("get-wallpaper", async (event) => {
ipcMain.on("get-wallpaper", async (event, args) => {
const wpPath: string = await wallpaper.get();
// get the wallpaper and encode it to base64 then return
const wpBase64: string = await readFileSync(wpPath, 'base64')
// add the data:image properties
const wpData: string = `data:image/png;base64,${wpBase64}`
const Jimp = require("jimp")
const img = await Jimp.read(wpPath)
const blurAmount = args.blurAmount ?? 256
if(blurAmount) {
img.blur(blurAmount)
}
const screens = await screen.getAllDisplays()
const width = screens.reduce((a, b) => a + b.size.width, 0)
const height = screens.reduce((a, b) => a + b.size.height, 0)
img.cover(width, height, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_MIDDLE)
const result = await img.getBase64Async(Jimp.MIME_PNG)
event.returnValue = {
path: wpPath,
data: wpData
data: result,
res: {
width: width,
height: height
}
};
})