'use strict';

var _electron = require('electron');

var _pathExtra = require('path-extra');

var _pathExtra2 = _interopRequireDefault(_pathExtra);

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _utils = require('./utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const { ROOT } = global;

// Specify flash path, supposing it is placed in the same directory with main.js.
let pluginName, folderName;
switch (process.platform) {
  case 'win32':
    pluginName = 'pepflashplayer.dll';
    folderName = `win-${process.arch}`;
    break;
  case 'darwin':
    pluginName = 'PepperFlashPlayer.plugin';
    folderName = `mac-${process.arch}`;
    break;
  case 'linux':
    pluginName = 'libpepflashplayer.so';
    folderName = `linux-${process.arch}`;
    break;
}
const flashPaths = [_pathExtra2.default.join(ROOT, '..', 'PepperFlash', folderName, pluginName), _pathExtra2.default.join(ROOT, 'PepperFlash', folderName, pluginName)];

try {
  const path = _electron.app.getPath('pepperFlashSystemPlugin');
  flashPaths.unshift(path);
} catch (e) {
  (0, _utils.warn)('Cannot get system flash plugin path');
}

for (const flashPath of flashPaths) {
  try {
    _fsExtra2.default.accessSync(flashPath, _fsExtra2.default.R_OK);
    _electron.app.commandLine.appendSwitch('ppapi-flash-path', flashPath);
    let flashVersion = '27.0.0.187';
    try {
      flashVersion = require(_pathExtra2.default.join(_pathExtra2.default.dirname(flashPath), 'manifest.json')).version;
    } catch (e) {
      (0, _utils.warn)('Get flash metadata failed.');
    }
    _electron.app.commandLine.appendSwitch('ppapi-flash-version', flashVersion);
    break;
  } catch (e) {
    (0, _utils.warn)(`Flash in ${flashPath} not found.`);
  }
}