mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* unify build fs layout Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use currentApp path for static files Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to import open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to customize both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix compile-library script Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove bundled extensions Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * similar interface for both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use startApp on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * Fix injection cycle (somehow) Signed-off-by: Sebastian Malton <sebastian@malton.name> * use cwd in download_binaries Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce applicationInformationToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * register applicationInformationInjectable in main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to define bundled extensions via appStart Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * compile node-fetch automatically via prepare Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * define peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * rename application-information-token.injectable.ts -> application-information-token.ts Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * monaco-editor as externals Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor application-information Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce bundledExtensionInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * mark library exports as experimental Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move extension npm package files & add release automation Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add missing build files to package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix bad merge conflict resolve Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix package.json name Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to set mode via startApp Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * revert unnecessary changes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack: fix extensionOutDir Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove unnecessary peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce nodeEnvInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove NODE_ENV from environmentVariablesInjectable Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix jest modulePathIgnorePatterns Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix duplicate injectable registration Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build executableName Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <sebastian@malton.name>
140 lines
4.6 KiB
TypeScript
140 lines
4.6 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import { ensureDir, readFile } from "fs-extra";
|
|
import { JSDOM } from "jsdom";
|
|
import path from "path";
|
|
import sharp from "sharp";
|
|
|
|
const size = Number(process.env.OUTPUT_SIZE || "16");
|
|
const outputFolder = process.env.OUTPUT_DIR || "./static/build/tray";
|
|
const inputFile = process.env.INPUT_SVG_PATH || path.resolve(__dirname, "../src/renderer/components/icon/logo-lens.svg");
|
|
const noticeFile = process.env.NOTICE_SVG_PATH || path.resolve(__dirname, "../src/renderer/components/icon/notice.svg");
|
|
const spinnerFile = process.env.SPINNER_SVG_PATH || path.resolve(__dirname, "../src/renderer/components/icon/arrow-spinner.svg");
|
|
|
|
async function ensureOutputFoler() {
|
|
await ensureDir(outputFolder);
|
|
}
|
|
|
|
function getSvgStyling(colouring: "dark" | "light"): string {
|
|
return `
|
|
<style>
|
|
ellipse {
|
|
stroke: ${colouring === "dark" ? "white" : "black"} !important;
|
|
}
|
|
path, rect {
|
|
fill: ${colouring === "dark" ? "white" : "black"} !important;
|
|
}
|
|
</style>
|
|
`;
|
|
}
|
|
|
|
type TargetSystems = "macos" | "windows-or-linux";
|
|
|
|
async function getBaseIconImage(system: TargetSystems) {
|
|
const svgData = await readFile(inputFile, { encoding: "utf-8" });
|
|
const dom = new JSDOM(`<body>${svgData}</body>`);
|
|
const root = dom.window.document.body.getElementsByTagName("svg")[0];
|
|
|
|
root.innerHTML += getSvgStyling(system === "macos" ? "light" : "dark");
|
|
|
|
return Buffer.from(root.outerHTML);
|
|
}
|
|
|
|
async function generateImage(image: Buffer, size: number, namePrefix: string) {
|
|
sharp(image)
|
|
.resize({ width: size, height: size })
|
|
.png()
|
|
.toFile(path.join(outputFolder, `${namePrefix}.png`));
|
|
}
|
|
|
|
async function generateImages(image: Buffer, size: number, name: string) {
|
|
await Promise.all([
|
|
generateImage(image, size, name),
|
|
generateImage(image, size*2, `${name}@2x`),
|
|
generateImage(image, size*3, `${name}@3x`),
|
|
generateImage(image, size*4, `${name}@4x`),
|
|
]);
|
|
}
|
|
|
|
async function generateImageWithSvg(baseImage: Buffer, system: TargetSystems, filePath: string) {
|
|
const svgFile = await getIconImage(system, filePath);
|
|
|
|
const circleBuffer = await sharp(Buffer.from(`
|
|
<svg viewBox="0 0 64 64">
|
|
<circle cx="32" cy="32" r="32" fill="black" />
|
|
</svg>
|
|
`))
|
|
.toBuffer();
|
|
|
|
return sharp(baseImage)
|
|
.resize({ width: 128, height: 128 })
|
|
.composite([
|
|
{
|
|
input: circleBuffer,
|
|
top: 64,
|
|
left: 64,
|
|
blend: "dest-out",
|
|
},
|
|
{
|
|
input: (
|
|
await sharp(svgFile)
|
|
.resize({
|
|
width: 60,
|
|
height: 60,
|
|
})
|
|
.toBuffer()
|
|
),
|
|
top: 66,
|
|
left: 66,
|
|
},
|
|
])
|
|
.toBuffer();
|
|
}
|
|
|
|
async function getIconImage(system: TargetSystems, filePath: string) {
|
|
const svgData = await readFile(filePath, { encoding: "utf-8" });
|
|
const root = new JSDOM(svgData).window.document.getElementsByTagName("svg")[0];
|
|
|
|
root.innerHTML += getSvgStyling(system === "macos" ? "light" : "dark");
|
|
|
|
return Buffer.from(root.outerHTML);
|
|
}
|
|
|
|
async function generateTrayIcons() {
|
|
try {
|
|
console.log("Generating tray icon pngs");
|
|
await ensureOutputFoler();
|
|
|
|
const baseIconTemplateImage = await getBaseIconImage("macos");
|
|
const baseIconImage = await getBaseIconImage("windows-or-linux");
|
|
|
|
const updateAvailableTemplateImage = await generateImageWithSvg(baseIconTemplateImage, "macos", noticeFile);
|
|
const updateAvailableImage = await generateImageWithSvg(baseIconImage, "windows-or-linux", noticeFile);
|
|
|
|
const checkingForUpdatesTemplateImage = await generateImageWithSvg(baseIconTemplateImage, "macos", spinnerFile);
|
|
const checkingForUpdatesImage = await generateImageWithSvg(baseIconImage, "windows-or-linux", spinnerFile);
|
|
|
|
await Promise.all([
|
|
// Templates are for macOS only
|
|
generateImages(baseIconTemplateImage, size, "trayIconTemplate"),
|
|
generateImages(updateAvailableTemplateImage, size, "trayIconUpdateAvailableTemplate"),
|
|
generateImages(updateAvailableTemplateImage, size, "trayIconUpdateAvailableTemplate"),
|
|
generateImages(checkingForUpdatesTemplateImage, size, "trayIconCheckingForUpdatesTemplate"),
|
|
|
|
// Non-templates are for windows and linux
|
|
generateImages(baseIconImage, size, "trayIcon"),
|
|
generateImages(updateAvailableImage, size, "trayIconUpdateAvailable"),
|
|
generateImages(checkingForUpdatesImage, size, "trayIconCheckingForUpdates"),
|
|
]);
|
|
|
|
console.log("Generated all images");
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
generateTrayIcons();
|