Implement rudimentary inferment of flash

This commit is contained in:
Jia Hao 2016-02-23 16:46:14 +08:00
parent cf24858ba6
commit 6ca4e794cd
3 changed files with 90 additions and 0 deletions

View File

@ -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
};

View File

@ -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;

View File

@ -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');
}