Add generation of icons for windows and linux
Signed-off-by: Sebastian Malton <sebastian@malton.name>
@ -22,7 +22,6 @@ function getSvgStyling(colouring: "dark" | "light"): string {
|
|||||||
<style>
|
<style>
|
||||||
ellipse {
|
ellipse {
|
||||||
stroke: ${colouring === "dark" ? "white" : "black"} !important;
|
stroke: ${colouring === "dark" ? "white" : "black"} !important;
|
||||||
fill: ${colouring === "dark" ? "black" : "white"} !important;
|
|
||||||
}
|
}
|
||||||
path, rect {
|
path, rect {
|
||||||
fill: ${colouring === "dark" ? "white" : "black"} !important;
|
fill: ${colouring === "dark" ? "white" : "black"} !important;
|
||||||
@ -31,12 +30,14 @@ function getSvgStyling(colouring: "dark" | "light"): string {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBaseIconImage() {
|
type TargetSystems = "macos" | "windows-or-linux";
|
||||||
|
|
||||||
|
async function getBaseIconImage(system: TargetSystems) {
|
||||||
const svgData = await readFile(inputFile, { encoding: "utf-8" });
|
const svgData = await readFile(inputFile, { encoding: "utf-8" });
|
||||||
const dom = new JSDOM(`<body>${svgData}</body>`);
|
const dom = new JSDOM(`<body>${svgData}</body>`);
|
||||||
const root = dom.window.document.body.getElementsByTagName("svg")[0];
|
const root = dom.window.document.body.getElementsByTagName("svg")[0];
|
||||||
|
|
||||||
root.innerHTML += getSvgStyling("light");
|
root.innerHTML += getSvgStyling(system === "macos" ? "light" : "dark");
|
||||||
|
|
||||||
return Buffer.from(root.outerHTML);
|
return Buffer.from(root.outerHTML);
|
||||||
}
|
}
|
||||||
@ -57,8 +58,8 @@ async function generateImages(image: Buffer, size: number, name: string) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateUpdateAvailableImages(baseImage: Buffer) {
|
async function generateUpdateAvailableImages(baseImage: Buffer, system: TargetSystems) {
|
||||||
const noticeIconImage = await getNoticeIconImage();
|
const noticeIconImage = await getNoticeIconImage(system);
|
||||||
const circleBuffer = await sharp(Buffer.from(`
|
const circleBuffer = await sharp(Buffer.from(`
|
||||||
<svg viewBox="0 0 64 64">
|
<svg viewBox="0 0 64 64">
|
||||||
<circle cx="32" cy="32" r="32" fill="black" />
|
<circle cx="32" cy="32" r="32" fill="black" />
|
||||||
@ -91,11 +92,13 @@ async function generateUpdateAvailableImages(baseImage: Buffer) {
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNoticeIconImage() {
|
async function getNoticeIconImage(system: TargetSystems) {
|
||||||
const svgData = await readFile(noticeFile, { encoding: "utf-8" });
|
const svgData = await readFile(noticeFile, { encoding: "utf-8" });
|
||||||
const noticeSvgRoot = new JSDOM(svgData).window.document.getElementsByTagName("svg")[0];
|
const root = new JSDOM(svgData).window.document.getElementsByTagName("svg")[0];
|
||||||
|
|
||||||
return Buffer.from(noticeSvgRoot.outerHTML);
|
root.innerHTML += getSvgStyling(system === "macos" ? "light" : "dark");
|
||||||
|
|
||||||
|
return Buffer.from(root.outerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateTrayIcons() {
|
async function generateTrayIcons() {
|
||||||
@ -103,12 +106,19 @@ async function generateTrayIcons() {
|
|||||||
console.log("Generating tray icon pngs");
|
console.log("Generating tray icon pngs");
|
||||||
await ensureOutputFoler();
|
await ensureOutputFoler();
|
||||||
|
|
||||||
const baseIconImage = await getBaseIconImage();
|
const baseIconTemplateImage = await getBaseIconImage("macos");
|
||||||
const updateAvailableImage = await generateUpdateAvailableImages(baseIconImage);
|
const updateAvailableTemplateImage = await generateUpdateAvailableImages(baseIconTemplateImage, "macos");
|
||||||
|
const baseIconImage = await getBaseIconImage("windows-or-linux");
|
||||||
|
const updateAvailableImage = await generateUpdateAvailableImages(baseIconImage, "windows-or-linux");
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
generateImages(baseIconImage, size, "trayIconTemplate"),
|
// Templates are for macOS only
|
||||||
generateImages(updateAvailableImage, size, "trayIconUpdateAvailableTemplate"),
|
generateImages(baseIconTemplateImage, size, "trayIconTemplate"),
|
||||||
|
generateImages(updateAvailableTemplateImage, size, "trayIconUpdateAvailableTemplate"),
|
||||||
|
|
||||||
|
// Non-templates are for windows and linux
|
||||||
|
generateImages(baseIconImage, size, "trayIcon"),
|
||||||
|
generateImages(updateAvailableImage, size, "trayIconUpdateAvailable"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
console.log("Generated all images");
|
console.log("Generated all images");
|
||||||
|
|||||||
BIN
build/tray/trayIcon.png
Normal file
|
After Width: | Height: | Size: 392 B |
BIN
build/tray/trayIcon@2x.png
Normal file
|
After Width: | Height: | Size: 724 B |
BIN
build/tray/trayIcon@3x.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
build/tray/trayIcon@4x.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
build/tray/trayIconUpdateAvailable.png
Normal file
|
After Width: | Height: | Size: 518 B |
BIN
build/tray/trayIconUpdateAvailable@2x.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
build/tray/trayIconUpdateAvailable@3x.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
build/tray/trayIconUpdateAvailable@4x.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |