From 835f0a6016fc8395e34c60ab5a44c412e23ebba0 Mon Sep 17 00:00:00 2001 From: msojocs Date: Sat, 3 Jun 2023 16:35:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20flag=E5=8F=82=E6=95=B0=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.MD | 4 ++++ README.MD | 16 ++++++++++++++++ res/scripts/injectIndex.js | 32 ++++++++++++++++++++++++++++---- tools/fix-other.sh | 5 +---- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 8ee5eb5..57bb12d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,7 @@ +# v1.10.1-3 / 2023-06-03 + +- feat: flag参数识别加载 + # v1.10.1-2 / 2023-06-03 - fix: 弹幕ext有概率无法加载 diff --git a/README.MD b/README.MD index 39533bd..8a09eff 100644 --- a/README.MD +++ b/README.MD @@ -72,6 +72,22 @@ https://github.com/msojocs/bilibili-linux/releases/tag/continuous 如果阁下不喜欢电脑多装一个 Electron,可以自行提取发布版的 `app.asar` 并使用已安装 Electron 启动,建议的 Electron 版本是:`17.4.11` +## Flag参数配置 + +支持的参数列表: +https://www.electronjs.org/docs/latest/api/command-line-switches + +1. 创建 `flags` 文件 + + 在 `~/.config/bilibili` 目录下创建 `bilibili-flags.conf` 文件 + +2. 填写配置 + + ``` + --disable-gpu + --key=value + ``` + ## 预览 ![推荐](res/screenshots/1.png) diff --git a/res/scripts/injectIndex.js b/res/scripts/injectIndex.js index 194ddb0..a8b9989 100644 --- a/res/scripts/injectIndex.js +++ b/res/scripts/injectIndex.js @@ -1,6 +1,29 @@ -const { - app -} = require("electron") +const {app} = require('electron'); +const fs = require('fs') +try { + const userDataPath = app.getPath("userData") + const flagPath = `${userDataPath}/bilibili-flags.conf` + console.log('flagPath:', flagPath) + if (fs.existsSync(flagPath) && fs.statSync(flagPath).isFile()) { + const flagData = fs.readFileSync(flagPath).toString() + const flags = flagData.split('\n').filter(e => e && e.length > 0) + for (let flag of flags) { + if (flag.startsWith('--')) + flag = flag.substring(2) + + const kv = flag.split('=') + if (kv.length > 1) { + console.log('append flag:', `${kv[0]}=${kv[1]}`) + app.commandLine.appendSwitch(kv[0], kv[1]) + }else { + console.log('append flag:', kv[0]) + app.commandLine.appendArgument(kv[0]) + } + } + } +} catch (error) { + console.error('flag 解析失败', error) +} const pkgHack = { idx: 0, data: [ @@ -20,4 +43,5 @@ Object.defineProperty(app, 'isPackaged', { return ret; }, -}); \ No newline at end of file +}); +require('./main/index.js')(); \ No newline at end of file diff --git a/tools/fix-other.sh b/tools/fix-other.sh index 7d9a2b8..5dbdcec 100755 --- a/tools/fix-other.sh +++ b/tools/fix-other.sh @@ -30,10 +30,7 @@ notice "====index.js====" # 修复新版不能启动的问题 notice "修复不能启动的问题 index.js -- $root_dir" echo "require('./main/index.js')();" > "app/index.js" -cat "$root_dir/res/scripts/injectIndex.js" > "app/main/temp.js" -cat "app/main/index.js" >> "app/main/temp.js" -rm "app/main/index.js" -mv "app/main/temp.js" "app/main/index.js" +cat "$root_dir/res/scripts/injectIndex.js" > "app/index.js" # 从app.js加载 ok # grep -lr '!import_electron2' --exclude="app.asar" . # sed -i 's#!import_electron2#import_electron2#' app/main/index.js