mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-24 11:57:27 +08:00
fix: remove osdlyrics
This commit is contained in:
parent
c7681df0e8
commit
caaf62ea20
|
@ -1,240 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: Barlow, -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
user-select: none;
|
||||
margin: 2px;
|
||||
padding: 0px;
|
||||
-webkit-user-select: none;
|
||||
-webkit-app-region: drag;
|
||||
background: rgba(0, 0, 0, 0.000);
|
||||
}
|
||||
|
||||
div {
|
||||
display: block;
|
||||
padding: 9px;
|
||||
border-radius: 6px;
|
||||
background: rgba(128, 128, 128, 0.800);
|
||||
}
|
||||
</style>
|
||||
<title>OSD Lyrics</title>
|
||||
<script>
|
||||
const electron = (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) ? window.require('electron') : null;
|
||||
const ipcRenderer = electron ? electron.ipcRenderer : null;
|
||||
const player_api = window.location.origin + "/player";
|
||||
const lyrics_api = window.location.origin + "/api/lyric?id=";
|
||||
const min_update_interval = 50;
|
||||
const max_update_interval = 500;
|
||||
song_id = null;
|
||||
lyrics = null;
|
||||
current_line = null;
|
||||
current_index = 0;
|
||||
next_time = 0;
|
||||
function lyric_parser(lrc) {
|
||||
if (!lrc) {
|
||||
return null;
|
||||
}
|
||||
lines = lrc
|
||||
.split('\n')
|
||||
.map(nx => {
|
||||
//nx = decodeURIComponent(x);
|
||||
text = nx.split(']');
|
||||
lrc = text[1];
|
||||
if (!lrc) {
|
||||
return null;
|
||||
}
|
||||
_time = text[0].split('[')[1];
|
||||
if (!_time) {
|
||||
return null;
|
||||
}
|
||||
time = _time.split(':')
|
||||
min = Number(time[0]);
|
||||
sec = Number(time[1]);
|
||||
if (lrc.length < 1) {
|
||||
return [min * 60 + sec, " "]
|
||||
} else {
|
||||
return [min * 60 + sec, lrc];
|
||||
}
|
||||
})
|
||||
.filter(x => Boolean(x));
|
||||
if (lines.length > 0) {
|
||||
return lines;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function update_window_size() {
|
||||
if (!ipcRenderer) {
|
||||
return;
|
||||
}
|
||||
offsetHeight = document.getElementById('line1').offsetHeight + 4;
|
||||
if (offsetHeight == window.innerHeight) {
|
||||
return;
|
||||
}
|
||||
ipcRenderer.send('resizeOSDLyrics', offsetHeight);
|
||||
}
|
||||
function search_line(progress) {
|
||||
for (i = 1; i < lyrics.length; i++) {
|
||||
if (progress < lyrics[i][0]) {
|
||||
current_index = i - 1;
|
||||
next_time = lyrics[i][0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
current_index = lyrics.length - 1;
|
||||
return;
|
||||
}
|
||||
function translation_combine(lrc, tr) {
|
||||
if (!lrc) {
|
||||
lyrics = null;
|
||||
return;
|
||||
}
|
||||
if (!tr) {
|
||||
lyrics = lrc.map(x => [x[0], x[1], null]);
|
||||
return;
|
||||
}
|
||||
lyrics = new Array(lrc.length);
|
||||
lrc_length = lrc.length;
|
||||
t_length = tr.length;
|
||||
for (i = 0, j = 0; i < lrc_length;) {
|
||||
if (j >= t_length) {
|
||||
lyrics[i] = [lrc[i][0], lrc[i][1], null];
|
||||
i++;
|
||||
} else {
|
||||
lrc_time = lrc[i][0];
|
||||
tr_time = tr[j][0];
|
||||
if (lrc_time == tr_time) {
|
||||
lyrics[i] = [lrc_time, lrc[i][1], tr[j][1]];
|
||||
i++; j++;
|
||||
} else if (lrc_time < tr_time) {
|
||||
lyrics[i] = [lrc_time, lrc[i][1], null];
|
||||
i++;
|
||||
} else if (lrc_time > tr_time) {
|
||||
while (lrc_time > tr[j][0] && j < t_length) {
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function update_display() {
|
||||
document.getElementById("line1").innerHTML = current_line;
|
||||
update_window_size();
|
||||
}
|
||||
function update_line(progress) {
|
||||
next_update = max_update_interval;
|
||||
if (!lyrics) {
|
||||
current_line = "纯音乐,请欣赏";
|
||||
} else {
|
||||
lyrics_length = lyrics.length;
|
||||
if (progress > lyrics[current_index][0]) {
|
||||
next_index = current_index + 1;
|
||||
if (next_index < lyrics_length) {
|
||||
if (progress < lyrics[next_index][0]) {
|
||||
next_update = (next_time - progress) * 1000;
|
||||
} else {
|
||||
next_next_index = next_index + 1;
|
||||
if (next_next_index < lyrics_length) {
|
||||
if (progress < lyrics[next_next_index][0]) {
|
||||
current_index = next_index;
|
||||
current = lyrics[next_index];
|
||||
current_line = current[2] ? (current[1] + "<br>" + current[2]) : current[1];
|
||||
next_time = lyrics[next_next_index][0];
|
||||
next_update = (next_time - progress) * 1000;
|
||||
} else {
|
||||
search_line(progress);
|
||||
current = lyrics[current_index];
|
||||
current_line = current[2] ? (current[1] + "<br>" + current[2]) : current[1];
|
||||
next_update = (next_time - progress) * 1000;
|
||||
}
|
||||
} else {
|
||||
// next line is last line
|
||||
current_index = next_index;
|
||||
current = lyrics[next_index];
|
||||
current_line = current[2] ? (current[1] + "<br>" + current[2]) : current[1];
|
||||
next_update = max_update_interval;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// last line
|
||||
next_update = max_update_interval;
|
||||
}
|
||||
} else {
|
||||
search_line(progress);
|
||||
current = lyrics[current_index];
|
||||
current_line = current[2] ? (current[1] + "<br>" + current[2]) : current[1];
|
||||
next_update = (next_time - progress) * 1000;
|
||||
}
|
||||
}
|
||||
if (next_update > max_update_interval) {
|
||||
interval = parseInt(next_update / max_update_interval);
|
||||
next_update = next_update / interval;
|
||||
} else if (next_update < min_update_interval) {
|
||||
next_update = min_update_interval;
|
||||
}
|
||||
setTimeout(update_lyrics, next_update);
|
||||
update_display();
|
||||
}
|
||||
function get_lyrics(_song_id) {
|
||||
var url = lyrics_api + _song_id;
|
||||
fetch(url)
|
||||
.then(
|
||||
(_lyric) => {
|
||||
_lyric
|
||||
.text()
|
||||
.then(
|
||||
(text) => {
|
||||
result = JSON.parse(text);
|
||||
if (!result.lrc) {
|
||||
lyrics = null;
|
||||
update_line(_progress);
|
||||
return;
|
||||
}
|
||||
_lyrics = lyric_parser(result.lrc.lyric);
|
||||
_translation = lyric_parser(result.tlyric.lyric);
|
||||
translation_combine(_lyrics, _translation);
|
||||
current_index = 0;
|
||||
update_line(_progress);
|
||||
})
|
||||
})
|
||||
}
|
||||
function update_lyrics() {
|
||||
fetch(player_api)
|
||||
.then(
|
||||
(player) => {
|
||||
player
|
||||
.text()
|
||||
.then((text) => {
|
||||
_status = JSON.parse(text);
|
||||
_song_id = _status.currentTrack.id;
|
||||
_progress = _status.progress;
|
||||
if (_song_id !== song_id) {
|
||||
song_id = _song_id;
|
||||
get_lyrics(_song_id);
|
||||
} else {
|
||||
update_line(_progress);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
function init_lyrics() {
|
||||
update_window_size();
|
||||
update_lyrics();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body onload="init_lyrics()">
|
||||
<div id="line1">YesPlayMusic</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" focusable="false" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
x="0px" y="0px" viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
|
||||
<path fill="currentColor" d="M15,0C6.7,0,0,6.7,0,15s6.7,15,15,15s15-6.7,15-15S23.3,0,15,0z M11.9,10.6c0.4,0,0.7,0.1,1,0.1s0.6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0.4,0-0.8,0-1.2c0-0.4-0.1-0.7-0.1-0.9c0.2,0,0.3,0,0.5,0.1c0.2,0,0.4,0,0.6,0c0.2,0,0.5,0,0.8,0c0.3,0,0.7,0,1.1,0h1.1
|
||||
c0.3,0,0.6,0,0.8,0c0.2,0,0.4,0,0.5,0c0.1,0,0.3,0,0.4-0.1c-0.1,0.2-0.1,0.5-0.1,0.9c0,0.4,0,0.8,0,1.2v2.5c0,0.1,0,0.3,0,0.5
|
||||
c0,0.2,0,0.4,0,0.6c0,0.2,0,0.4,0.1,0.6c0,0.2,0,0.4,0.1,0.6h-1.7v-1L14.3,19.5L14.3,19.5z M22.6,7.5c0,0.1,0,0.3,0,0.5
|
||||
c0,0.2,0,0.4,0,0.6v12.7c0,0.4,0,0.7-0.1,1c-0.1,0.3-0.2,0.5-0.4,0.6c-0.2,0.2-0.5,0.3-1,0.4c-0.4,0.1-1,0.2-1.8,0.3
|
||||
c0-0.3-0.1-0.7-0.2-1.1c-0.1-0.4-0.4-0.8-0.7-1.1c0.5,0.1,1,0.1,1.3,0.1c0.3,0,0.6,0,0.7,0c0.2,0,0.3-0.1,0.3-0.2
|
||||
c0.1-0.1,0.1-0.2,0.1-0.4V8.7h-4.1c-0.5,0-0.9,0-1.2,0c-0.4,0-0.7,0-1.1,0c-0.3,0-0.7,0-1,0.1c-0.3,0-0.6,0.1-1,0.1V7.2
|
||||
c0.3,0,0.6,0,0.9,0.1c0.3,0,0.6,0,0.9,0c0.3,0,0.7,0,1.2,0H17c0.8,0,1.4,0,2,0c0.5,0,1,0,1.4,0c0.4,0,0.8,0,1.1,0
|
||||
c0.3,0,0.7-0.1,1.1-0.1l0,0C22.6,7.3,22.6,7.4,22.6,7.5z"/>
|
||||
<path fill="currentColor" d="M14.3,15h2.8v3.4h-2.8L14.3,15L14.3,15z"/>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.4 KiB |
|
@ -29,7 +29,6 @@ const log = text => {
|
|||
class Background {
|
||||
constructor() {
|
||||
this.window = null;
|
||||
this.osdlyrics = null;
|
||||
this.tray = null;
|
||||
this.store = new Store({
|
||||
windowWidth: {
|
||||
|
@ -165,71 +164,6 @@ class Background {
|
|||
}
|
||||
}
|
||||
|
||||
createOSDWindow() {
|
||||
this.osdlyrics = new BrowserWindow({
|
||||
x: this.store.get('osdlyrics.x-pos') || 0,
|
||||
y: this.store.get('osdlyrics.y-pos') || 0,
|
||||
width: this.store.get('osdlyrics.width') || 840,
|
||||
height: this.store.get('osdlyrics.height') || 110,
|
||||
title: 'OSD Lyrics',
|
||||
transparent: true,
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
});
|
||||
this.osdlyrics.setAlwaysOnTop(true, 'screen');
|
||||
|
||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||
// Load the url of the dev server if in development mode
|
||||
this.osdlyrics.loadURL(
|
||||
process.env.WEBPACK_DEV_SERVER_URL + '/osdlyrics.html'
|
||||
);
|
||||
if (!process.env.IS_TEST) this.osdlyrics.webContents.openDevTools();
|
||||
} else {
|
||||
this.osdlyrics.loadURL('http://localhost:27232/osdlyrics.html');
|
||||
}
|
||||
}
|
||||
|
||||
initOSDLyrics() {
|
||||
const osdState = this.store.get('osdlyrics.show') || false;
|
||||
if (osdState) {
|
||||
this.showOSDLyrics();
|
||||
}
|
||||
}
|
||||
|
||||
toggleOSDLyrics() {
|
||||
const osdState = this.store.get('osdlyrics.show') || false;
|
||||
if (osdState) {
|
||||
this.hideOSDLyrics();
|
||||
} else {
|
||||
this.showOSDLyrics();
|
||||
}
|
||||
}
|
||||
|
||||
showOSDLyrics() {
|
||||
this.store.set('osdlyrics.show', true);
|
||||
if (!this.osdlyrics) {
|
||||
this.createOSDWindow();
|
||||
this.handleOSDEvents();
|
||||
}
|
||||
}
|
||||
|
||||
hideOSDLyrics() {
|
||||
this.store.set('osdlyrics.show', false);
|
||||
if (this.osdlyrics) {
|
||||
this.osdlyrics.close();
|
||||
}
|
||||
}
|
||||
|
||||
resizeOSDLyrics(height) {
|
||||
const width = this.store.get('osdlyrics.width') || 840;
|
||||
this.osdlyrics.setSize(width, height);
|
||||
}
|
||||
|
||||
checkForUpdates() {
|
||||
if (process.env.NODE_ENV === 'development') return;
|
||||
log('checkForUpdates');
|
||||
|
@ -259,30 +193,6 @@ class Background {
|
|||
});
|
||||
}
|
||||
|
||||
handleOSDEvents() {
|
||||
this.osdlyrics.once('ready-to-show', () => {
|
||||
log('OSD ready-to-show event');
|
||||
this.osdlyrics.show();
|
||||
});
|
||||
|
||||
this.osdlyrics.on('closed', e => {
|
||||
log('OSD close event');
|
||||
this.osdlyrics = null;
|
||||
});
|
||||
|
||||
this.osdlyrics.on('resized', () => {
|
||||
let { height, width } = this.osdlyrics.getBounds();
|
||||
this.store.set('osdlyrics.width', width);
|
||||
this.store.set('osdlyrics.height', height);
|
||||
});
|
||||
|
||||
this.osdlyrics.on('moved', () => {
|
||||
var pos = this.osdlyrics.getPosition();
|
||||
this.store.set('osdlyrics.x-pos', pos[0]);
|
||||
this.store.set('osdlyrics.y-pos', pos[1]);
|
||||
});
|
||||
}
|
||||
|
||||
handleWindowEvents() {
|
||||
this.window.once('ready-to-show', () => {
|
||||
log('windows ready-to-show event');
|
||||
|
@ -363,13 +273,8 @@ class Background {
|
|||
});
|
||||
this.handleWindowEvents();
|
||||
|
||||
this.initOSDLyrics();
|
||||
|
||||
// init ipcMain
|
||||
initIpcMain(this.window, this.store, {
|
||||
resizeOSDLyrics: height => this.resizeOSDLyrics(height),
|
||||
toggleOSDLyrics: () => this.toggleOSDLyrics(),
|
||||
});
|
||||
initIpcMain(this.window, this.store);
|
||||
|
||||
// set proxy
|
||||
const proxyRules = this.store.get('proxy');
|
||||
|
|
|
@ -95,12 +95,6 @@
|
|||
<div class="right-control-buttons">
|
||||
<div class="blank"></div>
|
||||
<div class="container" @click.stop>
|
||||
<button-icon
|
||||
v-if="osdState"
|
||||
:title="$t('player.osdLyrics')"
|
||||
@click.native="toggleOSDLyrics"
|
||||
><svg-icon icon-class="osd-lyrics"
|
||||
/></button-icon>
|
||||
<button-icon
|
||||
:title="$t('player.nextUp')"
|
||||
:class="{
|
||||
|
@ -174,10 +168,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
const electron =
|
||||
process.env.IS_ELECTRON === true ? window.require('electron') : null;
|
||||
const ipcRenderer =
|
||||
process.env.IS_ELECTRON === true ? electron.ipcRenderer : null;
|
||||
import { mapState, mapMutations, mapActions } from 'vuex';
|
||||
import '@/assets/css/slider.css';
|
||||
|
||||
|
@ -211,18 +201,10 @@ export default {
|
|||
? '音源来自酷我音乐'
|
||||
: '';
|
||||
},
|
||||
osdState() {
|
||||
return Boolean(ipcRenderer);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['toggleLyrics']),
|
||||
...mapActions(['showToast', 'likeATrack']),
|
||||
toggleOSDLyrics() {
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send('toggleOSDLyrics');
|
||||
}
|
||||
},
|
||||
goToNextTracksPage() {
|
||||
if (this.player.isPersonalFM) return;
|
||||
this.$route.name === 'next'
|
||||
|
|
|
@ -12,7 +12,7 @@ const log = text => {
|
|||
|
||||
const client = require('discord-rich-presence')('818936529484906596');
|
||||
|
||||
export function initIpcMain(win, store, lrc) {
|
||||
export function initIpcMain(win, store) {
|
||||
ipcMain.on('unblock-music', (event, track) => {
|
||||
// 兼容 unblockneteasemusic 所使用的 api 字段
|
||||
track.alias = track.alia || [];
|
||||
|
@ -128,14 +128,6 @@ export function initIpcMain(win, store, lrc) {
|
|||
store.set('proxy', '');
|
||||
});
|
||||
|
||||
ipcMain.on('resizeOSDLyrics', (event, arg) => {
|
||||
lrc.resizeOSDLyrics(arg);
|
||||
});
|
||||
|
||||
ipcMain.on('toggleOSDLyrics', () => {
|
||||
lrc.toggleOSDLyrics();
|
||||
});
|
||||
|
||||
ipcMain.on('switchGlobalShortcutStatusTemporary', (e, status) => {
|
||||
if (status === 'disable') {
|
||||
globalShortcut.unregisterAll();
|
||||
|
|
|
@ -5,7 +5,7 @@ const { app, Menu } = require('electron');
|
|||
|
||||
const isMac = process.platform === 'darwin';
|
||||
|
||||
export function createMenu(win, store, lrc) {
|
||||
export function createMenu(win, store) {
|
||||
let shortcuts = store.get('settings.shortcuts');
|
||||
if (shortcuts === undefined) {
|
||||
shortcuts = defaultShortcuts;
|
||||
|
@ -188,7 +188,6 @@ export function createMenu(win, store, lrc) {
|
|||
accelerator: 'F12',
|
||||
click: () => {
|
||||
win.webContents.openDevTools();
|
||||
lrc.openDevTools();
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -100,7 +100,6 @@ export default {
|
|||
pause: 'Pause',
|
||||
mute: 'Mute',
|
||||
nextUp: 'Next Up',
|
||||
osdLyrics: 'OSD Lyrics',
|
||||
},
|
||||
modal: {
|
||||
close: 'Close',
|
||||
|
|
|
@ -100,7 +100,6 @@ export default {
|
|||
pause: 'Durdur',
|
||||
mute: 'Sesi kapat',
|
||||
nextUp: 'Sıradaki',
|
||||
osdLyrics: 'masaüstü şarkı sözleri',
|
||||
},
|
||||
modal: {
|
||||
close: 'Kapat',
|
||||
|
|
|
@ -101,7 +101,6 @@ export default {
|
|||
pause: '暂停',
|
||||
mute: '静音',
|
||||
nextUp: '播放列表',
|
||||
osdLyrics: '桌面歌词',
|
||||
},
|
||||
modal: {
|
||||
close: '关闭',
|
||||
|
|
Loading…
Reference in New Issue
Block a user