Skip to content

Commit

Permalink
1. 修复了掉登陆的问题;
Browse files Browse the repository at this point in the history
2. 新增:底部的播放栏点击歌曲名的跳转功能优化;
3. 修复在window、linux下移动窗口卡顿、崩溃的bug;
4. 新增windows支持自定义安装路径;
5. linux新增适配歌词插件功能,可通过插件实现状态栏歌词功能;
  • Loading branch information
stark81 committed Dec 28, 2024
1 parent 91acfdb commit 0367ef2
Show file tree
Hide file tree
Showing 23 changed files with 363 additions and 31 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
## 推广
- 本项目使用低版本的node、低版本electron,导致某些功能,如Linux下的桌面歌词体验不佳;
- 本地音乐的匹配问题。项目集成的express + NeteaseCloudMusicApi无法使用search_match这个API(本地音乐匹配线上信息),每次使用都只显示参数错误,导致本项目的本地歌曲只能使用“搜索 + 筛选”的方式(该方式增加搜索间隔来避免搜索功能被封)来进行匹配,效率低下;
- 更新API的依赖后,由于未知bug导致掉登陆,即登陆后几分钟内便会自动登出(自动登出不会导致封号);
- 基于以上几个原因,在解决掉登陆的问题之前,本人将暂停本项目的更新,转而维护自己开发的另一个项目:[VutronMusic](https://github.com/stark81/VutronMusic)。其他用户如果发现本项目掉登陆的原因,请提issue或者pull request,本人会尽快更新处理。
- 基于以上两个原因,本项目开始转向维护阶段,更新频率将会有所下降,转而维护另一个项目:[VutronMusic](https://github.com/stark81/VutronMusic)
- 该项目使用vue3 + ts + better-sqlite3 + fastify + pinia + electron32+进行开发,且可快速进行electron版本更新,以保障用户体验;
- 该项目暂时仅支持客户端,不会像YesPlayMusic一样支持web端,因此无法实现Vercel部署、服务器部署等功能。如果需要可以自行fork后进行修改;
- UI界面和功能大量【参考和复用】[YesPlayMusic](https://github.com/qier222/YesPlayMusic),延续了YesPlayMusic的美观和优雅;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"core-js": "^3.6.5",
"crypto-js": "^4.0.0",
"dayjs": "^1.8.36",
"dbus-native": "^0.4.0",
"dexie": "^3.0.3",
"discord-rich-presence": "^0.0.8",
"electron": "^13.6.7",
Expand Down
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,19 @@ export default {
created() {
if (this.isElectron) {
ipcRenderer(this);
const render = require('electron').ipcRenderer;
const show_menu = isMac
? this.settings.showLyricsMenu &&
!this.settings.showStatusBarLyric &&
!this.settings.showControl
: true;
if (show_menu) {
const render = require('electron').ipcRenderer;
render.send('switchRepeatMode', this.player.repeatMode);
render.send('switchShuffle', this.player.shuffle);
}
render.invoke('checkExtensionStatus').then(res => {
this.$store.commit('updateDBusStatus', res);
});
}
if (isMac && this.isElectron) {
const { initMacStatusbarLyric } = require('./utils/macStatusBarLyric');
Expand Down
22 changes: 16 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,15 @@ class Background {
this.store.set('osdlyrics.height', height);
});

let moveTimeout;
this.osdlyrics.on('move', () => {
var pos = this.osdlyrics.getPosition();
this.store.set('osdlyrics.x_pos', pos[0]);
this.store.set('osdlyrics.y_pos', pos[1]);
if (moveTimeout) clearTimeout(moveTimeout);

moveTimeout = setTimeout(() => {
var pos = this.osdlyrics.getPosition();
this.store.set('osdlyrics.x_pos', pos[0]);
this.store.set('osdlyrics.y_pos', pos[1]);
}, 500);
});
}

Expand Down Expand Up @@ -457,10 +462,15 @@ class Background {
this.store.set('window', this.window.getBounds());
});

let moveTimeout;
this.window.on('move', () => {
var pos = this.window.getPosition();
this.store.set('window.x', pos[0]);
this.store.set('window.y', pos[1]);
if (moveTimeout) clearTimeout(moveTimeout);

moveTimeout = setTimeout(() => {
var pos = this.window.getPosition();
this.store.set('window.x', pos[0]);
this.store.set('window.y', pos[1]);
}, 500);
});

this.window.on('maximize', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Cover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
playActions[this.type].bind(player)(
trackIDs.slice().reverse(),
this.id,
'localMusic',
'localPlaylist',
'first'
);
} else {
Expand Down
15 changes: 12 additions & 3 deletions src/components/TrackList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
:column-number="columnNumber"
:show-position="showPosition"
:item-size="itemSize"
:pid="id"
:type="type"
:enabled="enabled"
>
Expand All @@ -112,7 +113,7 @@
ref="trackListItemRef"
:key="itemKey === 'id' ? item.id : `${item.id}${index}`"
:track-prop="item"
:type="type"
:type="type === 'localTracklist' ? 'tracklist' : type"
:track-no="index + 1"
:album-object="albumObject"
:batch-op="isBatchOp"
Expand Down Expand Up @@ -307,9 +308,17 @@ export default {
} else if (this.type === 'tracklist') {
let trackIDs = this.tracks.map(t => t.id);
this.player.replacePlaylist(trackIDs, this.id, 'artist', trackID);
} else if (this.type === 'localTracks') {
} else if (
this.type === 'localPlaylist' ||
this.type === 'localTracklist'
) {
let trackIDs = this.tracks.map(t => t.id);
this.player.replacePlaylist(trackIDs, this.id, 'localTracks', trackID);
this.player.replacePlaylist(
trackIDs,
this.id,
'localPlaylist',
trackID
);
}
},
scrollTo(top, behavior = 'smooth') {
Expand Down
3 changes: 2 additions & 1 deletion src/components/VirtualScroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export default {
return (
(this.playlistSource.type === this.type &&
this.playlistSource.id === this.pid) ||
(this.playlistSource.type === this.type && this.type === 'localtracks')
(this.playlistSource.type === this.type &&
this.type === 'localPlaylist')
);
},
rightClickedTrack() {
Expand Down
72 changes: 72 additions & 0 deletions src/electron/dbus-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class ServiceMonitor {
constructor(busName, win) {
this.interfaceName = 'org.freedesktop.DBus';
this.objectPath = '/org/freedesktop/DBus';
this.busName = busName;
this.status = false;
this.win = win;
this.iface = null;
this.sessionBus = require('dbus-native').sessionBus();
this.watchName();
}

watchName() {
this.sessionBus.getInterface(
this.interfaceName,
this.objectPath,
this.interfaceName,
(err, iface) => {
if (err) {
console.error('error getting interface:', err);
return;
}
iface.on('NameOwnerChanged', (name, oldOwner, newOwner) => {
if (name === this.busName) {
const isRunning = !!newOwner;

if (isRunning) {
this.onOwnerName();
} else {
this.onLostOwnerName();
}
}
});

iface.GetNameOwner(this.busName, err => {
if (err) {
this.onLostOwnerName();
} else {
this.onOwnerName();
}
});
}
);
}

onOwnerName() {
const path = `/${this.busName.replace(/\./g, '/')}`;
this.sessionBus
.getService(this.busName)
.getInterface(path, this.busName, (err, iface) => {
if (err) {
console.error('error getting interface:', err);
this.status = false;
this.win.webContents.send('dbus-status', this.status);
return;
}

this.iface = iface;
this.status = true;
this.win.webContents.send('dbus-status', this.status);
});
}

onLostOwnerName() {
this.status = false;
this.win.webContents.send('dbus-status', this.status);
}
}

export const createDBus = (busName, win) => {
return new ServiceMonitor(busName, win);
};
13 changes: 13 additions & 0 deletions src/electron/ipcMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { registerGlobalShortcut } from '@/electron/globalShortcut';
import cloneDeep from 'lodash/cloneDeep';
import shortcuts from '@/utils/shortcuts';
import { createMenu } from './menu';
import { createDBus } from './dbus-client';
import { isCreateTray, isMac } from '@/utils/platform';

let lyrics;
Expand Down Expand Up @@ -411,5 +412,17 @@ export function initIpcMain(win, store, tray, lrc) {
return null;
}
});

const busName = 'org.gnome.Shell.TrayLyric';
const dbus = createDBus(busName, win);

ipcMain.handle('checkExtensionStatus', () => {
return dbus.status;
});

ipcMain.on('updateCurrentLyric', (_, data) => {
data.sender = 'YesPlayMusic';
dbus.iface.UpdateLyric(JSON.stringify(data));
});
}
}
5 changes: 5 additions & 0 deletions src/electron/ipcRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ export function ipcRenderer(vueInstance) {
ipcRenderer.on('setPosition', (event, position) => {
player._howler.seek(position);
});

ipcRenderer.on('dbus-status', (event, status) => {
console.log('dbus-status', status);
store.commit('updateDBusStatus', status);
});
}
2 changes: 1 addition & 1 deletion src/electron/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function createMpris(window) {
const renderer = window.webContents;

const player = Player({
name: 'yesplaymusic',
name: 'YesPlayMusic',
identity: 'YesPlayMusic',
});

Expand Down
7 changes: 7 additions & 0 deletions src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export default {
localMusicPath: '本地歌曲扫描路径',
localMusicMatchedStatus: '本地歌曲匹配状态',
},
extension: {
status: '歌词插件服务状态',
showLyric: {
text: '显示状态栏歌词',
desc: '该功能需要安装并启用歌词插件服务',
},
},
},
contextMenu: {
play: '播放',
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ window.resetApp = () => {
.replace(/^ +/, '')
.replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
});
document.cookie = 'os = pc';
return '已重置应用,请刷新页面(按Ctrl/Command + R)';
};
window.resetPlayer = () => {
localStorage.removeItem('player');
return '已重置播放器,请刷新页面(按Ctrl/Command + R)';
};

document.cookie = 'os = pc';

console.log(
'如出现问题,可尝试在本页输入 %cresetApp()%c 然后按回车重置应用。',
'background: #eaeffd;color:#335eea;padding: 4px 6px;border-radius:3px;',
Expand Down
1 change: 1 addition & 0 deletions src/store/initLocalStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let localStorage = {
},
shortcuts: shortcuts,
showOsdLyric: false,
sendLyricToDBus: false,
},
data: {
user: {},
Expand Down
3 changes: 3 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default {
toggleLyrics(state) {
state.showLyrics = !state.showLyrics;
},
updateDBusStatus(state, status) {
state.extensionStatus = status;
},
toggleUpdateStatus(state) {
state.updateFlag = !state.updateFlag;
},
Expand Down
1 change: 1 addition & 0 deletions src/store/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ updateApp();

export default {
showLyrics: false,
extensionStatus: false,
updateFlag: true,
enableScrolling: true,
enabledVirtualScroll: false,
Expand Down
11 changes: 10 additions & 1 deletion src/utils/playList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { isAccountLoggedIn } from '@/utils/auth';

export function hasListSource() {
return !state.player.isPersonalFM && state.player.playlistSource.id !== 0;
return (
!state.player.isPersonalFM &&
(state.player.playlistSource.id !== 0 ||
state.player.playlistSource.type.includes('local'))
);
}

export function goToListSource() {
Expand All @@ -22,6 +26,11 @@ export function getListSourcePath() {
return state.player.playlistSource.id;
} else if (state.player.playlistSource.type === 'cloudDisk') {
return '/library';
} else if (
state.player.playlistSource.type.includes('local') &&
state.player.playlistSource.id === 0
) {
return '/local-music';
} else {
return `/${state.player.playlistSource.type}/${state.player.playlistSource.id}`;
}
Expand Down
7 changes: 4 additions & 3 deletions src/views/localMusic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
</div>
<div class="songs">
<TrackList
:id="sortedTracks.id"
:id="0"
:tracks="randomShowTracks"
:column-number="3"
type="tracklist"
type="localTracklist"
:show-position="false"
:item-size="57"
:enabled="false"
Expand Down Expand Up @@ -114,10 +114,11 @@

<div v-show="currentTab === 'localSongs'">
<TrackList
:id="0"
ref="trackListRef"
:tracks="filterLocalTracks"
:column-number="1"
type="localTracks"
type="localPlaylist"
:is-batch-op="isBatchOp"
:extra-context-menu-item="[
'showInFolder',
Expand Down
Loading

0 comments on commit 0367ef2

Please sign in to comment.