Skip to content

Commit

Permalink
fix: - 窗口菜单同步
Browse files Browse the repository at this point in the history
 -  修复客户端版本号错误bug
 -  版本检测优化
  • Loading branch information
Beats0 committed Jun 10, 2020
1 parent 438b76f commit 3a098c0
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 141 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## v1.0.1

- 优化版本号检查
- win 和 mac 顶部窗口菜单栏保持一致
- 修复客户端版本号错误bug
- 文档优化

## v1.0.1-beta.0

- 完成初版功能
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ text-shadow: 1px 1px 2px #e91e63, 0 0 0.2em #e91e63;

然后填入到 `设置` > `自定义样式` 中,`Ctrl+R` 重载即可。

4. 每次更新后请点击 `设置` 中的 `重置`,保持更新数据同步,但以前的部分会丢失。

### 已知 BUG

- mac 在全屏模式下无法至于顶层
Expand Down
2 changes: 2 additions & 0 deletions README_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

安装尽量翻墙

eslint配置不生效,JSX代码格式各种警告,实在搞不动了,有代码强迫症的把eslint 检查关了吧 = =

## 命令

调试 dev
Expand Down
2 changes: 1 addition & 1 deletion app/components/Danmaku/DanmakuControl/DanmakuControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function DanmakuControl(props: Props) {
updateConfig({ k, v });
};

const newVersion = hasNewVersion(config.latestVersion, config.version);
const newVersion = hasNewVersion(config.version, config.latestVersion);

return (
<div id="danmakuControlOuter">
Expand Down
1 change: 1 addition & 0 deletions app/dao/ConfigDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default class ConfigDao {
const configData: configStateType = JSON.parse(configStr);
configData.roomid = resentLiveData.roomid;
configData.shortid = resentLiveData.shortid;
configData.version = pkg.version;
return configData;
}

Expand Down
144 changes: 30 additions & 114 deletions app/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ export default class MenuBuilder {

buildDarwinTemplate() {
const subMenuAbout: DarwinMenuItemConstructorOptions = {
label: 'Electron',
label: 'bilive-danmaku',
submenu: [
{
label: 'About ElectronReact',
label: 'About bilive-danmaku',
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide ElectronReact',
label: 'Hide bilive-danmaku',
accelerator: 'Command+H',
selector: 'hide:'
},
Expand All @@ -85,22 +85,6 @@ export default class MenuBuilder {
}
]
};
const subMenuEdit: DarwinMenuItemConstructorOptions = {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'Command+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+Command+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'Command+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'Command+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'Command+V', selector: 'paste:' },
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
};
const subMenuViewDev: MenuItemConstructorOptions = {
label: 'View',
submenu: [
Expand All @@ -127,18 +111,6 @@ export default class MenuBuilder {
}
]
};
const subMenuViewProd: MenuItemConstructorOptions = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
}
]
};
const subMenuWindow: DarwinMenuItemConstructorOptions = {
label: 'Window',
submenu: [
Expand All @@ -156,103 +128,53 @@ export default class MenuBuilder {
label: 'Help',
submenu: [
{
label: 'Learn More',
label: 'Source code',
click() {
shell.openExternal('https://electronjs.org');
shell.openExternal('https://github.com/Beats0/bilive-danmaku');
}
},
{
label: 'Documentation',
label: 'Check update',
click() {
shell.openExternal(
'https://github.com/electron/electron/tree/master/docs#readme'
'https://github.com/Beats0/bilive-danmaku/releases'
);
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://www.electronjs.org/community');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/electron/electron/issues');
}
}
]
};

const subMenuView =
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
? subMenuViewDev
: subMenuViewProd;

return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
return [subMenuAbout, subMenuViewDev, subMenuWindow, subMenuHelp];
}

buildDefaultTemplate() {
const templateDefault = [
{
label: '&File',
label: '&View',
submenu: [
{
label: '&Open',
accelerator: 'Ctrl+O'
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
},
{
label: '&Close',
accelerator: 'Ctrl+W',
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.close();
this.mainWindow.webContents.toggleDevTools();
}
}
]
},
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
}
}
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
}
]
},
{
label: 'Help',
submenu: [
Expand All @@ -279,23 +201,17 @@ export default class MenuBuilder {
},
// END
{
label: 'Documentation',
label: 'Source code',
click() {
shell.openExternal(
'https://github.com/electron/electron/tree/master/docs#readme'
);
shell.openExternal('https://github.com/Beats0/bilive-danmaku');
}
},
{
label: 'Community Discussions',
label: 'Check update',
click() {
shell.openExternal('https://www.electronjs.org/community');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/electron/electron/issues');
shell.openExternal(
'https://github.com/Beats0/bilive-danmaku/releases'
);
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bilive-danmaku",
"productName": "bilive-danmaku",
"version": "1.0.0",
"version": "1.0.1",
"description": "bilibili live danmaku client",
"main": "./main.prod.js",
"author": {
Expand Down
30 changes: 6 additions & 24 deletions app/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { shell } from 'electron';
import { lt } from 'semver';

function openLink(href: string) {
shell.openExternal(href).catch(e => {
console.log(e);
console.warn(e);
});
}

Expand Down Expand Up @@ -81,34 +82,15 @@ function tranNumber(num: number, point = 2): string {
}

/**
* @param {string} serverVersion 服务器端版本.
* @param {string} clientVersion 客户端版本
* @param {string} serverVersion 服务器端版本.
* @return {boolean} 判断是否能更新
*/
const hasNewVersion = (
serverVersion: string,
clientVersion: string
clientVersion: string,
serverVersion: string
): boolean => {
const arr1 = serverVersion.split('.');
const arr2 = clientVersion.split('.');
// 将两个版本号拆成数字
const minL = Math.min(arr1.length, arr2.length);
let pos = 0; // 当前比较位
let diff = 0; // 当前为位比较是否相等

// 逐个比较如果当前位相等则继续比较下一位
while (pos < minL) {
diff = parseInt(arr1[pos], 10) - parseInt(arr2[pos], 10);
if (diff !== 0) {
break;
}
pos++;
}

if (diff > 0) {
return true;
}
return false;
return lt(clientVersion, serverVersion);
};

export {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bilive-danmaku",
"productName": "bilive-danmaku",
"version": "1.0.0",
"version": "1.0.1",
"ElectronReactVersion": "1.1.0",
"description": "bilibili live danmaku client",
"scripts": {
Expand Down Expand Up @@ -285,6 +285,7 @@
"react-spring": "^8.0.27",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"semver": "^7.3.2",
"source-map-support": "^0.5.16",
"styled-components": "^5.1.0"
},
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13447,6 +13447,11 @@ semver@^7.1.3:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.3.tgz#e4345ce73071c53f336445cfc19efb1c311df2a6"
integrity sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA==

semver@^7.3.2:
version "7.3.2"
resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.2.tgz?cache=0&sync_timestamp=1586886301819&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha1-YElisFK4HtB4aq6EOJ/7pw/9OTg=

semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
Expand Down

0 comments on commit 3a098c0

Please sign in to comment.