2016-01-28 02:00:28 +00:00
|
|
|
import path from 'path';
|
2016-01-29 06:09:36 +00:00
|
|
|
import helpers from './../helpers/helpers';
|
|
|
|
import pngToIcns from './../helpers/pngToIcns';
|
2016-01-28 02:00:28 +00:00
|
|
|
const isOSX = helpers.isOSX;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @callback augmentIconsCallback
|
|
|
|
* @param error
|
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will check and convert a `.png` to `.icns` if necessary and augment
|
|
|
|
* options.icon with the result
|
|
|
|
*
|
|
|
|
* @param options will need options.platform and options.icon
|
|
|
|
* @param {augmentIconsCallback} callback
|
|
|
|
*/
|
|
|
|
function iconBuild(options, callback) {
|
|
|
|
|
|
|
|
const returnCallback = () => {
|
|
|
|
callback(null, options);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!options.icon) {
|
|
|
|
returnCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.platform !== 'darwin') {
|
2016-01-28 03:47:40 +00:00
|
|
|
if (iconIsPng(options.icon)) {
|
2016-01-28 02:00:28 +00:00
|
|
|
returnCallback();
|
|
|
|
} else {
|
2016-01-28 03:47:40 +00:00
|
|
|
console.warn('Icon should be a png for Linux and Windows apps');
|
2016-01-28 02:00:28 +00:00
|
|
|
returnCallback();
|
|
|
|
}
|
2016-01-28 03:47:40 +00:00
|
|
|
return;
|
2016-01-28 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (iconIsIcns(options.icon)) {
|
|
|
|
returnCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iconIsPng(options.icon)) {
|
|
|
|
|
|
|
|
if (!isOSX()) {
|
|
|
|
console.warn('Conversion of `.png` to `.icns` for OSX app is only supported on OSX');
|
|
|
|
returnCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pngToIcns(options.icon, (error, icnsPath) => {
|
|
|
|
options.icon = icnsPath;
|
|
|
|
if (error) {
|
|
|
|
console.warn('Skipping icon conversion from `.png` to `.icns`: ', error);
|
|
|
|
}
|
|
|
|
returnCallback();
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function iconIsPng(iconPath) {
|
|
|
|
return path.extname(iconPath) === '.png';
|
|
|
|
}
|
|
|
|
|
|
|
|
function iconIsIcns(iconPath) {
|
|
|
|
return path.extname(iconPath) === '.icns';
|
|
|
|
}
|
|
|
|
|
|
|
|
export default iconBuild;
|