2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-10 23:31:10 +00:00
nativefier/src/helpers/helpers.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

import os from 'os';
import axios from 'axios';
2016-03-12 07:17:03 +00:00
import hasBinary from 'hasbin';
import path from 'path';
function isOSX() {
return os.platform() === 'darwin';
}
function isWindows() {
return os.platform() === 'win32';
}
function downloadFile(fileUrl) {
return axios.get(
fileUrl, {
responseType: 'arraybuffer'
})
.then(function(response) {
2016-03-12 07:17:03 +00:00
if (!response.data) {
return null;
}
return {
data: response.data,
ext: path.extname(fileUrl)
};
});
}
2016-03-12 07:17:03 +00:00
function allowedIconFormats(platform) {
const hasIdentify = hasBinary.sync('identify');
const hasConvert = hasBinary.sync('convert');
const hasIconUtil = hasBinary.sync('iconutil');
const pngToIcns = hasConvert && hasIconUtil;
const pngToIco = hasConvert;
const icoToIcns = pngToIcns && hasIdentify;
const icoToPng = hasConvert;
// todo scripts for the following
const icnsToPng = false;
const icnsToIco = false;
const formats = [];
// todo shell scripting is not supported on windows, temporary override
if (isWindows()) {
switch (platform) {
case 'darwin':
formats.push('.icns');
break;
case 'linux':
formats.push('.png');
break;
case 'win32':
formats.push('.ico');
2016-03-12 07:17:03 +00:00
break;
default:
throw `function allowedIconFormats error: Unknown platform ${platform}`;
}
return formats;
}
switch (platform) {
case 'darwin':
formats.push('.icns');
if (pngToIcns) {
formats.push('.png');
}
if (icoToIcns) {
formats.push('.ico');
}
break;
case 'linux':
formats.push('.png');
if (icoToPng) {
formats.push('.ico');
}
if (icnsToPng) {
formats.push('.icns');
2016-03-12 07:17:03 +00:00
}
break;
case 'win32':
formats.push('.ico');
if (pngToIco) {
formats.push('.png');
}
if (icnsToIco) {
formats.push('.icns');
2016-03-12 07:17:03 +00:00
}
break;
default:
throw `function allowedIconFormats error: Unknown platform ${platform}`;
}
return formats;
}
export default {
isOSX,
isWindows,
2016-03-12 07:17:03 +00:00
downloadFile,
allowedIconFormats
};