mirror of https://github.com/Kylart/KawAnime.git
Added scripts and fixed path for mpv plugin to be found on Windows
This commit is contained in:
parent
45118a856d
commit
7c1e2778e2
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
})
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue