2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-09-28 04:19:01 +00:00

Prefer correct extension for page icon

This commit is contained in:
Jia Hao 2016-03-09 14:50:25 +08:00
parent a5e3c5c2f8
commit c3374618d9
2 changed files with 12 additions and 5 deletions

View File

@ -7,11 +7,17 @@ tmp.setGracefulCleanup();
/** /**
* *
* @param {string} targetUrl * @param {string} targetUrl
* @param {string} platform
* @param {string} outDir * @param {string} outDir
* @param {inferIconCallback} callback * @param {inferIconCallback} callback
*/ */
function inferIconFromUrlToPath(targetUrl, outDir, callback) { function inferIconFromUrlToPath(targetUrl, platform, outDir, callback) {
pageIcon(targetUrl, {ext: 'png'}) let preferredExt = 'png';
if (platform === 'win32') {
preferredExt = 'ico';
}
pageIcon(targetUrl, {ext: preferredExt})
.then(icon => { .then(icon => {
const outfilePath = path.join(outDir, `/icon.${icon.ext}`); const outfilePath = path.join(outDir, `/icon.${icon.ext}`);
fs.writeFile(outfilePath, icon.data, error => { fs.writeFile(outfilePath, icon.data, error => {
@ -29,12 +35,13 @@ function inferIconFromUrlToPath(targetUrl, outDir, callback) {
/** /**
* @param {string} targetUrl * @param {string} targetUrl
* @param {string} platform
* @param {inferIconCallback} callback * @param {inferIconCallback} callback
*/ */
function inferIcon(targetUrl, callback) { function inferIcon(targetUrl, platform, callback) {
const tmpObj = tmp.dirSync({unsafeCleanup: true}); const tmpObj = tmp.dirSync({unsafeCleanup: true});
const tmpPath = tmpObj.name; const tmpPath = tmpObj.name;
inferIconFromUrlToPath(targetUrl, tmpPath, callback); inferIconFromUrlToPath(targetUrl, platform, tmpPath, callback);
} }
export default inferIcon; export default inferIcon;

View File

@ -63,7 +63,7 @@ function optionsFactory(inpOptions, callback) {
callback(); callback();
return; return;
} }
inferIcon(options.targetUrl, (error, pngPath) => { inferIcon(options.targetUrl, options.platform, (error, pngPath) => {
if (error) { if (error) {
console.warn('Cannot automatically retrieve the app icon:', error); console.warn('Cannot automatically retrieve the app icon:', error);
} else { } else {