Skip to content

Commit

Permalink
added ability to skip if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Nov 3, 2024
1 parent a4eb01e commit 76d19dc
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/nexrender-action-fonts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,46 @@ const path = require("path");
const { execSync } = require("child_process");
const { name } = require("./package.json");

const installMac = async (job, fontpath) => {
const installMac = async (settings, job, fontpath) => {
const fontdir = path.join(process.env.HOME, "Library", "Fonts");

if (!fs.existsSync(fontdir)) {
fs.mkdirSync(fontdir, { recursive: true });
}

if (fs.existsSync(fontpath)) {
settings.logger.log(`[action-fonts] Font ${fontpath} already exists, skipping.`);
return 0;
}

settings.logger.log(`[action-fonts] Installing font ${fontpath} to ${fontdir}...`);
fs.copyFileSync(fontpath, path.join(fontdir, path.basename(fontpath)));

return 1;
};

const installWin = async (job, fontpath) => {
const installWin = async (settings, job, fontpath) => {
const fontdir = path.join(process.env.LOCALAPPDATA, "Microsoft", "Windows", "Fonts");

if (!fs.existsSync(fontdir)) {
fs.mkdirSync(fontdir, { recursive: true });
}

if (fs.existsSync(fontpath)) {
settings.logger.log(`[action-fonts] Font ${fontpath} already exists, skipping.`);
return 0;
}

settings.logger.log(`[action-fonts] Installing font ${fontpath} to ${fontdir}...`);

const fontdest = path.join(fontdir, path.basename(fontpath));
fs.copyFileSync(fontpath, fontdest);

const fontdisplayname = path.basename(fontpath, path.extname(fontpath)).replace(/-/g, " ");
const fontreg = `reg add "HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" /v "${fontdisplayname} (TrueType)" /t REG_SZ /d "${fontdest}" /f`;

execSync(fontreg);
return 1;
};

const notifyWin = async (job) => {
Expand Down Expand Up @@ -64,14 +80,12 @@ module.exports = async (job, settings, params, type) => {
}

if (process.platform === "darwin") {
await installMac(job, asset.dest);
fontsAdded += await installMac(settings, job, asset.dest);
} else if (process.platform === "win32") {
await installWin(job, asset.dest);
fontsAdded += await installWin(settings, job, asset.dest);
} else {
throw new Error(`Platform ${process.platform} is not supported.`);
}

fontsAdded++;
}

if (fontsAdded > 0 && process.platform === "win32") {
Expand Down

0 comments on commit 76d19dc

Please sign in to comment.