diff --git a/README.md b/README.md index 77ea078..1cf2cec 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ View the changelog [here](https://github.com/jiahaog/nativefier/blob/master/Hist ### Features - Automatically retrieves the correct icon and app name +- Flash Support ## Installation @@ -54,6 +55,10 @@ You need [XCode](https://developer.apple.com/xcode/) installed. $ brew install imagemagick ``` +##### [Google Chrome](https://www.google.com/chrome/) + +Google Chrome is required for flash to be supported. Alternatively, you could download the PepperFlash Chrome plugin and specify the path to it directly with the `--flash` flag. See the command line options below for more details. + ## Usage Creating a native desktop app for [medium.com](http://medium.com): @@ -237,6 +242,14 @@ Forces the packaged app to ignore certificate errors. ``` Forces the packaged app to ignore web security errors. +#### [flash] + +``` +--flash +``` + +By default, nativefier will automatically try to determine the location of your Google Chrome flash binary. In the event that Flash does not appear to work, you can specify it directly with this command line flag, by retrieving the location of the Flash path from [chrome://plugins](chrome://plugins), under `Adobe Flash Player` > `Location`. + ## Programmatic API You can use the Nativefier programmatic API as well. diff --git a/app/src/helpers/helpers.js b/app/src/helpers/helpers.js index ed8327f..3683679 100644 --- a/app/src/helpers/helpers.js +++ b/app/src/helpers/helpers.js @@ -5,6 +5,14 @@ function isOSX() { return os.platform() === 'darwin'; } +function isLinux() { + return os.platform() === 'linux'; +} + +function isWindows() { + return os.platform() === 'win32'; +} + function linkIsInternal(currentUrl, newUrl) { var currentDomain = wurl('domain', currentUrl); var newDomain = wurl('domain', newUrl); @@ -13,5 +21,7 @@ function linkIsInternal(currentUrl, newUrl) { export default { isOSX, + isLinux, + isWindows, linkIsInternal }; diff --git a/app/src/helpers/inferFlash.js b/app/src/helpers/inferFlash.js new file mode 100644 index 0000000..fac26a6 --- /dev/null +++ b/app/src/helpers/inferFlash.js @@ -0,0 +1,72 @@ +import fs from 'fs'; +import path from 'path'; +import helpers from './helpers'; + +const {isOSX, isWindows, isLinux} = helpers; + +function inferFlash() { + if (isOSX()) { + return darwinMatch(); + } + + if (isWindows()) { + return windowsMatch(); + } + + if (isLinux()) { + return linuxMatch(); + } + + console.warn('Unable to determine OS to infer flash player'); +} + +/** + * Synchronously find a file or directory + * @param {RegExp} pattern regex + * @param {string} base path + * @param {boolean} [findDir] if true, search results will be limited to only directories + * @returns {Array} + */ +function findSync(pattern, base, findDir) { + const matches = []; + (function findSyncRecurse(base) { + const children = fs.readdirSync(base); + children.forEach(child => { + const childPath = path.join(base, child); + const childIsDirectory = fs.lstatSync(childPath).isDirectory(); + const patternMatches = pattern.test(childPath); + + if (!patternMatches) { + if (!childIsDirectory) { + return; + } + findSyncRecurse(childPath); + return; + } + + if (!findDir) { + matches.push(childPath); + return; + } + + if (childIsDirectory) { + matches.push(childPath); + } + }); + })(base); + return matches; +} + +function linuxMatch() { + return findSync(/libpepflashplayer\.so/, '/opt/google/chrome')[0]; +} + +function windowsMatch() { + return findSync(/pepflashplayer\.dll/, 'C:\\Program Files (x86)\\Google\\Chrome')[0]; +} + +function darwinMatch() { + return findSync(/PepperFlashPlayer.plugin/, '/Applications/Google Chrome.app/', true)[0]; +} + +export default inferFlash; diff --git a/app/src/main.js b/app/src/main.js index 5355f97..c78e2c3 100644 --- a/app/src/main.js +++ b/app/src/main.js @@ -5,6 +5,7 @@ import electron from 'electron'; import createLoginWindow from './components/login/loginWindow'; import createMainWindow from './components/mainWindow/mainWindow'; import helpers from './helpers/helpers'; +import inferFlash from './helpers/inferFlash'; const {app, ipcMain} = electron; const {isOSX} = helpers; @@ -14,6 +15,13 @@ const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8')); let mainWindow; +if (appArgs.flashPluginDir) { + app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir); +} else { + const flashPath = inferFlash(); + app.commandLine.appendSwitch('ppapi-flash-path', flashPath); +} + if (appArgs.insecure) { app.commandLine.appendSwitch('ignore-certificate-errors'); } diff --git a/src/build/buildApp.js b/src/build/buildApp.js index 37ea407..9782c2f 100644 --- a/src/build/buildApp.js +++ b/src/build/buildApp.js @@ -52,7 +52,8 @@ function selectAppArgs(options) { userAgent: options.userAgent, nativefierVersion: options.nativefierVersion, insecure: options.insecure, - disableWebSecurity: options.disableWebSecurity + disableWebSecurity: options.disableWebSecurity, + flashPluginDir: options.flashPluginDir }; } diff --git a/src/cli.js b/src/cli.js index a1c543b..a482dd4 100755 --- a/src/cli.js +++ b/src/cli.js @@ -30,6 +30,7 @@ if (require.main === module) { .option('--honest', 'prevent the nativefied app from changing the user agent string to masquerade as a regular chrome browser') .option('--insecure', 'ignore certificate related errors') .option('--disable-web-security', 'enable loading of insecure content, defaults to false') + .option('--flash ', 'path to Chrome flash plugin, find it in `Chrome://plugins`') .parse(process.argv); if (!process.argv.slice(2).length) { diff --git a/src/options/optionsMain.js b/src/options/optionsMain.js index 03a2fe8..838bb5b 100644 --- a/src/options/optionsMain.js +++ b/src/options/optionsMain.js @@ -47,7 +47,8 @@ function optionsFactory(inpOptions, callback) { showMenuBar: inpOptions.showMenuBar || false, userAgent: inpOptions.userAgent || getFakeUserAgent(), insecure: inpOptions.insecure || false, - disableWebSecurity: inpOptions.disableWebSecurity || false + disableWebSecurity: inpOptions.disableWebSecurity || false, + flashPluginDir: inpOptions.flash || null }; if (inpOptions.honest) {