2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-16 18:15:08 +00:00

Merge branch 'feature/flash' into development

This commit is contained in:
Jia Hao 2016-02-23 21:21:29 +08:00
commit 0c17f19631
7 changed files with 108 additions and 2 deletions

View File

@ -26,6 +26,7 @@ View the changelog [here](https://github.com/jiahaog/nativefier/blob/master/Hist
### Features ### Features
- Automatically retrieves the correct icon and app name - Automatically retrieves the correct icon and app name
- Flash Support
## Installation ## Installation
@ -54,6 +55,10 @@ You need [XCode](https://developer.apple.com/xcode/) installed.
$ brew install imagemagick $ 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 ## Usage
Creating a native desktop app for [medium.com](http://medium.com): 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. Forces the packaged app to ignore web security errors.
#### [flash]
```
--flash <value>
```
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 ## Programmatic API
You can use the Nativefier programmatic API as well. You can use the Nativefier programmatic API as well.

View File

@ -5,6 +5,14 @@ function isOSX() {
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} }
function isLinux() {
return os.platform() === 'linux';
}
function isWindows() {
return os.platform() === 'win32';
}
function linkIsInternal(currentUrl, newUrl) { function linkIsInternal(currentUrl, newUrl) {
var currentDomain = wurl('domain', currentUrl); var currentDomain = wurl('domain', currentUrl);
var newDomain = wurl('domain', newUrl); var newDomain = wurl('domain', newUrl);
@ -13,5 +21,7 @@ function linkIsInternal(currentUrl, newUrl) {
export default { export default {
isOSX, isOSX,
isLinux,
isWindows,
linkIsInternal 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 createLoginWindow from './components/login/loginWindow';
import createMainWindow from './components/mainWindow/mainWindow'; import createMainWindow from './components/mainWindow/mainWindow';
import helpers from './helpers/helpers'; import helpers from './helpers/helpers';
import inferFlash from './helpers/inferFlash';
const {app, ipcMain} = electron; const {app, ipcMain} = electron;
const {isOSX} = helpers; const {isOSX} = helpers;
@ -14,6 +15,13 @@ const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
let mainWindow; 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) { if (appArgs.insecure) {
app.commandLine.appendSwitch('ignore-certificate-errors'); app.commandLine.appendSwitch('ignore-certificate-errors');
} }

View File

@ -52,7 +52,8 @@ function selectAppArgs(options) {
userAgent: options.userAgent, userAgent: options.userAgent,
nativefierVersion: options.nativefierVersion, nativefierVersion: options.nativefierVersion,
insecure: options.insecure, insecure: options.insecure,
disableWebSecurity: options.disableWebSecurity disableWebSecurity: options.disableWebSecurity,
flashPluginDir: options.flashPluginDir
}; };
} }

View File

@ -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('--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('--insecure', 'ignore certificate related errors')
.option('--disable-web-security', 'enable loading of insecure content, defaults to false') .option('--disable-web-security', 'enable loading of insecure content, defaults to false')
.option('--flash <value>', 'path to Chrome flash plugin, find it in `Chrome://plugins`')
.parse(process.argv); .parse(process.argv);
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {

View File

@ -47,7 +47,8 @@ function optionsFactory(inpOptions, callback) {
showMenuBar: inpOptions.showMenuBar || false, showMenuBar: inpOptions.showMenuBar || false,
userAgent: inpOptions.userAgent || getFakeUserAgent(), userAgent: inpOptions.userAgent || getFakeUserAgent(),
insecure: inpOptions.insecure || false, insecure: inpOptions.insecure || false,
disableWebSecurity: inpOptions.disableWebSecurity || false disableWebSecurity: inpOptions.disableWebSecurity || false,
flashPluginDir: inpOptions.flash || null
}; };
if (inpOptions.honest) { if (inpOptions.honest) {