Skip to content

Commit

Permalink
feat: flag参数识别加载
Browse files Browse the repository at this point in the history
  • Loading branch information
msojocs committed Jun 3, 2023
1 parent e18b601 commit 835f0a6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.10.1-3 / 2023-06-03

- feat: flag参数识别加载

# v1.10.1-2 / 2023-06-03

- fix: 弹幕ext有概率无法加载
Expand Down
16 changes: 16 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 28 additions & 4 deletions res/scripts/injectIndex.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -20,4 +43,5 @@ Object.defineProperty(app, 'isPackaged', {
return ret;
},

});
});
require('./main/index.js')();
5 changes: 1 addition & 4 deletions tools/fix-other.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit 835f0a6

@msojocs
Copy link
Owner Author

@msojocs msojocs commented on 835f0a6 Jun 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#60

Please sign in to comment.