├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── lib ├── flash-loader.coffee └── flash-loader.js ├── package.json └── test ├── index.html └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Alvin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flash Player Loader (for electron apps) 2 | 3 | Makes life easier for the [electron](http://electron.atom.io/) apps which need the [Pepper Flash Player][1]. 4 | 5 | The path to the Flash Player for your app usually differs between develop (git) version and release (packed) version. 6 | This module manages multiple sources for you, and provides extra debug information and error handling. 7 | Plus some handy features (_OS X only_) like automatically locate the Flash Player and get the version of it. 8 | 9 | More details can be found at 10 | [electron docs](https://github.com/atom/electron/blob/master/docs/tutorial/using-pepper-flash-plugin.md). 11 | 12 | ## Installation 13 | 14 | ```sh 15 | npm install --save flash-player-loader 16 | ``` 17 | 18 | To run the example app: 19 | ``` 20 | cd /path/to/flash-player-loader 21 | npm install 22 | electron test 23 | ``` 24 | To run the example app with extra debug output: 25 | ``` 26 | electron test -d 27 | ``` 28 | 29 | ## Usage 30 | 31 | ```js 32 | var flashLoader = require('flash-player-loader'); 33 | var path = '/path/to/dir/contains/flash/player'; 34 | flashLoader.addSource(path); 35 | flashLoader.addSource('/alternative/path'); 36 | flashLoader.load(); 37 | ``` 38 | 39 | Alternatively, you can chain the methods together. 40 | ```js 41 | require('flash-player-loader').addSource('/path/to/dir').load(); 42 | ``` 43 | 44 | _**Do not forget to add the `'web-preferences': {'plugins': true}` option 45 | when creating your BrowserWindow.**_ 46 | 47 | See `test/index.js` for more detailed example and explanations. 48 | 49 | ## Get Pepper Flash Player Plug-in 50 | 51 | * Install [Google Chrome](https://www.google.com/chrome/browser/desktop/index.html). 52 | You can find the path to the Pepper Flash Player in the `chrome://plugins` tab. 53 | * Install the _PPAPI_ [system plug-in][2]. 54 | * You can also download and install any older version of the plug-in from [here][3]. 55 | 56 | ## Troubleshooting 57 | 58 | ##### The path added is correct, but it doesn't load the plug-in 59 | 1. Please make sure that you are not mixing the architecture of electron and Flash Player. 60 | That is, 32-bit electron will not work with 64-bit Flash Player, and vice versa. 61 | 2. Please make sure that you have included the option 62 | `'web-preferences': {'plugins': true}` when creating BrowserWindow. 63 | 64 | ## API 65 | 66 | ### `flashLoader.getFilename()` 67 | 68 | Returns the Flash Player filename according to the running OS. 69 | 70 | ### `flashLoader.addSource(location[, version])` 71 | 72 | * `location` String 73 | * `version` String (optional) 74 | 75 | Adds the location of Pepper Flash Player. 76 | 77 | _This method can be called multiple times. 78 | All added sources will be validated in the order they are added, 79 | until the first valid one is found._ 80 | 81 | The `location` is the _path to the **directory** contains the Pepper Flash Player file_, 82 | or the _full path to the Pepper Flash Player file_ 83 | (The filename has to match the string returned by `flashLoader.getFilename()`). 84 | If you have **electron v1.2.3** or newer, you can also specify `"@system"` for `location`. It will then look for the 85 | [Pepper Flash Player system plug-in][2] (**PPAPI**). 86 | If `location` is omitted, `'.'` will be used, i.e., the working directory, where you started your app. 87 | On **_OS X_**, you can always specify `"@chrome"` or `"@system"` for `location`. 88 | If `"@chrome"` is specified, it will automatically look for the [Pepper Flash Player][1] 89 | integrated by the newest installed Google Chrome. 90 | `"@system"` works for all versions of electron. 91 | 92 | You can optionally pass in a version string, which will be passed to 93 | [Chromium](http://www.chromium.org) with the `ppapi-flash-version` switch. 94 | _Note:_ 95 | 1) Google Chrome uses this version number to decide which Flash Player to load, 96 | and for displaying. However, for (most) electron apps, it's useless. 97 | *It's safe to ignore the version string.* 98 | 2) On **_OS X_**, the Flash Player version is automatically detected. 99 | The passed in string is **ignored**. 100 | 101 | _This method returns `this`, so it's possible to chain it._ 102 | 103 | ### `flashLoader.load()` 104 | 105 | Validates the source(s) added by `addSource()`, in the order they are added. 106 | The first valid one will be loaded. 107 | 108 | ### `flashLoader.debug([options])` 109 | 110 | * `options` Object 111 | * `enable` Boolean - Enable/Disable debug mode. Default is `true`. 112 | * `log` Function - Customised log function. Default is `console.log`. 113 | * `error` Function - Customised error function. Default is `console.error`. 114 | 115 | Enable or disable debug mode. 116 | When enabled, extra information and error messages will be print to the console. 117 | You can also specify a customised log/error function, 118 | to make the output format match other output of your app, 119 | or log the information in other forms (e.g., write to a log file). 120 | _Note you may need to use `bind` to make you log function callable._ 121 | _(See the example app for instance.)_ 122 | 123 | _This method returns `this`, so it's possible to chain it._ 124 | 125 | ### `flashLoader.getVersion(location)` _OS X_ 126 | 127 | * `location` String 128 | 129 | Returns the version of the Flash Player found at the specified location. 130 | An empty string is returned if the location is invalid. 131 | 132 | 133 | [1]: https://helpx.adobe.com/flash-player/kb/flash-player-google-chrome.html "Flash Player with Google Chrome" 134 | [2]: https://get.adobe.com/flashplayer/otherversions/ "Download Pepper Flash Player system plug-in" 135 | [3]: https://helpx.adobe.com/flash-player/kb/archived-flash-player-versions.html "Download archived Pepper Flash Player" 136 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/flash-loader'); 3 | -------------------------------------------------------------------------------- /lib/flash-loader.coffee: -------------------------------------------------------------------------------- 1 | electron = require 'electron' 2 | app = if process.type is 'browser' then electron.app else electron.remote.app 3 | {join, resolve} = require 'path' 4 | fs = require 'fs' 5 | 6 | doNothing = -> 7 | log = error = doNothing 8 | 9 | debugOld = (logFunc, errFunc) -> 10 | if typeof logFunc is 'function' 11 | log = error = logFunc 12 | else 13 | log = console.log.bind console 14 | error = console.error.bind console 15 | error = errFunc if typeof errFunc is 'function' 16 | log 'Debugging Flash Loader' 17 | log '[DEPRECATED] `debug(logFunc, errFunc)` is deprecated. Please call `debug(options)` instead.' 18 | @ 19 | debug = (options = {}) -> 20 | return debugOld.apply(@, arguments) if typeof options isnt 'object' 21 | options.enable ?= true 22 | if options.enable 23 | log = if options.log? then options.log else console.log.bind console 24 | error = if options.error? then options.error else console.error.bind console 25 | else 26 | log = error = doNothing 27 | log 'Debugging Flash Loader' 28 | @ 29 | 30 | PLATFORM = process.platform 31 | FILENAME = switch PLATFORM 32 | when 'darwin' then 'PepperFlashPlayer.plugin' 33 | when 'linux' then 'libpepflashplayer.so' 34 | when 'win32' then 'pepflashplayer.dll' 35 | 36 | # `path` can be the full path to the file, 37 | # or the path to the dir contains the file. 38 | # Returns the validated path string, or null if `path` is not valid. 39 | validatePath = (path) -> 40 | p = path 41 | try 42 | fs.accessSync p 43 | stats = fs.statSync p 44 | if stats.isDirectory() 45 | p = join path, FILENAME 46 | fs.accessSync p 47 | catch 48 | return null 49 | p 50 | 51 | 52 | reVerNum = /(\d+)\.(\d+)\.(\d+)\.(\d+)/ 53 | getNewerVersion = (ver1, ver2) -> 54 | v1 = reVerNum.exec ver1 55 | v2 = reVerNum.exec ver2 56 | if not v1 57 | return if v2 then ver2 else '' 58 | for i in [1..4] 59 | continue if v1[i] == v2[i] 60 | return if parseInt(v1[i]) > parseInt(v2[i]) then ver1 else ver2 61 | ver1 # Exactly the same version 62 | 63 | findChromeFlashPath = (getAll = false) -> 64 | # Refer to: https://helpx.adobe.com/flash-player/kb/flash-player-google-chrome.html 65 | switch PLATFORM 66 | when 'darwin' 67 | if getAll 68 | paths = [] 69 | try 70 | flashDir = join app.getPath('appData'), 'Google/Chrome/PepperFlash' 71 | flashVersions = fs.readdirSync flashDir 72 | for ver in flashVersions 73 | paths.push(join flashDir, ver) 74 | try 75 | # Usually there are 2 directories under the 'Versions' directory, 76 | # all named after their respective Google Chrome version number. 77 | # Find the newest version of Google Chrome 78 | # and use its built-in Pepper Flash Player plugin. 79 | chromeVersionsDir = '/Applications/Google Chrome.app/Contents/Versions' 80 | internalFlashDir = 'Google Chrome Framework.framework/Internet Plug-Ins/PepperFlash' 81 | chromeVersions = fs.readdirSync chromeVersionsDir 82 | if not getAll 83 | return null if chromeVersions.length is 0 # Broken Chrome... 84 | chromeVer = chromeVersions.reduce getNewerVersion 85 | chromeFlashPath = join chromeVersionsDir, chromeVer, internalFlashDir 86 | fs.accessSync chromeFlashPath 87 | chromeFlashPath 88 | else 89 | for ver in chromeVersions 90 | paths.push(join chromeVersionsDir, ver, internalFlashDir) 91 | paths.map(validatePath).filter (x) -> x 92 | catch 93 | null 94 | else null 95 | 96 | findSystemFlashPath = -> 97 | # Download/install from: https://get.adobe.com/flashplayer/otherversions/ 98 | try 99 | # Since Electron v1.2.3, you can get system Flash path in this way 100 | systemFlashPath = app.getPath 'pepperFlashSystemPlugin' 101 | fs.accessSync systemFlashPath 102 | systemFlashPath 103 | catch 104 | # Backwards compatible 105 | if PLATFORM is 'darwin' 106 | try 107 | systemFlashPath = '/Library/Internet Plug-Ins/PepperFlashPlayer' 108 | fs.accessSync systemFlashPath 109 | systemFlashPath 110 | catch 111 | null 112 | else null 113 | 114 | getFlashVersion = (loc) -> 115 | return '' if typeof loc isnt 'string' 116 | path = switch loc.toLowerCase() 117 | when '@chrome' then findChromeFlashPath() 118 | when '@system' then findSystemFlashPath() 119 | else loc 120 | path = validatePath path 121 | return '' if not path 122 | switch PLATFORM 123 | when 'darwin' 124 | # The version info is in the Info.plist inside PepperFlashPlayer.plugin 125 | plistPath = join path, 'Contents', 'Info.plist' 126 | plistContent = fs.readFileSync(plistPath, 'utf8') 127 | match = /CFBundleVersion<\/key>\s*(\d+(?:\.\d+)*)<\/string>/.exec plistContent 128 | if match and match.length > 1 then match[1] else '' 129 | else '' 130 | 131 | getAllChromeFlashVersions = -> 132 | paths = findChromeFlashPath true 133 | if paths then paths.map (p) -> [getFlashVersion(p), p] else [] 134 | 135 | flashSources = [] 136 | usingIndex = -1 137 | addSource = (location = '.', version) -> 138 | if typeof location is 'string' 139 | o = loc: location 140 | if version? 141 | if typeof version is 'string' and reVerNum.test version 142 | o.ver = version 143 | else 144 | error "Invalid version string for #{location}: #{version}" 145 | flashSources.push o 146 | else 147 | error "'#{location}' is not a valid location string!" 148 | @ 149 | 150 | getPath = (loc) -> 151 | if loc? 152 | switch loc.toLowerCase() 153 | when '@chrome' 154 | flashPath = findChromeFlashPath() 155 | errMsg = 'Could not load Chrome integrated Pepper Flash Player plug-in' 156 | when '@system' 157 | flashPath = findSystemFlashPath() 158 | errMsg = 'Could not load Pepper Flash Player system plug-in' 159 | else 160 | flashPath = loc 161 | errMsg = "Could not load '#{FILENAME}' from: \n#{loc}" 162 | else 163 | if flashSources.length is 0 164 | errMsg = 'No source has been added. Please call `addSource()` \ 165 | to add the location where Flash Player can be found.' 166 | for src, i in flashSources 167 | flashPath = getPath src.loc 168 | usingIndex = i 169 | break if flashPath? 170 | flashPath = validatePath flashPath 171 | error errMsg if errMsg? and not flashPath? 172 | flashPath 173 | 174 | load = -> 175 | flashPath = getPath() 176 | if flashPath? 177 | log "Loading Pepper Flash Player: \n#{resolve flashPath}" 178 | app.commandLine.appendSwitch 'ppapi-flash-path', flashPath 179 | # Note: the 'ppapi-flash-version' switch is used by Google Chrome to decide 180 | # which flash player to load (it'll choose the newest one), and display in 181 | # the 'chrome://version', 'chrome://plugins', 'chrome://flash' pages. 182 | # However, for (most) electron apps, it's useless. It's safe to ignore it. 183 | ver = getFlashVersion flashPath 184 | ver = flashSources[usingIndex].ver if usingIndex >= 0 and not ver 185 | if ver 186 | log "Pepper Flash Player version: #{ver}" 187 | app.commandLine.appendSwitch 'ppapi-flash-version', ver 188 | 189 | if process.type is 'browser' 190 | exports.addSource = addSource 191 | exports.load = load 192 | 193 | exports.debug = debug 194 | exports.getFilename = () -> FILENAME 195 | exports.getVersion = getFlashVersion 196 | exports.getAllChromeFlashVersions = getAllChromeFlashVersions 197 | -------------------------------------------------------------------------------- /lib/flash-loader.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.10.0 2 | (function() { 3 | var FILENAME, PLATFORM, addSource, app, debug, debugOld, doNothing, electron, error, findChromeFlashPath, findSystemFlashPath, flashSources, fs, getAllChromeFlashVersions, getFlashVersion, getNewerVersion, getPath, join, load, log, reVerNum, ref, resolve, usingIndex, validatePath; 4 | 5 | electron = require('electron'); 6 | 7 | app = process.type === 'browser' ? electron.app : electron.remote.app; 8 | 9 | ref = require('path'), join = ref.join, resolve = ref.resolve; 10 | 11 | fs = require('fs'); 12 | 13 | doNothing = function() {}; 14 | 15 | log = error = doNothing; 16 | 17 | debugOld = function(logFunc, errFunc) { 18 | if (typeof logFunc === 'function') { 19 | log = error = logFunc; 20 | } else { 21 | log = console.log.bind(console); 22 | error = console.error.bind(console); 23 | } 24 | if (typeof errFunc === 'function') { 25 | error = errFunc; 26 | } 27 | log('Debugging Flash Loader'); 28 | log('[DEPRECATED] `debug(logFunc, errFunc)` is deprecated. Please call `debug(options)` instead.'); 29 | return this; 30 | }; 31 | 32 | debug = function(options) { 33 | if (options == null) { 34 | options = {}; 35 | } 36 | if (typeof options !== 'object') { 37 | return debugOld.apply(this, arguments); 38 | } 39 | if (options.enable == null) { 40 | options.enable = true; 41 | } 42 | if (options.enable) { 43 | log = options.log != null ? options.log : console.log.bind(console); 44 | error = options.error != null ? options.error : console.error.bind(console); 45 | } else { 46 | log = error = doNothing; 47 | } 48 | log('Debugging Flash Loader'); 49 | return this; 50 | }; 51 | 52 | PLATFORM = process.platform; 53 | 54 | FILENAME = (function() { 55 | switch (PLATFORM) { 56 | case 'darwin': 57 | return 'PepperFlashPlayer.plugin'; 58 | case 'linux': 59 | return 'libpepflashplayer.so'; 60 | case 'win32': 61 | return 'pepflashplayer.dll'; 62 | } 63 | })(); 64 | 65 | validatePath = function(path) { 66 | var error1, p; 67 | p = path; 68 | try { 69 | fs.accessSync(p); 70 | if (!p.endsWith(FILENAME)) { 71 | p = join(path, FILENAME); 72 | fs.accessSync(p); 73 | } 74 | } catch (error1) { 75 | return null; 76 | } 77 | return p; 78 | }; 79 | 80 | reVerNum = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; 81 | 82 | getNewerVersion = function(ver1, ver2) { 83 | var i, j, v1, v2; 84 | v1 = reVerNum.exec(ver1); 85 | v2 = reVerNum.exec(ver2); 86 | if (!v1) { 87 | if (v2) { 88 | return ver2; 89 | } else { 90 | return ''; 91 | } 92 | } 93 | for (i = j = 1; j <= 4; i = ++j) { 94 | if (v1[i] === v2[i]) { 95 | continue; 96 | } 97 | if (parseInt(v1[i]) > parseInt(v2[i])) { 98 | return ver1; 99 | } else { 100 | return ver2; 101 | } 102 | } 103 | return ver1; 104 | }; 105 | 106 | findChromeFlashPath = function(getAll) { 107 | var chromeFlashPath, chromeVer, chromeVersions, chromeVersionsDir, error1, flashDir, flashVersions, internalFlashDir, j, k, len, len1, paths, ver; 108 | if (getAll == null) { 109 | getAll = false; 110 | } 111 | switch (PLATFORM) { 112 | case 'darwin': 113 | if (getAll) { 114 | paths = []; 115 | try { 116 | flashDir = join(app.getPath('appData'), 'Google/Chrome/PepperFlash'); 117 | flashVersions = fs.readdirSync(flashDir); 118 | for (j = 0, len = flashVersions.length; j < len; j++) { 119 | ver = flashVersions[j]; 120 | paths.push(join(flashDir, ver)); 121 | } 122 | } catch (undefined) {} 123 | } 124 | try { 125 | chromeVersionsDir = '/Applications/Google Chrome.app/Contents/Versions'; 126 | internalFlashDir = 'Google Chrome Framework.framework/Internet Plug-Ins/PepperFlash'; 127 | chromeVersions = fs.readdirSync(chromeVersionsDir); 128 | if (!getAll) { 129 | if (chromeVersions.length === 0) { 130 | return null; 131 | } 132 | chromeVer = chromeVersions.reduce(getNewerVersion); 133 | chromeFlashPath = join(chromeVersionsDir, chromeVer, internalFlashDir); 134 | fs.accessSync(chromeFlashPath); 135 | return chromeFlashPath; 136 | } else { 137 | for (k = 0, len1 = chromeVersions.length; k < len1; k++) { 138 | ver = chromeVersions[k]; 139 | paths.push(join(chromeVersionsDir, ver, internalFlashDir)); 140 | } 141 | return paths.map(validatePath).filter(function(x) { 142 | return x; 143 | }); 144 | } 145 | } catch (error1) { 146 | return null; 147 | } 148 | break; 149 | default: 150 | return null; 151 | } 152 | }; 153 | 154 | findSystemFlashPath = function() { 155 | var error1, error2, systemFlashPath; 156 | try { 157 | systemFlashPath = app.getPath('pepperFlashSystemPlugin'); 158 | fs.accessSync(systemFlashPath); 159 | return systemFlashPath; 160 | } catch (error1) { 161 | if (PLATFORM === 'darwin') { 162 | try { 163 | systemFlashPath = '/Library/Internet Plug-Ins/PepperFlashPlayer'; 164 | fs.accessSync(systemFlashPath); 165 | return systemFlashPath; 166 | } catch (error2) { 167 | return null; 168 | } 169 | } else { 170 | return null; 171 | } 172 | } 173 | }; 174 | 175 | getFlashVersion = function(loc) { 176 | var match, path, plistContent, plistPath; 177 | if (typeof loc !== 'string') { 178 | return ''; 179 | } 180 | path = (function() { 181 | switch (loc.toLowerCase()) { 182 | case '@chrome': 183 | return findChromeFlashPath(); 184 | case '@system': 185 | return findSystemFlashPath(); 186 | default: 187 | return loc; 188 | } 189 | })(); 190 | path = validatePath(path); 191 | if (!path) { 192 | return ''; 193 | } 194 | switch (PLATFORM) { 195 | case 'darwin': 196 | plistPath = join(path, 'Contents', 'Info.plist'); 197 | plistContent = fs.readFileSync(plistPath, 'utf8'); 198 | match = /CFBundleVersion<\/key>\s*(\d+(?:\.\d+)*)<\/string>/.exec(plistContent); 199 | if (match && match.length > 1) { 200 | return match[1]; 201 | } else { 202 | return ''; 203 | } 204 | break; 205 | default: 206 | return ''; 207 | } 208 | }; 209 | 210 | getAllChromeFlashVersions = function() { 211 | var paths; 212 | paths = findChromeFlashPath(true); 213 | if (paths) { 214 | return paths.map(function(p) { 215 | return [getFlashVersion(p), p]; 216 | }); 217 | } else { 218 | return []; 219 | } 220 | }; 221 | 222 | flashSources = []; 223 | 224 | usingIndex = -1; 225 | 226 | addSource = function(location, version) { 227 | var o; 228 | if (location == null) { 229 | location = '.'; 230 | } 231 | if (typeof location === 'string') { 232 | o = { 233 | loc: location 234 | }; 235 | if (version != null) { 236 | if (typeof version === 'string' && reVerNum.test(version)) { 237 | o.ver = version; 238 | } else { 239 | error("Invalid version string for " + location + ": " + version); 240 | } 241 | } 242 | flashSources.push(o); 243 | } else { 244 | error("'" + location + "' is not a valid location string!"); 245 | } 246 | return this; 247 | }; 248 | 249 | getPath = function(loc) { 250 | var errMsg, flashPath, i, j, len, src; 251 | if (loc != null) { 252 | switch (loc.toLowerCase()) { 253 | case '@chrome': 254 | flashPath = findChromeFlashPath(); 255 | errMsg = 'Could not load Chrome integrated Pepper Flash Player plug-in'; 256 | break; 257 | case '@system': 258 | flashPath = findSystemFlashPath(); 259 | errMsg = 'Could not load Pepper Flash Player system plug-in'; 260 | break; 261 | default: 262 | flashPath = loc; 263 | errMsg = "Could not load '" + FILENAME + "' from: \n" + loc; 264 | } 265 | } else { 266 | if (flashSources.length === 0) { 267 | errMsg = 'No source has been added. Please call `addSource()` to add the location where Flash Player can be found.'; 268 | } 269 | for (i = j = 0, len = flashSources.length; j < len; i = ++j) { 270 | src = flashSources[i]; 271 | flashPath = getPath(src.loc); 272 | usingIndex = i; 273 | if (flashPath != null) { 274 | break; 275 | } 276 | } 277 | } 278 | flashPath = validatePath(flashPath); 279 | if ((errMsg != null) && (flashPath == null)) { 280 | error(errMsg); 281 | } 282 | return flashPath; 283 | }; 284 | 285 | load = function() { 286 | var flashPath, ver; 287 | flashPath = getPath(); 288 | if (flashPath != null) { 289 | log("Loading Pepper Flash Player: \n" + (resolve(flashPath))); 290 | app.commandLine.appendSwitch('ppapi-flash-path', flashPath); 291 | ver = getFlashVersion(flashPath); 292 | if (usingIndex >= 0 && !ver) { 293 | ver = flashSources[usingIndex].ver; 294 | } 295 | if (ver) { 296 | log("Pepper Flash Player version: " + ver); 297 | return app.commandLine.appendSwitch('ppapi-flash-version', ver); 298 | } 299 | } 300 | }; 301 | 302 | if (process.type === 'browser') { 303 | exports.addSource = addSource; 304 | exports.load = load; 305 | } 306 | 307 | exports.debug = debug; 308 | 309 | exports.getFilename = function() { 310 | return FILENAME; 311 | }; 312 | 313 | exports.getVersion = getFlashVersion; 314 | 315 | exports.getAllChromeFlashVersions = getAllChromeFlashVersions; 316 | 317 | }).call(this); 318 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flash-player-loader", 3 | "version": "1.2.0", 4 | "description": "Makes life easier for the electron apps which need the pepper flash player.", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "dependencies": {}, 10 | "devDependencies": { 11 | "coffee-script": "^1.10.0", 12 | "colors": "^1.1.2" 13 | }, 14 | "scripts": { 15 | "test": "electron test -d", 16 | "prepublish": "coffee --compile lib/flash-loader.coffee" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/alvin-777/flash-player-loader-for-electron.git" 21 | }, 22 | "keywords": [ 23 | "pepper flash player", 24 | "flash", 25 | "electron" 26 | ], 27 | "author": { 28 | "name": "Alvin", 29 | "url": "https://github.com/alvin-777" 30 | }, 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/alvin-777/flash-player-loader-for-electron/issues" 34 | }, 35 | "homepage": "https://github.com/alvin-777/flash-player-loader-for-electron#readme" 36 | } 37 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Flash Player Detection 6 | 20 | 21 | 22 |

23 | If you see clouds moving in the animation below, you have successfully installed Flash Player. Congratulations! 24 |

25 |
26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 |

42 | >> Check Flash Player Version 43 |

44 | 45 | 46 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var app = require('electron').app; 2 | var BrowserWindow = require('electron').BrowserWindow; 3 | require('colors'); 4 | 5 | var mainWindow = null; 6 | 7 | app.on('window-all-closed', function() { 8 | app.quit(); 9 | }); 10 | 11 | var enableDebug = process.argv.some((arg) => arg === '-d'); 12 | if (!enableDebug) 13 | console.log('[NOTE] Append command line argument "-d" to enable debug mode.'.blue); 14 | 15 | // Load the module 16 | var flashLoader = require('..'); 17 | // Using custom log functions to add extra prefixes and colours. 18 | flashLoader.debug({ 19 | enable: enableDebug, 20 | log: console.log.bind(console, '[INFO] %s'.cyan), 21 | error: console.error.bind(console, '[ERROR] %s'.bold.red) 22 | }); 23 | // Try to load Flash Player in the directory 'path_to_this_module/test/' first. 24 | // To make it work you need to copy the Flash Player to the 'test' directory, 25 | // or change the path to where your Flash Player file locates. 26 | // If that fails, then try to find the system plug-in (OS X only). 27 | // And then try to find the Chrome integrated plug-in (OS X only). 28 | var pathToDirContainsFlashPlayer = __dirname; 29 | flashLoader.addSource(pathToDirContainsFlashPlayer, '1.2.3.4'); 30 | flashLoader.addSource('@system'); 31 | flashLoader.addSource('@chrome'); 32 | flashLoader.load(); 33 | 34 | chromeFlashes = flashLoader.getAllChromeFlashVersions(); 35 | if (enableDebug && chromeFlashes.length > 0) { 36 | console.log('\nGoogle Chrome has Pepper Flash Players at:'.blue); 37 | chromeFlashes.forEach((cf) => console.log('>>'.blue, cf[0].yellow, cf[1].magenta)); 38 | } 39 | 40 | // Alternatively, you can chain the methods together. 41 | // require('..').debug().addSource('@system').addSource('@chrome').load(); 42 | 43 | app.on('ready', function() { 44 | mainWindow = new BrowserWindow({ 45 | 'width': 416, 46 | 'height': 400, 47 | 'webPreferences': {'plugins': true} // Do not forget to add this option 48 | // when creating BrowserWindow 49 | }); 50 | var url; 51 | url = 'file://' + __dirname + '/index.html'; 52 | // Try the other links out! 53 | // url = 'http://www.adobe.com/software/flash/about/'; 54 | // url = 'https://helpx.adobe.com/flash-player.html'; 55 | mainWindow.loadURL(url); 56 | }); 57 | --------------------------------------------------------------------------------