Skip to content

Commit

Permalink
Merge pull request #881 from YuRiJinX/touchbar
Browse files Browse the repository at this point in the history
feat: Touchbar
  • Loading branch information
ipy authored Aug 22, 2019
2 parents ef93713 + cb50f6a commit ce3472a
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 7 deletions.
55 changes: 55 additions & 0 deletions src/renderer/components/BrowsingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export default {
acceleratorAvailable: true,
oldDisplayId: 0,
backToLandingView: false,
sidebarButton: null,
backwardButton: null,
forwardButton: null,
refreshButton: null,
pipButton: null,
};
},
computed: {
Expand Down Expand Up @@ -170,6 +175,7 @@ export default {
}
},
isPip(val: boolean) {
if (this.pipButton) this.pipButton.icon = this.createIcon(`touchBar/${val ? 'pop' : 'pip'}.png`);
this.menuService.updateMenuItemLabel(
'browsing.window.pip',
this.isPip ? 'msg.window.exitPip' : 'msg.window.enterPip',
Expand Down Expand Up @@ -224,6 +230,7 @@ export default {
if (val) {
this.hasVideo = false;
this.menuService.updateMenuItemEnabled('browsing.window.pip', false);
this.createTouchBar(false);
this.$refs.browsingHeader.updateWebInfo({
hasVideo: this.hasVideo,
url: loadUrl,
Expand All @@ -238,6 +245,7 @@ export default {
this.$refs.webView.executeJavaScript(this.calculateVideoNum, (r: number) => {
this.hasVideo = recordIndex === 0 && !getVideoId(loadUrl).id ? false : !!r;
this.menuService.updateMenuItemEnabled('browsing.window.pip', this.hasVideo);
this.createTouchBar(this.hasVideo);
this.$refs.browsingHeader.updateWebInfo({
hasVideo: this.hasVideo,
url: loadUrl,
Expand Down Expand Up @@ -458,6 +466,53 @@ export default {
updateBarrageOpen: browsingActions.UPDATE_BARRAGE_OPEN,
updateIsPip: browsingActions.UPDATE_IS_PIP,
}),
createTouchBar(enablePip: boolean) {
const { TouchBar } = this.$electron.remote;
const {
TouchBarLabel, TouchBarButton,
TouchBarSpacer,
} = TouchBar;
this.sidebarButton = new TouchBarButton({
icon: this.createIcon('touchBar/sidebar.png'),
click: () => {},
});
this.backwardButton = new TouchBarButton({
icon: this.createIcon(`touchBar/${this.$refs.webView.canGoBack() ? 'backward' : 'backward-disabled'}.png`),
click: () => {
this.$bus.$emit('toggle-back');
},
});
this.forwardButton = new TouchBarButton({
icon: this.createIcon(`touchBar/${this.$refs.webView.canGoForward() ? 'forward' : 'forward-disabled'}.png`),
click: () => {
this.$bus.$emit('toggle-forward');
},
});
this.refreshButton = new TouchBarButton({
icon: this.createIcon('touchBar/refresh.png'),
click: () => {
this.$bus.$emit('toggle-reload');
},
});
this.pipButton = enablePip ? new TouchBarButton({
icon: this.createIcon('touchBar/pip.png'),
click: () => {
this.$bus.$emit('toggle-pip');
},
}) : null;
const touchbarItems = [
this.sidebarButton,
new TouchBarSpacer({ size: 'large' }),
this.backwardButton,
this.forwardButton,
this.refreshButton,
new TouchBarSpacer({ size: 'large' }),
];
if (enablePip) touchbarItems.push(this.pipButton);
this.touchBar = new TouchBar({ items: touchbarItems });
this.$electron.remote.getCurrentWindow().setTouchBar(this.touchBar);
},
handleOpenUrl({ url }: { url: string }) {
if (!url || url === 'about:blank') return;
if (this.isPip) {
Expand Down
29 changes: 29 additions & 0 deletions src/renderer/containers/LandingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export default {
},
/* eslint-disable @typescript-eslint/no-explicit-any */
created() {
this.createTouchBar();
window.addEventListener('mousemove', this.globalMoveHandler);
// Get all data and show
if (!this.incognitoMode) {
Expand Down Expand Up @@ -372,6 +373,34 @@ export default {
...mapActions({
updateInitialUrl: browsingActions.UPDATE_INITIAL_URL,
}),
createTouchBar() {
const { TouchBar } = this.$electron.remote;
const {
TouchBarLabel, TouchBarButton,
TouchBarSpacer,
} = TouchBar;
this.sidebarButton = new TouchBarButton({
icon: this.createIcon('touchBar/sidebar.png'),
click: () => {
this.$event.emit('side-bar-mouseup');
},
});
this.openFileButton = new TouchBarButton({
icon: this.createIcon('touchBar/addVideo.png'),
click: () => {
this.open();
},
});
this.touchBar = new TouchBar({
items: [
this.sidebarButton,
new TouchBarSpacer({ size: 'large' }),
this.openFileButton,
],
});
this.$electron.remote.getCurrentWindow().setTouchBar(this.touchBar);
},
move(steps: number) {
return steps * (this.thumbnailWidth + this.marginRight);
},
Expand Down
29 changes: 22 additions & 7 deletions src/renderer/containers/TheVideoController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,6 @@ export default {
updateHideModalCallback: atActions.AUDIO_TRANSLATE_MODAL_HIDE_CALLBACK,
updateHideBubbleCallback: atActions.AUDIO_TRANSLATE_BUBBLE_CANCEL_CALLBACK,
}),
createIcon(iconPath: string) {
const { nativeImage } = this.$electron.remote;
// @ts-ignore
return nativeImage.createFromPath(path.join(__static, iconPath)).resize({
width: 20,
});
},
createTouchBar() {
const { TouchBar } = this.$electron.remote;
const {
Expand All @@ -523,12 +516,30 @@ export default {
this.timeLabel = new TouchBarLabel();
this.previousButton = new TouchBarButton({
icon: this.createIcon('touchBar/lastVideo.png'),
click: () => {
this.$bus.$emit('previous-video');
},
});
this.restartButton = new TouchBarButton({
icon: this.createIcon('touchBar/restart.png'),
click: () => {
this.$bus.$emit('seek', 0);
},
});
this.playButton = new TouchBarButton({
icon: this.createIcon('touchBar/pause.png'),
click: () => {
this.$bus.$emit('toggle-playback');
},
});
this.nextButton = new TouchBarButton({
icon: this.createIcon('touchBar/nextVideo.png'),
click: () => {
this.$bus.$emit('next-video');
},
});
this.fullScreenBar = new TouchBarButton({
icon: this.createIcon('touchBar/fullscreen.png'),
click: () => {
Expand All @@ -538,7 +549,11 @@ export default {
this.touchBar = new TouchBar({
items: [
this.fullScreenBar,
new TouchBarSpacer({ size: 'large' }),
this.previousButton,
this.playButton,
this.nextButton,
this.restartButton,
new TouchBarSpacer({ size: 'large' }),
this.timeLabel,
new TouchBarSpacer({ size: 'large' }),
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ export default {
}
return false;
},
createIcon(iconPath) {
const { nativeImage } = this.$electron.remote;
return nativeImage.createFromPath(path.join(__static, iconPath)).resize({
width: 25,
});
},
openFileByPlayingView(url) {
const protocol = urlParseLax(url).protocol;
return !['https:', 'http:'].includes(protocol) || document.createElement('video').canPlayType(`video/${url.slice(url.lastIndexOf('.') + 1, url.length)}`);
Expand Down
Binary file added static/touchBar/addVideo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/backward-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/forward-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/forward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/touchBar/fullscreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/lastVideo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/nextVideo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/touchBar/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/pip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/touchBar/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/pop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/touchBar/resize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/restart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/touchBar/sidebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ce3472a

Please sign in to comment.