diff --git a/package.json b/package.json index 5d071d0..2acb247 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "express-fileupload": "^1.2.0", "express-http-proxy": "^1.6.2", "extract-zip": "^2.0.1", - "howler": "^2.2.1", + "howler": "^2.2.3", "js-cookie": "^2.2.1", "lodash": "^4.17.20", "node-vibrant": "^3.1.6", diff --git a/src/api/lastfm.js b/src/api/lastfm.js index d41fe1b..41ad9c5 100644 --- a/src/api/lastfm.js +++ b/src/api/lastfm.js @@ -22,9 +22,10 @@ const sign = params => { }; export function auth() { - window.open( - `https://www.last.fm/api/auth/?api_key=${apiKey}&cb=${baseUrl}/#/lastfm/callback` - ); + const url = process.env.IS_ELECTRON + ? `https://www.last.fm/api/auth/?api_key=${apiKey}&cb=${baseUrl}/#/lastfm/callback` + : `https://www.last.fm/api/auth/?api_key=${apiKey}&cb=${baseUrl}/lastfm/callback`; + window.open(url); } export function authGetSession(token) { diff --git a/src/background.js b/src/background.js index e1fcfdd..c71d137 100644 --- a/src/background.js +++ b/src/background.js @@ -26,6 +26,11 @@ const log = text => { console.log(`${clc.blueBright('[background.js]')} ${text}`); }; +const isWindows = process.platform === 'win32'; +const isMac = process.platform === 'darwin'; +const isLinux = process.platform === 'linux'; +const isDevelopment = process.env.NODE_ENV === 'development'; + class Background { constructor() { this.window = null; @@ -38,7 +43,7 @@ class Background { }); this.neteaseMusicAPI = null; this.expressApp = null; - this.willQuitApp = process.platform === 'darwin' ? false : true; + this.willQuitApp = isMac ? false : true; this.init(); } @@ -73,7 +78,7 @@ class Background { } // Exit cleanly on request from parent process in development mode. - if (process.platform === 'win32') { + if (isWindows) { process.on('message', data => { if (data === 'graceful-exit') { app.quit(); @@ -119,7 +124,7 @@ class Background { minWidth: 1080, minHeight: 720, titleBarStyle: 'hiddenInset', - frame: process.platform !== 'win32', + frame: !isWindows, title: 'YesPlayMusic', show: false, webPreferences: { @@ -165,7 +170,7 @@ class Background { } checkForUpdates() { - if (process.env.NODE_ENV === 'development') return; + if (isDevelopment) return; log('checkForUpdates'); autoUpdater.checkForUpdatesAndNotify(); @@ -195,17 +200,20 @@ class Background { handleWindowEvents() { this.window.once('ready-to-show', () => { - log('windows ready-to-show event'); + log('window ready-to-show event'); this.window.show(); }); this.window.on('close', e => { - log('windows close event'); + log('window close event'); let closeOpt = this.store.get('settings.closeAppOption'); if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) { /* the user tried to quit the app */ this.window = null; app.quit(); + } else if (!this.willQuitApp && isMac) { + e.preventDefault(); + this.window.hide(); } else { /* the user only tried to close the window */ e.preventDefault(); @@ -223,7 +231,7 @@ class Background { this.window.on('minimize', () => { if ( - ['win32', 'linux'].includes(process.platform) && + !isMac && this.store.get('settings.closeAppOption') === 'minimizeToTray' ) { this.window.hide(); @@ -263,7 +271,7 @@ class Background { log('app ready event'); // for development - if (process.env.NODE_ENV === 'development') { + if (isDevelopment) { this.initDevtools(); } @@ -292,10 +300,7 @@ class Background { createMenu(this.window, this.store); // create tray - if ( - ['win32', 'linux'].includes(process.platform) || - process.env.NODE_ENV === 'development' - ) { + if (isWindows || isLinux || isDevelopment) { this.tray = createTray(this.window); } @@ -323,7 +328,7 @@ class Background { }); app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { + if (!isMac) { app.quit(); } }); diff --git a/src/components/Cover.vue b/src/components/Cover.vue index 4d79bc0..654d217 100644 --- a/src/components/Cover.vue +++ b/src/components/Cover.vue @@ -101,6 +101,7 @@ img { width: 100%; user-select: none; aspect-ratio: 1 / 1; + border: 1px solid rgba(0, 0, 0, 0.04); } .cover-hover { diff --git a/src/components/FMCard.vue b/src/components/FMCard.vue index 377bbe7..bb2c866 100644 --- a/src/components/FMCard.vue +++ b/src/components/FMCard.vue @@ -86,6 +86,7 @@ export default { this.getColor(); }, getColor() { + if (!this.player.personalFMTrack?.album?.picUrl) return; const cover = `${this.player.personalFMTrack.album.picUrl.replace( 'http://', 'https://' diff --git a/src/store/actions.js b/src/store/actions.js index 3053226..d29eb88 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -38,22 +38,26 @@ export default { } let like = true; if (state.liked.songs.includes(id)) like = false; - likeATrack({ id, like }).then(() => { - if (like === false) { - commit('updateLikedXXX', { - name: 'songs', - data: state.liked.songs.filter(d => d !== id), - }); - } else { - let newLikeSongs = state.liked.songs; - newLikeSongs.push(id); - commit('updateLikedXXX', { - name: 'songs', - data: newLikeSongs, - }); - } - dispatch('fetchLikedSongsWithDetails'); - }); + likeATrack({ id, like }) + .then(() => { + if (like === false) { + commit('updateLikedXXX', { + name: 'songs', + data: state.liked.songs.filter(d => d !== id), + }); + } else { + let newLikeSongs = state.liked.songs; + newLikeSongs.push(id); + commit('updateLikedXXX', { + name: 'songs', + data: newLikeSongs, + }); + } + dispatch('fetchLikedSongsWithDetails'); + }) + .catch(() => { + dispatch('showToast', '操作失败,专辑下架或版权锁定'); + }); }, fetchLikedSongs: ({ state, commit }) => { if (!isLooseLoggedIn()) return; @@ -140,7 +144,7 @@ export default { }, fetchLikedMVs: ({ commit }) => { if (!isAccountLoggedIn()) return; - return likedMVs({ limit: 2000 }).then(result => { + return likedMVs({ limit: 1000 }).then(result => { if (result.data) { commit('updateLikedXXX', { name: 'mvs', diff --git a/src/store/initLocalStorage.js b/src/store/initLocalStorage.js index b2a1dcf..59b50cd 100644 --- a/src/store/initLocalStorage.js +++ b/src/store/initLocalStorage.js @@ -17,14 +17,14 @@ let localStorage = { outputDevice: 'default', showPlaylistsByAppleMusic: true, enableUnblockNeteaseMusic: true, - automaticallyCacheSongs: false, - cacheLimit: false, + automaticallyCacheSongs: true, + cacheLimit: 8192, nyancatStyle: false, showLyricsTranslation: true, lyricsBackground: true, closeAppOption: 'ask', enableDiscordRichPresence: false, - enableGlobalShortcut: true, + enableGlobalShortcut: false, showLibraryDefault: false, enabledPlaylistCategories, proxyConfig: { diff --git a/src/utils/db.js b/src/utils/db.js index 411bbcb..6dfabeb 100644 --- a/src/utils/db.js +++ b/src/utils/db.js @@ -51,6 +51,7 @@ async function deleteExcessCache() { } export function cacheTrackSource(trackInfo, url, bitRate, from = 'netease') { + if (!process.env.IS_ELECTRON) return; const name = trackInfo.name; const artist = (trackInfo.ar && trackInfo.ar[0]?.name) || diff --git a/yarn.lock b/yarn.lock index 1156d07..257e6c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6355,10 +6355,10 @@ hosted-git-info@^4.0.1: dependencies: lru-cache "^6.0.0" -howler@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/howler/-/howler-2.2.1.tgz#a521a9b495841e8bb9aa12e651bebba0affc179e" - integrity sha512-0iIXvuBO/81CcrQ/HSSweYmbT50fT2mIc9XMFb+kxIfk2pW/iKzDbX1n3fZmDXMEIpYvyyfrB+gXwPYSDqUxIQ== +howler@^2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/howler/-/howler-2.2.3.tgz#a2eff9b08b586798e7a2ee17a602a90df28715da" + integrity sha512-QM0FFkw0LRX1PR8pNzJVAY25JhIWvbKMBFM4gqk+QdV+kPXOhleWGCB6AiAF/goGjIHK2e/nIElplvjQwhr0jg== hpack.js@^2.1.6: version "2.1.6"