Skip to content

Commit

Permalink
Merge branch 'develop' into account
Browse files Browse the repository at this point in the history
  • Loading branch information
ipy authored Oct 11, 2019
2 parents a9bd6c3 + 552c405 commit 2c4ebdc
Show file tree
Hide file tree
Showing 30 changed files with 704 additions and 629 deletions.
1 change: 1 addition & 0 deletions src/main/helpers/BrowserViewCacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class BrowserViewCacheManager implements IBrowserViewCacheManager {
public recoverCacheWhenExitPip(channel: string,
mainPage: BrowserViewHistoryItem, deletePages: BrowserViewHistoryItem[]): void {
if (this.singlePageHistory.has(channel)) {
(this.singlePageHistory.get(channel) as BrowserSingleCache).page.view.destroy();
this.singlePageHistory.set(channel, {
lastUpdateTime: Date.now(),
page: mainPage,
Expand Down
132 changes: 41 additions & 91 deletions src/main/helpers/BrowserViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class BrowserViewManager implements IBrowserViewManager {
pipPage: null,
};
this.history = [];
this.multiPagesChannel = ['youtube.com', 'iqiyi.com', 'bilibili.com', 'douyu.com', 'huya.com'];
this.singlePageChannel = [];
this.multiPagesChannel = ['youtube.com', 'iqiyi.com', 'bilibili.com', 'douyu.com', 'huya.com', 'twitch.com'];
this.singlePageChannel = ['qq.com', 'youku.com'];
}

public create(channel: string, args: { url: string, isNewWindow?: boolean }): BrowserViewData {
Expand Down Expand Up @@ -302,110 +302,53 @@ export class BrowserViewManager implements IBrowserViewManager {
const currentHistory = (this.historyByChannel.get(this.currentChannel) as ChannelData);
const currentIndex = currentHistory.currentIndex;
const currentView = view || currentHistory.list[currentIndex].view;
currentView.webContents.removeAllListeners('media-started-playing');
if (currentView.webContents.isCurrentlyAudible()) {
let type = '';
switch (true) {
case pausedChannel.includes('bilibili'):
currentView.webContents
.executeJavaScript(InjectJSManager.bilibiliFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('bilibili', type));
});
break;
case pausedChannel.includes('douyu'):
currentView.webContents
.executeJavaScript(InjectJSManager.douyuFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('douyu', type));
});
break;
case pausedChannel.includes('huya'):
currentView.webContents
.executeJavaScript(InjectJSManager.huyaFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('huya', type));
});
break;
default:
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal'));
break;
if (['bilibili.com', 'douyu.com', 'huya.com', 'qq.com'].includes(pausedChannel)) {
const channel = pausedChannel.slice(0, pausedChannel.indexOf('.'));
currentView.webContents
.executeJavaScript(InjectJSManager.pipFindType(channel))
.then((r: string) => {
type = r;
if (!currentView.webContents.isDestroyed()) {
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo(channel, type));
}
});
} else {
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal'));
}
}
if (!enterPip) {
currentView.webContents.addListener('media-started-playing', () => {
currentView.webContents.setAudioMuted(true);
let type = '';
switch (true) {
case pausedChannel.includes('bilibili'):
currentView.webContents
.executeJavaScript(InjectJSManager.bilibiliFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('bilibili', type));
});
break;
case pausedChannel.includes('douyu'):
currentView.webContents
.executeJavaScript(InjectJSManager.douyuFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('douyu', type));
});
break;
case pausedChannel.includes('huya'):
currentView.webContents
.executeJavaScript(InjectJSManager.huyaFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('huya', type));
});
break;
default:
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal'));
break;
if (['bilibili.com', 'douyu.com', 'huya.com', 'qq.com'].includes(pausedChannel)) {
const channel = pausedChannel.slice(0, pausedChannel.indexOf('.'));
currentView.webContents
.executeJavaScript(InjectJSManager.pipFindType(channel))
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo(channel, type));
});
} else {
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal'));
}
});
} else if (currentView.webContents.isLoading()) {
currentView.webContents.once('media-started-playing', () => {
currentView.webContents.setAudioMuted(true);
let type = '';
switch (true) {
case pausedChannel.includes('bilibili'):
currentView.webContents
.executeJavaScript(InjectJSManager.bilibiliFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('bilibili', type)).then(() => {
currentView.webContents.setAudioMuted(false);
});
});
break;
case pausedChannel.includes('douyu'):
currentView.webContents
.executeJavaScript(InjectJSManager.douyuFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('douyu', type)).then(() => {
currentView.webContents.setAudioMuted(false);
});
});
break;
case pausedChannel.includes('huya'):
currentView.webContents
.executeJavaScript(InjectJSManager.huyaFindType())
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('huya', type));
});
break;
default:
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal')).then(() => {
currentView.webContents.setAudioMuted(false);
if (['bilibili.com', 'douyu.com', 'huya.com', 'qq.com'].includes(pausedChannel)) {
const channel = pausedChannel.slice(0, pausedChannel.indexOf('.'));
currentView.webContents
.executeJavaScript(InjectJSManager.pipFindType(channel))
.then((r: string) => {
type = r;
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo(channel, type));
});
break;
} else {
currentView.webContents.executeJavaScript(InjectJSManager.pauseVideo('normal'));
}
});
}
Expand All @@ -420,6 +363,13 @@ export class BrowserViewManager implements IBrowserViewManager {
}

public clearAllBrowserViews(isDeepClear?: boolean): void {
this.currentChannel = '';
this.currentPip = {
pipIndex: -1,
pipChannel: '',
pipPage: null,
};
this.history = [];
isDeepClear = isDeepClear || false;
this.historyByChannel.forEach((history) => {
history.lastUpdateTime = Date.now();
Expand Down
31 changes: 18 additions & 13 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import path, {
import fs from 'fs';
import http from 'http';
import rimraf from 'rimraf';
import urlParse from 'url-parse-lax';
import { audioGrabService } from './helpers/AudioGrabService';
import './helpers/electronPrototypes';
import writeLog from './helpers/writeLog';
Expand Down Expand Up @@ -99,6 +98,8 @@ const locale = new Locale();
const tmpVideoToOpen = [];
const tmpSubsToOpen = [];
const subRegex = getValidSubtitleRegex();
const allChannels = ['youtube', 'bilibili', 'iqiyi', 'douyu', 'qq', 'huya', 'youku', 'twitch'];
const compareStr = [['youtube'], ['bilibili'], ['iqiyi'], ['douyu'], ['v.qq.com'], ['huya'], ['youku', 'soku.com'], ['twitch']];
const titlebarUrl = process.platform === 'darwin' ? `file:${resolve(__static, 'pip/macTitlebar.html')}` : `file:${resolve(__static, 'pip/winTitlebar.html')}`;
const maskUrl = process.platform === 'darwin' ? `file:${resolve(__static, 'pip/mask.html')}` : `file:${resolve(__static, 'pip/mask.html')}`;
const mainURL = process.env.NODE_ENV === 'development'
Expand Down Expand Up @@ -750,12 +751,13 @@ function registerMainWindowEvent(mainWindow) {
});
ipcMain.on('create-browser-view', (evt, args) => {
if (!browserViewManager) browserViewManager = new BrowserViewManager();
const hostname = urlParse(args.url).hostname;
let channel = hostname.slice(hostname.indexOf('.') + 1, hostname.length);
if (args.url.includes('youtube')) {
channel = 'youtube.com';
}
const currentMainBrowserView = browserViewManager.create(channel, args);
let currentChannel = '';
allChannels.forEach((channel, index) => {
if (compareStr[index].findIndex(str => args.url.includes(str)) !== -1) {
currentChannel = `${channel}.com`;
}
});
const currentMainBrowserView = browserViewManager.create(currentChannel, args);
setTimeout(() => {
mainWindow.send('update-browser-state', {
url: args.url,
Expand Down Expand Up @@ -885,12 +887,13 @@ function registerMainWindowEvent(mainWindow) {
browViews.forEach((view) => {
browsingWindow.removeBrowserView(view);
});
const hostname = urlParse(mainView.webContents.getURL()).hostname;
let channel = hostname.slice(hostname.indexOf('.') + 1, hostname.length);
if (mainView.webContents.getURL().includes('youtube')) {
channel = 'youtube.com';
}
const browsers = browserViewManager.changePip(channel);
let currentChannel = '';
allChannels.forEach((channel, index) => {
if (compareStr[index].findIndex(str => mainView.webContents.getURL().includes(str)) !== -1) {
currentChannel = `${channel}.com`;
}
});
const browsers = browserViewManager.changePip(currentChannel);
const pipBrowser = browsers.pipBrowser;
const mainBrowser = browsers.mainBrowser;
mainWindow.addBrowserView(mainBrowser.page.view);
Expand Down Expand Up @@ -945,6 +948,7 @@ function registerMainWindowEvent(mainWindow) {
mainWindow.removeBrowserView(mainWindow.getBrowserViews()[0]);
mainWindow.addBrowserView(mainBrowser.page.view);
browsingWindow.addBrowserView(pipBrowser);
browsingWindow.setSize(420, 236);
createPipControlView();
createTitlebarView();
browsingWindow.show();
Expand Down Expand Up @@ -1478,6 +1482,7 @@ app.on('window-all-closed', () => {

const oauthRegex = [
/^https:\/\/cnpassport.youku.com\//i,
/^https:\/\/udb3lgn.huya.com\//i,
/^https:\/\/passport.iqiyi.com\/apis\/thirdparty/i,
/^https:\/\/api.weibo.com\/oauth2/i,
/^https:\/\/graph.qq.com\//i,
Expand Down
12 changes: 12 additions & 0 deletions src/main/menu/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@
"id": "favourite.huya",
"label": "msg.favourite.huya"
},
{
"id": "favourite.qq",
"label": "msg.favourite.qq"
},
{
"id": "favourite.youku",
"label": "msg.favourite.youku"
},
{
"id": "favourite.twitch",
"label": "msg.favourite.twitch"
},
{
"id": "favourite.youtube",
"label": "msg.favourite.youtube"
Expand Down
15 changes: 0 additions & 15 deletions src/renderer/assets/icon/bilibili-default-icon.svg

This file was deleted.

Loading

0 comments on commit 2c4ebdc

Please sign in to comment.