Added scripts and fixed path for mpv plugin to be found on Windows

This commit is contained in:
Kylart 2020-01-31 19:58:18 +01:00
parent 45118a856d
commit 7c1e2778e2
3 changed files with 83 additions and 5 deletions

View File

@ -14,7 +14,9 @@
"start": "cross-env NODE_ENV=production npm run build:after && electron dist/bundled/background.js",
"build": "vue-cli-service electron:build",
"build:after": "node scripts/afterBuild.js",
"build:bindings": "cmake-js build -d bindings -O bindings/build && ./collect-dylib-deps.sh",
"build:bindings": "cmake-js build -d bindings -O bindings/build",
"move:libs": "node scripts/moveLibs.js",
"collect:dylibs": "./collect-dylib-deps.sh",
"pack": "npm run build -- --dir",
"dist": "npm run dist:mac && npm run dist:win && npm run dist:linux",
"dist:mac": "cross-env NODE_ENV=production npm run build -- --mac",

22
scripts/moveLibs.js Normal file
View File

@ -0,0 +1,22 @@
const { readdirSync, copyFileSync } = require('fs')
const { join } = require('path')
const PUBLIC_DIR = join(__dirname, '..', 'public')
const BINDINGS_BUILD_DIR = join(__dirname, '..', 'bindings', 'build', 'Release')
const FILE_NAME = {
darwin: 'libtorrent-rasterbar.10.dylib',
win32: 'libtorrent-rasterbar.dll'
}[process.platform] || '.so'
readdirSync(BINDINGS_BUILD_DIR)
.forEach((file) => {
if (file !== FILE_NAME) return
console.log(`[KawAnime] Moving ${file} to public directory.`)
copyFileSync(
join(BINDINGS_BUILD_DIR, file),
join(PUBLIC_DIR, file)
)
})

View File

@ -1,6 +1,61 @@
/* global __static */
import { join } from 'path'
import { join, dirname, relative, sep } from 'path'
/**
* The MIME type associated with mpv.js plugin.
* This is coming straight from mpvjs lib
*/
const PLUGIN_MIME_TYPE = 'application/x-mpvjs'
function containsNonASCII (str) {
for (let i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 255) {
return true
}
}
return false
}
/**
* Return value to be passed to `register-pepper-plugins` switch.
* This is coming straight from mpvjs lib
*
* @param {string} pluginDir - Plugin directory
* @param {string} [pluginName=mpvjs.node] - Plugin name
* @throws {Error} Resulting path contains non-ASCII characters.
*/
function getPluginEntry (pluginDir, pluginName = 'mpvjs.node') {
const fullPluginPath = join(pluginDir, pluginName)
// Try relative path to workaround ASCII-only path restriction.
let pluginPath = relative(process.cwd(), fullPluginPath)
if (dirname(pluginPath) === '.') {
// "./plugin" is required only on Linux.
if (process.platform === 'linux') {
pluginPath = `.${sep}${pluginPath}`
}
} else {
// Relative plugin paths doesn't work reliably on Windows, see
// <https://github.com/Kagami/mpv.js/issues/9>.
if (process.platform === 'win32') {
pluginPath = fullPluginPath
}
}
if (containsNonASCII(pluginPath)) {
if (containsNonASCII(fullPluginPath)) {
throw new Error('Non-ASCII plugin path is not supported')
} else {
pluginPath = fullPluginPath
}
}
return `${pluginPath};${PLUGIN_MIME_TYPE}`
}
/**
* Configure app to use MPV player.
*
@ -9,12 +64,11 @@ import { join } from 'path'
export default function (app) {
// Absolute path to the plugin directory.
const pluginDir = join(__static, 'mpv')
const pluginPath = join(pluginDir, 'mpvjs.node;application/x-mpvjs')
// See pitfalls section for details.
// if (process.platform !== 'linux') process.chdir(pluginDir)
if (process.platform !== 'linux') process.chdir(pluginDir)
// To support a broader number of systems.
app.commandLine.appendSwitch('ignore-gpu-blacklist')
app.commandLine.appendSwitch('register-pepper-plugins', pluginPath)
app.commandLine.appendSwitch('register-pepper-plugins', getPluginEntry(pluginDir))
}