From 8eaa3a39e08ec1763621889252b5657d42d7de28 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Wed, 27 Jan 2016 10:36:30 +0800 Subject: [PATCH] Allow using png to build for OSX if OS is OSX --- package.json | 2 +- src/buildApp.js | 15 ++++++++++++++- src/helpers.js | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/helpers.js diff --git a/package.json b/package.json index 3eb4302..3a401f6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "clean": "gulp clean", "build": "gulp build", "watch": "while true ; do gulp watch ; done", - "package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --app-name notification-test && open ~/Desktop/notification-test-darwin-x64/notification-test.app", + "package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --app-name notification-test --icon ./test-resources/iconSampleGrey.png && open ~/Desktop/notification-test-darwin-x64/notification-test.app", "start-placeholder": "npm run build && electron app", "release": "gulp release" }, diff --git a/src/buildApp.js b/src/buildApp.js index 13964b1..3548deb 100644 --- a/src/buildApp.js +++ b/src/buildApp.js @@ -3,6 +3,8 @@ import path from 'path'; import crypto from 'crypto'; import optionsFactory from './options'; +import pngToIcns from './getIcon'; +import helpers from './helpers'; import packager from 'electron-packager'; import tmp from 'tmp'; import ncp from 'ncp'; @@ -12,6 +14,7 @@ import _ from 'lodash'; import packageJson from './../package.json'; const copy = ncp.ncp; +const isOSX = helpers.isOSX; /** * @callback buildAppCallback @@ -56,6 +59,17 @@ function buildApp(options, callback) { callback(error, tempDirPath, options); }); }, + (tempDir, options, callback) => { + if (options.platform !== 'darwin' || !isOSX()) { + callback(null, tempDir, options); + return; + } + + pngToIcns(options.icon, (error, icnsPath) => { + options.icon = icnsPath; + callback(error, tempDir, options); + }); + }, (tempDir, options, callback) => { options.dir = tempDir; packager(options, (error, appPathArray) => { @@ -84,7 +98,6 @@ function buildApp(options, callback) { } if (options.platform === 'darwin') { - // todo mac icon copy callback(null, appPath); return; } diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000..ca75a49 --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,9 @@ +import os from 'os'; + +function isOSX() { + return os.platform() === 'darwin'; +} + +export default { + isOSX: isOSX +};