Skip to content

Commit

Permalink
速度、边距
Browse files Browse the repository at this point in the history
  • Loading branch information
Wybxc committed Oct 8, 2021
1 parent 7dff323 commit 825d0ca
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ log: # 日志配置
file: # 日志文件
level: info
format: "[{h}:{i}:{s}.{ms}] [{level}] {text}"
margin: # 边距,单位 %
left: 0 # 由于某种神秘力量的影响,left 和 right 好像并不起作用
right: 0
top: 0
bottom: 0
danmaku: # 弹幕配置
speed: 144 # 弹幕速度,默认值144
opacity: 0.4 # 弹幕透明度
defaultSize: 25 # 默认字号,单位像素
defaultColor: "#fff" # 默认颜色
```
Expand Down
27 changes: 26 additions & 1 deletion src/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import * as path from "path";
import YAML from "yaml";
import * as logger from "electron-log";

function assiginObj(target = {}, sources = {}) {
let obj = target;
if (typeof target != "object" || typeof sources != "object") {
return sources; // 如果其中一个不是对象 就返回sources
}
for (let key in sources) {
// 如果target也存在 那就再次合并
if (target.hasOwnProperty(key)) {
obj[key] = assiginObj(target[key], sources[key]);
} else {
// 不存在就直接添加
obj[key] = sources[key];
}
}
return obj;
}

let config = {
server: {
port: 3000,
Expand All @@ -24,7 +41,14 @@ let config = {
format: "[{h}:{i}:{s}.{ms}] [{level}] {text}",
},
},
margin: { // 单位 %
left: 0,
right: 0,
top: 0,
bottom: 0,
},
danmaku: {
speed: 144,
opacity: 0.8,
defaultSize: 25,
defaultColor: "#fff",
Expand All @@ -36,7 +60,8 @@ try {
"utf8"
);

config = YAML.parse(data);
const new_config = YAML.parse(data);
assiginObj(config, new_config);
// 日志输出设置
logger.transports.console.level = config.log.console.level;
logger.transports.console.format = config.log.console.format;
Expand Down
8 changes: 8 additions & 0 deletions src/main/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ app.whenReady().then(() => {
type: "normal",
click: () => mainWindow.webContents.send("about"),
},
{
label: "重启",
type: "normal",
click: () => {
app.relaunch();
app.quit();
},
},
{ label: "退出", type: "normal", role: "quit" },
]);
tray.setToolTip("元火弹幕姬");
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/danmaku.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class CustomDanmaku {
hide() {
this.app.style.marginTop = "100%";
}

resize() {
this.danmaku.resize();
}

setSpeed(speed) {
this.danmaku.speed = speed;
}
}

export default CustomDanmaku;
16 changes: 14 additions & 2 deletions src/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ document.head.appendChild(styles);

window.addEventListener("load", () => {
const app = document.getElementById("app");
app.style.height = "100%";
app.style.position = "fixed";
app.style.top = "0";
app.style.left = "0";
app.style.right = "0";
app.style.bottom = "0";
app.style.overflow = "hidden";


ipcRenderer.on("init", (event, config) => {
logger.info("init", config);
logger.info(config.danmaku.opacity.toString());
app.style.opacity = config.danmaku.opacity.toString();
app.style.left = config.margin.left + "%";
app.style.light = config.margin.right + "%";
app.style.top = config.margin.top + "%";
app.style.bottom = config.margin.bottom + "%";

danmaku.setSpeed(config.danmaku.speed);
danmaku.resize();
});

const danmaku = new CustomDanmaku(app);
Expand Down

0 comments on commit 825d0ca

Please sign in to comment.