Skip to content

Commit

Permalink
feat: refine the app icon
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Dec 16, 2020
1 parent 0bace35 commit b200c6c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 41 deletions.
36 changes: 32 additions & 4 deletions makefile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const util = require('util')
const chalk = require('chalk')
const packager = require('electron-packager')
const png2icons = require('png2icons')
const app = require('./package.json')

const execa = util.promisify(childProcess.exec)

const logger = {
info(message) {
console.log(chalk.inverse(chalk.blue(' INFO ')) + ' ' + message)
},
done(message) {
console.log(chalk.inverse(chalk.green(' DONE ')) + ' ' + message)
},
warn(message) {
console.log(chalk.inverse(chalk.yellow(' WARN ')) + ' ' + chalk.yellow(message))
},
error(message) {
console.log(chalk.inverse(chalk.red(' ERROR ')) + ' ' + chalk.red(message))
},
}

async function generateAppIcon(input, icon, suffix) {
// Check icon file
const iconPath = `${icon}.${suffix}`
Expand All @@ -17,7 +34,7 @@ async function generateAppIcon(input, icon, suffix) {
// ignore error
}
try {
console.info(`Generating ${suffix.toUpperCase()} icon for application...`)
logger.info(`Generating ${suffix.toUpperCase()} icon for application...`)
const builder = suffix === 'icns' ? png2icons.createICNS : png2icons.createICO
const output = builder(input, png2icons.BICUBIC2, 0, false, true)
await fs.promises.writeFile(iconPath, output)
Expand Down Expand Up @@ -63,14 +80,24 @@ async function getMacOSCodeSign(name) {

async function copyWindowsManifest(dir) {
try {
console.info(`Copying Visual Elements Manifest for Windows...`)
logger.info(`Copying Visual Elements Manifest for Windows...`)
const manifest = `${app.name}.VisualElementsManifest.xml`
await fs.promises.copyFile(`resources/${manifest}`, `${dir}/${manifest}`)
} catch {
// ignore error
}
}

async function compressPackage(dir) {
logger.info(`Packing ${path.basename(dir)}...`)
try {
await fs.promises.unlink(`${dir}.zip`)
} catch {
// ignore error
}
return execa(`zip -ry ${dir}.zip ${dir}/`)
}

async function make() {
// Generate icons
const startedAt = Date.now()
Expand All @@ -93,12 +120,13 @@ async function make() {
if (dir.includes('win32')) {
await copyWindowsManifest(dir)
}
return compressPackage(dir)
})
)
return Date.now() - startedAt
}

make().then(
duration => console.info(`Build finished after ${duration / 1000}s.`),
err => console.error(err),
duration => logger.done(`Build finished after ${duration / 1000}s.`),
err => logger.error(err),
)
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified resources/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions resources/images/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b200c6c

Please sign in to comment.