mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 21:58:03 +00:00
feat: updates
This commit is contained in:
parent
ce757215a3
commit
c1cd31840e
86 changed files with 1048 additions and 778 deletions
|
|
@ -9,7 +9,8 @@ const electronVersion = pkg.devDependencies.electron.replaceAll('^', '')
|
|||
module.exports = {
|
||||
appId: 'app.r3play',
|
||||
productName: pkg.productName,
|
||||
copyright: 'Copyright © 2022 qier222',
|
||||
executableName: pkg.productName,
|
||||
copyright: 'Copyright © 2023 qier222',
|
||||
asar: true,
|
||||
directories: {
|
||||
output: 'release',
|
||||
|
|
@ -70,14 +71,14 @@ module.exports = {
|
|||
},
|
||||
linux: {
|
||||
target: [
|
||||
{
|
||||
target: 'deb',
|
||||
arch: [
|
||||
'x64',
|
||||
// 'arm64',
|
||||
// 'armv7l'
|
||||
],
|
||||
},
|
||||
// {
|
||||
// target: 'deb',
|
||||
// arch: [
|
||||
// 'x64',
|
||||
// // 'arm64',
|
||||
// // 'armv7l'
|
||||
// ],
|
||||
// },
|
||||
{
|
||||
target: 'AppImage',
|
||||
arch: ['x64'],
|
||||
|
|
@ -105,19 +106,13 @@ module.exports = {
|
|||
},
|
||||
files: [
|
||||
'!**/*.ts',
|
||||
'!**/node_modules/better-sqlite3/{bin,build,deps}/**',
|
||||
'!**/node_modules/*/{*.MD,*.md,README,readme}',
|
||||
'!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}',
|
||||
'!**/node_modules/*.d.ts',
|
||||
'!**/node_modules/.bin',
|
||||
'!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}',
|
||||
'!.editorconfig',
|
||||
'!**/._*',
|
||||
'!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}',
|
||||
'!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}',
|
||||
'!**/{appveyor.yml,.travis.yml,circle.yml}',
|
||||
'!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json,pnpm-lock.yaml}',
|
||||
'!**/{pnpm-lock.yaml}',
|
||||
'!**/*.{map,debug.min.js}',
|
||||
'!**/node_modules/*',
|
||||
|
||||
{
|
||||
from: './dist',
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import path from 'path'
|
||||
import { isProd } from '../env'
|
||||
import log from '../log'
|
||||
import appleMusic from './routes/r3play/appleMusic'
|
||||
import netease from './routes/netease/netease'
|
||||
import audio from './routes/r3play/audio'
|
||||
import fastifyCookie from '@fastify/cookie'
|
||||
import fastifyMultipart from '@fastify/multipart'
|
||||
import fastifyStatic from '@fastify/static'
|
||||
import fastify from 'fastify'
|
||||
import path from 'path'
|
||||
import { isProd } from '../env'
|
||||
import log from '../log'
|
||||
import netease from './routes/netease/netease'
|
||||
import appleMusic from './routes/r3play/appleMusic'
|
||||
import audio from './routes/r3play/audio'
|
||||
|
||||
log.info('[electron] appServer/appServer.ts')
|
||||
|
||||
const initAppServer = async () => {
|
||||
const server = fastify({
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import cache from '../../../cache'
|
||||
import log from '@/desktop/main/log'
|
||||
import { CacheAPIs } from '@/shared/CacheAPIs'
|
||||
import { pathCase, snakeCase } from 'change-case'
|
||||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'
|
||||
import NeteaseCloudMusicApi from 'NeteaseCloudMusicApi'
|
||||
import cache from '../../../cache'
|
||||
|
||||
log.info('[electron] appServer/routes/netease.ts')
|
||||
|
||||
async function netease(fastify: FastifyInstance) {
|
||||
const getHandler = (name: string, neteaseApi: (params: any) => any) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { FastifyInstance } from 'fastify'
|
||||
import proxy from '@fastify/http-proxy'
|
||||
import { isDev } from '@/desktop/main/env'
|
||||
import log from '@/desktop/main/log'
|
||||
|
||||
log.info('[electron] appServer/routes/r3play/appleMusic.ts')
|
||||
|
||||
async function appleMusic(fastify: FastifyInstance) {
|
||||
fastify.register(proxy, {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import { FetchTracksResponse } from '@/shared/api/Track'
|
|||
import store from '@/desktop/main/store'
|
||||
import { db, Tables } from '@/desktop/main/db'
|
||||
|
||||
log.info('[electron] appServer/routes/r3play/audio.ts')
|
||||
|
||||
const getAudioFromCache = async (id: number) => {
|
||||
// get from cache
|
||||
const cache = await db.find(Tables.Audio, id)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import { CacheAPIs, CacheAPIsParams } from '@/shared/CacheAPIs'
|
|||
import { TablesStructures } from './db'
|
||||
import { FastifyReply } from 'fastify'
|
||||
|
||||
log.info('[electron] cache.ts')
|
||||
|
||||
class Cache {
|
||||
constructor() {
|
||||
//
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import pkg from '../../../package.json'
|
|||
import { compare, validate } from 'compare-versions'
|
||||
import os from 'os'
|
||||
|
||||
log.info('[electron] db.ts')
|
||||
|
||||
export const enum Tables {
|
||||
Track = 'Track',
|
||||
Album = 'Album',
|
||||
|
|
@ -108,7 +110,7 @@ class DB {
|
|||
const prodBinPaths = {
|
||||
darwin: path.resolve(app.getPath('exe'), `../../Resources/bin/better_sqlite3.node`),
|
||||
win32: path.resolve(app.getPath('exe'), `../resources/bin/better_sqlite3.node`),
|
||||
linux: '',
|
||||
linux: path.resolve(app.getPath('exe'), `../resources/bin/better_sqlite3.node`),
|
||||
}
|
||||
return isProd
|
||||
? prodBinPaths[os.platform as unknown as 'darwin' | 'win32' | 'linux']
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import { isDev, isWindows, isLinux, isMac, appName } from './env'
|
|||
import store from './store'
|
||||
import initAppServer from './appServer/appServer'
|
||||
|
||||
log.info('[electron] index.ts')
|
||||
|
||||
class Main {
|
||||
win: BrowserWindow | null = null
|
||||
tray: YPMTray | null = null
|
||||
|
|
@ -103,7 +105,7 @@ class Main {
|
|||
|
||||
// Make all links open with the browser, not with the application
|
||||
this.win.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith('https:')) shell.openExternal(url)
|
||||
if (url.startsWith('https://')) shell.openExternal(url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
|
|
|
|||
29
packages/desktop/main/ipcMain.ts
Normal file → Executable file
29
packages/desktop/main/ipcMain.ts
Normal file → Executable file
|
|
@ -14,6 +14,8 @@ import path from 'path'
|
|||
import prettyBytes from 'pretty-bytes'
|
||||
import { db, Tables } from './db'
|
||||
|
||||
log.info('[electron] ipcMain.ts')
|
||||
|
||||
const on = <T extends keyof IpcChannelsParams>(
|
||||
channel: T,
|
||||
listener: (event: Electron.IpcMainEvent, params: IpcChannelsParams[T]) => void
|
||||
|
|
@ -50,9 +52,30 @@ function initWindowIpcMain(win: BrowserWindow | null) {
|
|||
win?.minimize()
|
||||
})
|
||||
|
||||
let isMaximized = false
|
||||
let unMaximizeSize: { width: number; height: number } | null = null
|
||||
let windowPosition: { x: number; y: number } | null = null
|
||||
on(IpcChannels.MaximizeOrUnmaximize, () => {
|
||||
if (!win) return
|
||||
win.isMaximized() ? win.unmaximize() : win.maximize()
|
||||
if (!win) return false
|
||||
|
||||
if (isMaximized) {
|
||||
if (unMaximizeSize) {
|
||||
win.setSize(unMaximizeSize.width, unMaximizeSize.width, true)
|
||||
}
|
||||
if (windowPosition) {
|
||||
win.setPosition(windowPosition.x, windowPosition.y, true)
|
||||
}
|
||||
win.unmaximize()
|
||||
} else {
|
||||
const size = win.getSize()
|
||||
unMaximizeSize = { width: size[1], height: size[0] }
|
||||
const position = win.getPosition()
|
||||
windowPosition = { x: position[0], y: position[1] }
|
||||
win.maximize()
|
||||
}
|
||||
|
||||
isMaximized = !isMaximized
|
||||
win.webContents.send(IpcChannels.IsMaximized, isMaximized)
|
||||
})
|
||||
|
||||
on(IpcChannels.Close, () => {
|
||||
|
|
@ -66,7 +89,7 @@ function initWindowIpcMain(win: BrowserWindow | null) {
|
|||
|
||||
handle(IpcChannels.IsMaximized, () => {
|
||||
if (!win) return
|
||||
return win.isMaximized()
|
||||
return isMaximized
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/** By default, it writes logs to the following locations:
|
||||
* on Linux: ~/.config/r3play/logs/main.log
|
||||
* on Linux: ~/.config/R3PLAY/logs/main.log
|
||||
* on macOS: ~/Library/Logs/r3play/main.log
|
||||
* on Windows: %USERPROFILE%\AppData\Roaming\r3play\logs\main.log
|
||||
* @see https://www.npmjs.com/package/electron-log
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemConstructorOptions,
|
||||
shell,
|
||||
} from 'electron'
|
||||
import { app, BrowserWindow, Menu, MenuItem, MenuItemConstructorOptions, shell } from 'electron'
|
||||
import { isMac } from './env'
|
||||
import { logsPath } from './utils'
|
||||
import { exec } from 'child_process'
|
||||
import log from './log'
|
||||
|
||||
log.info('[electron] menu.ts')
|
||||
|
||||
export const createMenu = (win: BrowserWindow) => {
|
||||
const template: Array<MenuItemConstructorOptions | MenuItem> = [
|
||||
|
|
@ -51,9 +47,7 @@ export const createMenu = (win: BrowserWindow) => {
|
|||
{
|
||||
label: '反馈问题',
|
||||
click: async () => {
|
||||
await shell.openExternal(
|
||||
'https://github.com/qier222/YesPlayMusic/issues/new'
|
||||
)
|
||||
await shell.openExternal('https://github.com/qier222/YesPlayMusic/issues/new')
|
||||
},
|
||||
},
|
||||
{ type: 'separator' },
|
||||
|
|
@ -66,17 +60,13 @@ export const createMenu = (win: BrowserWindow) => {
|
|||
{
|
||||
label: '访问论坛',
|
||||
click: async () => {
|
||||
await shell.openExternal(
|
||||
'https://github.com/qier222/YesPlayMusic/discussions'
|
||||
)
|
||||
await shell.openExternal('https://github.com/qier222/YesPlayMusic/discussions')
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '加入交流群',
|
||||
click: async () => {
|
||||
await shell.openExternal(
|
||||
'https://github.com/qier222/YesPlayMusic/discussions'
|
||||
)
|
||||
await shell.openExternal('https://github.com/qier222/YesPlayMusic/discussions')
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import Store from 'electron-store'
|
||||
import log from './log'
|
||||
|
||||
log.info('[electron] store.ts')
|
||||
|
||||
export interface TypedElectronStore {
|
||||
window: {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
import path from 'path'
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
Menu,
|
||||
MenuItemConstructorOptions,
|
||||
nativeImage,
|
||||
Tray,
|
||||
} from 'electron'
|
||||
import { app, BrowserWindow, Menu, MenuItemConstructorOptions, nativeImage, Tray } from 'electron'
|
||||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { RepeatMode } from '@/shared/playerDataTypes'
|
||||
import { appName } from './env'
|
||||
import log from './log'
|
||||
|
||||
log.info('[electron] tray.ts')
|
||||
|
||||
const iconDirRoot =
|
||||
process.env.NODE_ENV === 'development'
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import path from 'path'
|
|||
import os from 'os'
|
||||
import pkg from '../../../package.json'
|
||||
import { appName, isDev } from './env'
|
||||
import log from './log'
|
||||
|
||||
log.info('[electron] utils.ts')
|
||||
|
||||
export const dirname = isDev ? process.cwd() : __dirname
|
||||
export const devUserDataPath = path.resolve(process.cwd(), '../../tmp/userData')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { BrowserWindow, nativeImage, ThumbarButton } from 'electron'
|
||||
import path from 'path'
|
||||
import log from './log'
|
||||
|
||||
log.info('[electron] windowsTaskbar.ts')
|
||||
|
||||
enum ItemKeys {
|
||||
Play = 'play',
|
||||
|
|
@ -66,15 +69,11 @@ class ThumbarImpl implements Thumbar {
|
|||
}
|
||||
|
||||
private _updateThumbarButtons(clear: boolean) {
|
||||
this._win.setThumbarButtons(
|
||||
clear ? [] : [this._previous, this._playOrPause, this._next]
|
||||
)
|
||||
this._win.setThumbarButtons(clear ? [] : [this._previous, this._playOrPause, this._next])
|
||||
}
|
||||
|
||||
setPlayState(isPlaying: boolean) {
|
||||
this._playOrPause = this._buttons.get(
|
||||
isPlaying ? ItemKeys.Pause : ItemKeys.Play
|
||||
)!
|
||||
this._playOrPause = this._buttons.get(isPlaying ? ItemKeys.Pause : ItemKeys.Play)!
|
||||
this._updateThumbarButtons(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"main": "./main/index.js",
|
||||
"author": "*",
|
||||
"author": "qier222 <qier222@outlook.com>",
|
||||
"homepage": "https://github.com/qier222/YesPlayMusic",
|
||||
"scripts": {
|
||||
"postinstall": "tsx scripts/build.sqlite3.ts",
|
||||
"dev": "tsx scripts/build.main.ts --watch",
|
||||
|
|
@ -25,7 +26,6 @@
|
|||
"@fastify/multipart": "^7.4.0",
|
||||
"@fastify/static": "^6.6.1",
|
||||
"@sentry/electron": "^3.0.7",
|
||||
"@yimura/scraper": "^1.2.4",
|
||||
"NeteaseCloudMusicApi": "^4.8.9",
|
||||
"better-sqlite3": "8.1.0",
|
||||
"change-case": "^4.1.2",
|
||||
|
|
@ -41,10 +41,10 @@
|
|||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^7.6.3",
|
||||
"@vitest/ui": "^0.20.3",
|
||||
"axios": "^1.2.1",
|
||||
"axios": "^1.3.4",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"electron": "^23.1.1",
|
||||
"electron": "^23.1.4",
|
||||
"electron-builder": "23.6.0",
|
||||
"electron-devtools-installer": "^3.2.0",
|
||||
"electron-rebuild": "^3.2.9",
|
||||
|
|
|
|||
|
|
@ -39,10 +39,11 @@ exports.default = async function (context) {
|
|||
}
|
||||
}
|
||||
|
||||
if (platform === 'win32') {
|
||||
if (arch !== 'x64') return // Skip other archs
|
||||
// Windows and Linux
|
||||
if (platform === 'win32' || platform === 'linux') {
|
||||
if (platform === 'win32' && arch !== 'x64') return // Skip windows arm
|
||||
|
||||
const from = `${binDir}/better_sqlite3_win32_${arch}.node`
|
||||
const from = `${binDir}/better_sqlite3_${platform}_${arch}.node`
|
||||
const to = `${context.appOutDir}/resources/bin/better_sqlite3.node`
|
||||
console.info(`copy ${from} to ${to}`)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue