Skip to content

Commit

Permalink
Merge pull request #355 from Pat1enceLos/develop
Browse files Browse the repository at this point in the history
style(menu): improve menu
  • Loading branch information
ipy authored Dec 27, 2018
2 parents 74e2cd6 + 3831242 commit fda2ee8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/renderer/components/PlayingView/SubtitleControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export default {
});
},
mounted() {
this.$bus.$on('menu-subtitle-refresh', this.handleRefresh);
this.$bus.$on('finish-refresh', () => {
clearInterval(this.timer);
this.count = this.rotateTime * 100;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/locales/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
quit: 'Quit',
},
preferences: {
settings: 'Settings',
clearHistory: 'Always clear playback history on exit',
privacyConfirm: 'Allow anonymous data / Smart Translation',
},
Expand Down
1 change: 1 addition & 0 deletions src/renderer/locales/lang/zhCN.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default {
quit: '退出',
},
preferences: {
settings: '设置',
clearHistory: '退出时自动清空播放记录',
privacyConfirm: '启用匿名信息和智能翻译',
},
Expand Down
1 change: 1 addition & 0 deletions src/renderer/locales/lang/zhTW.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default {
quit: '退出',
},
preferences: {
settings: '設置',
clearHistory: '退出時自動清空播放記錄',
privacyConfirm: '啟用匿名信息和智能翻譯',
},
Expand Down
78 changes: 75 additions & 3 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ new Vue({
},
};
},
currentRouteName() {
return this.$route.name;
},
},
created() {
asyncStorage.get('subtitle-style').then((data) => {
Expand All @@ -153,6 +156,13 @@ new Vue({
});
},
watch: {
currentRouteName(val) {
if (val === 'landing-view') {
this.menuStateControl(false);
} else {
this.menuStateControl(true);
}
},
chosenStyle(val) {
if (this.menu) {
this.menu.getMenuItemById(`style${val}`).checked = true;
Expand Down Expand Up @@ -271,6 +281,7 @@ new Vue({
// menu.playback
{
label: this.$t('msg.playback.name'),
id: 'playback',
submenu: [
{
label: this.$t('msg.playback.forward'),
Expand Down Expand Up @@ -308,6 +319,7 @@ new Vue({
// menu.audio
{
label: this.$t('msg.audio.name'),
id: 'audio',
submenu: [
{
label: this.$t('msg.audio.increaseVolume'),
Expand Down Expand Up @@ -343,11 +355,12 @@ new Vue({
// menu.subtitle
{
label: this.$t('msg.subtitle.name'),
id: 'subtitle',
submenu: [
{
label: this.$t('msg.subtitle.AITranslation'),
click: () => {
this.$bus.$emit('refresh-subtitles');
this.$bus.$emit('menu-subtitle-refresh');
},
},
{
Expand Down Expand Up @@ -596,16 +609,56 @@ new Vue({
}
if (process.platform === 'win32') {
const file = template.shift();
file.submenu = file.submenu.reverse();
file.submenu.forEach((menuItem) => {
const winFile = file.submenu.slice(0, 3);
winFile[2].submenu.unshift(file.submenu[4], file.submenu[3]);
winFile.push(file.submenu[6], file.submenu[5]);
winFile.reverse().forEach((menuItem) => {
template.unshift(menuItem);
});
template.splice(5, 0, {
label: this.$t('msg.preferences.settings'),
submenu: [
{
label: this.$t('msg.preferences.clearHistory'),
id: 'deleteHistory',
type: 'checkbox',
checked: this.$store.getters.deleteVideoHistoryOnExit,
click: () => {
if (this.$store.getters.deleteVideoHistoryOnExit) {
this.$store.dispatch('notDeleteVideoHistoryOnExit');
} else {
this.$store.dispatch('deleteVideoHistoryOnExit');
}
},
},
{
label: this.$t('msg.preferences.privacyConfirm'),
id: 'privacy',
type: 'checkbox',
checked: this.$store.getters.privacyAgreement,
click: () => {
if (this.$store.getters.privacyAgreement) {
this.$store.dispatch('disagreeOnPrivacyPolicy');
} else {
this.$store.dispatch('agreeOnPrivacyPolicy');
}
},
},
],
});
template[10].submenu.unshift({
label: this.$t('msg.splayerx.about'),
role: 'about',
});
}
return template;
}).then((result) => {
this.menu = Menu.buildFromTemplate(result);
Menu.setApplicationMenu(this.menu);
}).then(() => {
if (this.currentRouteName === 'landing-view') {
this.menuStateControl(false);
}
if (this.chosenStyle !== '') {
this.menu.getMenuItemById(`style${this.chosenStyle}`).checked = true;
}
Expand Down Expand Up @@ -746,6 +799,20 @@ new Vue({
return recentMenuTemplate;
});
},
menuStateControl(flag) {
this.menu.getMenuItemById('playback').submenu.items.forEach((item) => {
item.enabled = flag;
});
this.menu.getMenuItemById('audio').submenu.items.forEach((item) => {
item.enabled = flag;
});
this.menu.getMenuItemById('subtitle').submenu.items.forEach((item) => {
item.submenu?.items.forEach((item) => {
item.enabled = flag;
});
item.enabled = flag;
});
},
processRecentPlay(recentPlayData) {
const menuRecentData = new Map([
['recent-1', {
Expand Down Expand Up @@ -829,6 +896,11 @@ new Vue({
Vue.http.headers.common['User-Agent'] = `SPlayerX@2018 ${platform} Version ${version}`;
});

window.addEventListener('mousedown', (e) => {
if (e.button === 2 && process.platform === 'win32') {
this.menu.popup(this.$electron.remote.getCurrentWindow());
}
});
window.addEventListener('keydown', (e) => {
switch (e.key) {
case 'ArrowLeft':
Expand Down

0 comments on commit fda2ee8

Please sign in to comment.