-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support flash lyrics display in electron(50%)
- Loading branch information
1 parent
fb206b1
commit 6708826
Showing
22 changed files
with
381 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IpcRenderer } from '@/electron/event/ipc-renderer' | ||
|
||
export const importIpc = () => { | ||
return import('@/electron/event/ipc-renderer').then((v: IpcRenderer) => { | ||
return { | ||
sendAsyncIpcRendererEvent: v.sendAsyncIpcRendererEvent, | ||
sendSyncIpcRendererEvent: v.sendSyncIpcRendererEvent | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/pages/footer/component/lyrice-flash/browser-lyrice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { defineComponent, computed, toRefs, watch, watchEffect } from 'vue' | ||
import { uesModuleStore } from '@/hooks/index' | ||
import { toFixed } from '@/utils/index' | ||
import { ENV } from '@/interface/app' | ||
import { | ||
NAMESPACED as LayoutNamespace, | ||
State as LayoutState, | ||
Size | ||
} from '@/layout/module' | ||
import { NAMESPACED, State, Getter, Mutations } from '../../module' | ||
import { Platform } from '@/config/build' | ||
import LyriceFlash from './index' | ||
import './index.less' | ||
|
||
const { VUE_APP_PLATFORM } = window as ENV | ||
|
||
export const BrowserLyriceFlash = defineComponent({ | ||
name: 'BrowserLyriceFlash', | ||
setup() { | ||
const { useState, useGetter, useMutations } = uesModuleStore<State, Getter>( | ||
NAMESPACED | ||
) | ||
const LayoutModule = uesModuleStore<LayoutState>(LayoutNamespace) | ||
|
||
const { currentTime, playing, visibleFlash, musicUrl } = toRefs(useState()) | ||
const { screenSize } = toRefs(LayoutModule.useState()) | ||
|
||
if (VUE_APP_PLATFORM === Platform.ELECTRON) { | ||
useMutations(Mutations.VISIBLE_FLASH, true) | ||
} | ||
|
||
const lyrice = computed(() => | ||
useGetter('musicLyrics').filter(value => value.lyric) | ||
) | ||
|
||
watch(screenSize, v => { | ||
if (musicUrl.value) { | ||
useMutations(Mutations.VISIBLE_FLASH, v === Size.SM) | ||
} | ||
}) | ||
|
||
const index = computed(() => { | ||
if (visibleFlash.value) { | ||
const len = lyrice.value.length | ||
return ( | ||
lyrice.value.findIndex((value, index) => { | ||
return currentTime.value >= value.time && len - 1 === index | ||
? true | ||
: currentTime.value < lyrice.value[index + 1]?.time | ||
}) || 0 | ||
) | ||
} | ||
return 0 | ||
}) | ||
|
||
const flashMagic = computed(() => { | ||
if (visibleFlash.value) { | ||
const cur = lyrice.value[index.value] | ||
// const schedule = cur.duration - (currentTime.value - cur.time) | ||
const d = toFixed(cur?.duration, 2) | ||
if (d) { | ||
return { | ||
animationDuration: `${d}s` | ||
} | ||
} else { | ||
return { | ||
animationDuration: '' | ||
} | ||
} | ||
} | ||
return { | ||
animationDuration: '' | ||
} | ||
}) | ||
|
||
watchEffect(() => { | ||
useMutations(Mutations.UPDATE_ELECTRON_LYRICE, { | ||
flashMagic: flashMagic.value, | ||
index: index.value, | ||
playing: playing.value, | ||
lyrice: lyrice.value | ||
}) | ||
}) | ||
|
||
return () => ( | ||
<> | ||
{VUE_APP_PLATFORM === Platform.BROWSER && ( | ||
<LyriceFlash | ||
screenSize={screenSize.value} | ||
visibleFlash={visibleFlash.value} | ||
lyrice={lyrice.value} | ||
index={index.value} | ||
playing={playing.value} | ||
flashMagic={flashMagic.value} | ||
></LyriceFlash> | ||
)} | ||
</> | ||
) | ||
} | ||
}) |
49 changes: 49 additions & 0 deletions
49
src/pages/footer/component/lyrice-flash/electron-lyrice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { defineComponent, reactive } from 'vue' | ||
import LyriceFlash from './index' | ||
import { Size } from '@/layout/module' | ||
import { Lyrics } from '@/pages/footer/module' | ||
import { ipcRenderer } from 'electron' | ||
import { Lyrice } from '@/electron/event/action-types' | ||
|
||
export interface PostData { | ||
screenSize: Size | ||
visibleFlash: boolean | ||
lyrice: Lyrics[] | ||
index: number | ||
playing: boolean | ||
flashMagic: { | ||
animationDuration: string | ||
} | ||
} | ||
|
||
export default defineComponent({ | ||
name: 'Lyrice', | ||
setup() { | ||
const postData: PostData = reactive({ | ||
screenSize: Size.SM, | ||
visibleFlash: true, | ||
lyrice: [], | ||
index: 0, | ||
playing: true, | ||
flashMagic: { | ||
animationDuration: '' | ||
} | ||
}) | ||
|
||
ipcRenderer.on(Lyrice.LYRICE_UPDATE_RENDER, (event, any) => { | ||
console.log('子窗口接受到主窗口的数据') | ||
console.log(any) | ||
}) | ||
|
||
return () => ( | ||
<LyriceFlash | ||
screenSize={postData.screenSize} | ||
visibleFlash={postData.visibleFlash} | ||
lyrice={postData.lyrice} | ||
index={postData.index} | ||
playing={postData.playing} | ||
flashMagic={postData.flashMagic} | ||
></LyriceFlash> | ||
) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.