Skip to content

Commit

Permalink
feat(desktop): 新窗口打开视频播放
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed May 27, 2024
1 parent 59f3139 commit b8f7961
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
16 changes: 16 additions & 0 deletions packages/web/electron/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ export function createAPI(win: BrowserWindow) {
pinned ? win.setAlwaysOnTop(true, 'screen-saver') : win.setAlwaysOnTop(false);
return success(win.isAlwaysOnTop());
});

pm.answer('post@openWindow', (data) => {
const window = new BrowserWindow({
title: 'AnyReader',
// titleBarStyle: 'hidden',
webPreferences: { nodeIntegration: true, contextIsolation: false }
});

if (process.env.VITE_DEV_SERVER_URL) {
window.loadURL(process.env.VITE_DEV_SERVER_URL + '/#' + data.url);
} else {
window.loadFile('dist/electron-template/index.html', {
hash: data.url
});
}
});
}
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "any-reader-web",
"version": "1.0.0-dev.1",
"version": "1.0.0-dev.4",
"private": true,
"scripts": {
"dev": "cross-env VITE_APP_PLATFORM=browser vite",
Expand Down
9 changes: 9 additions & 0 deletions packages/web/src/api/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ export function alwaysOnTop(pinned: boolean) {
}
});
}

// 打开新窗口
export function openWindow(data: any) {
return request({
method: 'post',
url: 'openWindow',
data
});
}
13 changes: 8 additions & 5 deletions packages/web/src/pages/pc/chapter/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</template>

<script setup>
import { stringify } from 'qs';
import { getChapter, getContent } from '@/api';
import { openWindow } from '@/api/electron';
import { useRulesStore } from '@/stores/rules';
const route = useRoute();
Expand Down Expand Up @@ -45,11 +47,12 @@ async function showContent(item) {
}).catch(() => {});
console.log('getContent', res);
if (res?.code === 0) {
router.push({
path: '/pc/player',
query: {
url: res?.data?.content || ''
}
openWindow({
url:
'/player?' +
stringify({
url: res?.data?.content || ''
})
});
return;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/web/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const router = createRouter({
path: '/',
redirect: '/pc/books'
},
{
path: '/player',
name: '/player',
component: () => import('@/pages/pc/player/index.vue')
},
// pc
{
path: '/pc',
Expand All @@ -33,10 +38,6 @@ const router = createRouter({
path: 'rules',
component: () => import('@/pages/pc/rules/index.vue')
},
{
path: 'player',
component: () => import('@/pages/pc/player/index.vue')
},
{
path: 'chapter',
component: () => import('@/pages/pc/chapter/index.vue')
Expand Down

0 comments on commit b8f7961

Please sign in to comment.