Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrzoom committed Aug 2, 2016
1 parent dd50776 commit c76fb93
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 25 deletions.
1 change: 1 addition & 0 deletions app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"music":"true","desktopDanmu":"false"}
4 changes: 4 additions & 0 deletions app/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
.num {
margin: 5px;
}

#set {
margin-top: 25px;
}
1 change: 1 addition & 0 deletions app/player/playlist.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
播放列表
1. 玫瑰
Empty file added app/render/frameless.html
Empty file.
Empty file added app/render/frameless.js
Empty file.
8 changes: 8 additions & 0 deletions app/render/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { shell } = require('electron');

$(document).ready(function() {
const githubLink = document.getElementById('github');
githubLink.addEventListener('click', function(event) {
shell.openExternal('http://github.com/zephyrzoom');
});
});
3 changes: 2 additions & 1 deletion app/render/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
window.$ = window.jQuery = require('../js/jquery.js');
require('./index.js');
require('./github');
</script>
</head>

Expand All @@ -19,7 +20,7 @@
<header class="toolbar toolbar-header">
<div class="toolbar-actions">
<div class="btn-group">
<button class="btn btn-default">
<button class="btn btn-default" id="settings">
<span class="icon icon-home"></span> 房间号
<span id="show-roomid" class="num"></span>
</button>
Expand Down
49 changes: 39 additions & 10 deletions app/render/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const danmu = require('../danmu/danmu');
const { shell, ipcRenderer } = require('electron');
const electron = require('electron');
const { shell, ipcRenderer } = electron;
const { BrowserWindow, ipcMain } = electron.remote;

const diange = require('../player/system');
const danmu = require('../danmu/danmu');
const config = require('../util/config');

let cfg;

// 处理格式化的弹幕
function splitDanmu(totalDanmu) {
Expand All @@ -17,10 +23,12 @@ function updateMsg(nn, txt) {
const pane = document.getElementById('pane');
pane.scrollTop = pane.scrollHeight;
}

// 更新观众人数
function updateAudience(content) {
$('#audience').text(content);
}

// 设置房间号
function setRoomId(roomid) {
$('#show-roomid').text(roomid);
Expand All @@ -33,33 +41,52 @@ function setRoomId(roomid) {

// github链接
$(document).ready(function() {
const githubLink = document.getElementById('github');
githubLink.addEventListener('click', function(event) {
shell.openExternal('http://github.com/zephyrzoom');
});

const playlist = document.getElementById('playlist');
playlist.addEventListener('click', (event) => {
const { BrowserWindow } = require('electron').remote;
let playlistWin = new BrowserWindow({
width: 200,
height: 300,
autoHideMenuBar: true,
icon: __dirname + '../assets/favicon.ico',
});
playlistWin.loadURL(`file://${__dirname}/../render/playlist.html`);
playlistWin.loadURL(`file://${__dirname}/playlist.html`);

playlistWin.on('closed', () => {
playlistWin = null;
});
});

const settings = document.getElementById('settings');
settings.addEventListener('click', (event) => {
let settingsWin = new BrowserWindow({
width: 200,
height: 100,
autoHideMenuBar: true,
icon: __dirname + '../assets/favicon.ico',
});
settingsWin.loadURL(`file://${__dirname}/settings.html`);

settingsWin.on('closed', () => {
settingsWin = null;
});
});

config.getConfig((data) => {
cfg = data;
});
});

// 获取roomid
ipcRenderer.on('roomid', (event, arg) => {
setRoomId(arg);
});


ipcMain.on('update-config', (event, arg) => {
cfg = arg;
console.log('update config', cfg);
});

function formatMsg(msg) {
const DANMU_TYPE = '1';
const BAMBOO_TYPE = '206';
Expand All @@ -73,7 +100,9 @@ function formatMsg(msg) {
if (msg.type == DANMU_TYPE) {
const identity = msg.data.from.identity;
let nickName = msg.data.from.nickName;
diange([0, nickName, content]); // 处理点歌
if (cfg.music == 'true') { // 设置可以开启点歌则处理点歌
diange([0, nickName, content]);
}
if (msg.data.from.sp_identity == SP_MANAGER) {
nickName = '*超管*' + nickName;
}
Expand Down
1 change: 1 addition & 0 deletions app/render/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
window.$ = window.jQuery = require('../js/jquery.js');
require('./login.js');
require('./github');
</script>

</head>
Expand Down
5 changes: 0 additions & 5 deletions app/render/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ function setRoomId() {
}
// github链接
$(document).ready(function() {
const { shell } = require('electron');
const githubLink = document.getElementById('github');
githubLink.addEventListener('click', function(event) {
shell.openExternal('http://github.com/zephyrzoom');
});
// 回车登录
$('#roomid').keypress(function(event) {
if (event.which == 13) {
Expand Down
1 change: 1 addition & 0 deletions app/render/playlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
window.$ = window.jQuery = require('../js/jquery.js');
require('./playlist');
require('./github');
</script>
</head>
<body>
Expand Down
5 changes: 0 additions & 5 deletions app/render/playlist.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const { shell, ipcRenderer } = require('electron');

$(document).ready(function() {
const githubLink = document.getElementById('github');
githubLink.addEventListener('click', function(event) {
shell.openExternal('http://github.com/zephyrzoom');
});

ipcRenderer.send('getList');
});

Expand Down
36 changes: 36 additions & 0 deletions app/render/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>系统设置</title>
<link rel="stylesheet" href="../css/index.css">
<!-- Stylesheets -->
<link rel="stylesheet" href="../css/photon.min.css">
<!-- Jquery -->
<script>
window.$ = window.jQuery = require('../js/jquery.js');
require('./github');
require('./settings');
</script>
</head>

<body>
<div class="window">
<div class="window-content">
<div class="pane-group">
<div class="pane" id="pane">
<div id="set">
<button class="btn" id="music"></button>
<button class="btn" id="desktopDanmu"></button>
</div>
</div>
</div>
</div>
<footer class="toolbar toolbar-footer">
<h1 class="title"><a id="github"><span class="icon icon-github"></span></a></h1>
</footer>
</div>
</body>

</html>
44 changes: 44 additions & 0 deletions app/render/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const config = require('../util/config');

const { ipcRenderer } = require('electron');

let cfg;
$(document).ready(() => {
config.getConfig((data) => {
cfg = data;
if (data.music == 'true') {
$('#music').addClass('btn-negative').text('关闭点歌');
} else {
$('#music').addClass('btn-positive').text('开启点歌');
}
if (data.desktopDanmu == 'true') {
$('#desktopDanmu').addClass('btn-negative').text('关闭弹幕');
} else {
$('#desktopDanmu').addClass('btn-positive').text('开启弹幕');
}
});

$('#music').click(() => {
if ($('#music').hasClass('btn-negative')) {
cfg.music = 'false';
$('#music').removeClass('btn-negative').addClass('btn-positive').text('开启点歌');
} else {
cfg.music = 'true';
$('#music').removeClass('btn-positive').addClass('btn-negative').text('关闭点歌');
}
ipcRenderer.send('update-config', cfg);
config.setConfig(cfg);
});

$('#desktopDanmu').click(() => {
if ($('#desktopDanmu').hasClass('btn-negative')) {
cfg.desktopDanmu = 'false';
$('#desktopDanmu').removeClass('btn-negative').addClass('btn-positive').text('开启弹幕');
} else {
cfg.desktopDanmu = 'true';
$('#desktopDanmu').removeClass('btn-positive').addClass('btn-negative').text('关闭弹幕');
}
ipcRenderer.send('update-config', cfg);
config.setConfig(cfg);
});
});
22 changes: 22 additions & 0 deletions app/util/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs');

const CONFIG_PATH = __dirname + '/../config.json';
let config;


exports.getConfig = function getConfig(callback) {
fs.readFile(CONFIG_PATH, (err, data) => {
if (err) throw err;
config = JSON.parse(data);
if (callback) {
callback(config);
}
});
};

exports.setConfig = function setConfig(newConfig) {
config = newConfig;
fs.writeFile(CONFIG_PATH, JSON.stringify(config), (err) => {
if (err) throw err;
});
};
5 changes: 3 additions & 2 deletions log/log.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
8/2/2016, 3:13:25 AM 点歌成功
8/2/2016, 3:15:25 AM 点歌成功
8/3/2016, 3:15:36 AM 点歌成功
8/3/2016, 3:16:21 AM 切歌成功
8/3/2016, 3:16:27 AM 点歌成功
2 changes: 0 additions & 2 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
点歌升级
设置播放列表文件路径
弹幕显示的透明页面
增加系统配置文件
设置点歌开关

0 comments on commit c76fb93

Please sign in to comment.