2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-22 18:18:55 +00:00

Implement conversion to ico for windows target

This commit is contained in:
Jia Hao 2016-03-11 13:05:54 +08:00
parent 1862d7cafe
commit 54b251ee1c
3 changed files with 64 additions and 4 deletions

45
bin/convertToIco Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# USAGE
# ./convertToIco <input png or ico> <outfilename>.ico
# Example
# ./convertToPng ~/sample.png ~/converted.ico
set -e
IMAGEMAGICK_CONVERT=$(which convert)
IMAGEMAGICK_IDENTIFY=$(which identify)
if [ ! -x "${IMAGEMAGICK_CONVERT}" ]; then
echo "Cannot find required ImageMagick Convert executable" >&2
exit 1;
fi
if [ ! -x "${IMAGEMAGICK_IDENTIFY}" ]; then
echo "Cannot find required ImageMagick Identify executable" >&2
exit 1;
fi
SOURCE=$1
DEST=$2
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
if [ -z "${DEST}" ]; then
echo "No destination specified"
exit 1
fi
NAME=$(basename "${SOURCE}")
EXT="${NAME##*.}"
BASE="${NAME%.*}"
if [ "${EXT}" == "ico" ]; then
cp "${SOURCE}" "${DEST}"
exit 0
fi
convert "${SOURCE}" "${DEST}"

View File

@ -3,7 +3,7 @@ import helpers from './../helpers/helpers';
import iconShellHelpers from './../helpers/iconShellHelpers';
const {isOSX} = helpers;
const {convertToPng, convertToIcns} = iconShellHelpers;
const {convertToPng, convertToIco, convertToIcns} = iconShellHelpers;
/**
* @callback augmentIconsCallback
@ -30,11 +30,20 @@ function iconBuild(options, callback) {
}
if (options.platform === 'win32') {
if (!iconIsIco(options.icon)) {
console.warn('Icon should be an .ico to package for Windows');
if (iconIsIco(options.icon)) {
returnCallback();
return;
}
returnCallback();
convertToIco(options.icon)
.then(outPath => {
options.icon = outPath;
returnCallback();
})
.catch(error => {
console.warn('Skipping icon conversion to .ico', error);
returnCallback();
});
return;
}

View File

@ -9,6 +9,7 @@ tmp.setGracefulCleanup();
const SCRIPT_PATHS = {
singleIco: path.join(__dirname, '../..', 'bin/singleIco'),
convertToPng: path.join(__dirname, '../..', 'bin/convertToPng'),
convertToIco: path.join(__dirname, '../..', 'bin/convertToIco'),
convertToIcns: path.join(__dirname, '../..', 'bin/convertToIcns')
};
@ -58,6 +59,10 @@ function convertToPng(icoSrc) {
return iconShellHelper(SCRIPT_PATHS.convertToPng, icoSrc, `${getTmpDirPath()}/icon.png`);
}
function convertToIco(icoSrc) {
return iconShellHelper(SCRIPT_PATHS.convertToIco, icoSrc, `${getTmpDirPath()}/icon.ico`);
}
function convertToIcns(icoSrc) {
if (!isOSX()) {
return new Promise((resolve, reject) => reject('OSX is required to convert to a .icns icon'));
@ -68,5 +73,6 @@ function convertToIcns(icoSrc) {
export default {
singleIco,
convertToPng,
convertToIco,
convertToIcns
};