From 6ca4e794cdbc5b4884cd2c05b9a56f1c4e139cd1 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Tue, 23 Feb 2016 16:46:14 +0800 Subject: [PATCH] Implement rudimentary inferment of flash --- app/src/helpers/helpers.js | 10 +++++ app/src/helpers/inferFlash.js | 72 +++++++++++++++++++++++++++++++++++ app/src/main.js | 8 ++++ 3 files changed, 90 insertions(+) create mode 100644 app/src/helpers/inferFlash.js 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..9cda7b9 --- /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'); }