mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 05:38:04 +00:00
chore: 将部分通用变量移动到utils.ts
This commit is contained in:
parent
78ba547138
commit
48869266e4
10 changed files with 24 additions and 33 deletions
|
|
@ -16,11 +16,7 @@ import { createTray, YPMTray } from './tray'
|
||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
import { createTaskbar, Thumbar } from './windowsTaskbar'
|
import { createTaskbar, Thumbar } from './windowsTaskbar'
|
||||||
import { Store as State, initialState } from '@/shared/store'
|
import { Store as State, initialState } from '@/shared/store'
|
||||||
|
import { isDev, isWindows, isLinux, isMac } from './utils'
|
||||||
const isWindows = process.platform === 'win32'
|
|
||||||
const isMac = process.platform === 'darwin'
|
|
||||||
const isLinux = process.platform === 'linux'
|
|
||||||
const isDev = process.env.NODE_ENV === 'development'
|
|
||||||
|
|
||||||
export interface TypedElectronStore {
|
export interface TypedElectronStore {
|
||||||
window: {
|
window: {
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,14 @@
|
||||||
|
|
||||||
import log from 'electron-log'
|
import log from 'electron-log'
|
||||||
import pc from 'picocolors'
|
import pc from 'picocolors'
|
||||||
|
import { isDev } from './utils'
|
||||||
|
|
||||||
Object.assign(console, log.functions)
|
Object.assign(console, log.functions)
|
||||||
log.variables.process = 'main'
|
log.variables.process = 'main'
|
||||||
log.transports.console.format = `[{process}] ${pc.dim(
|
if (log.transports.ipc) log.transports.ipc.level = false
|
||||||
'{h}:{i}:{s}{scope}'
|
log.transports.console.format = `${
|
||||||
)} {level} › {text}`
|
isDev ? '' : pc.dim('{h}:{i}:{s}{scope} ')
|
||||||
|
}{level} › {text}`
|
||||||
log.transports.file.level = 'info'
|
log.transports.file.level = 'info'
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
import log from './log'
|
import log from './log'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import { createDirIfNotExist } from './utils'
|
import { createDirIfNotExist, isDev } from './utils'
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development'
|
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
const devUserDataPath = path.resolve(process.cwd(), '../../tmp/userData')
|
const devUserDataPath = path.resolve(process.cwd(), '../../tmp/userData')
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
|
import { isLinux, isMac, isWindows } from './utils'
|
||||||
const { contextBridge, ipcRenderer } = require('electron')
|
const { contextBridge, ipcRenderer } = require('electron')
|
||||||
const log = require('electron-log')
|
const log = require('electron-log')
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development'
|
|
||||||
|
|
||||||
log.transports.file.level = 'info'
|
log.transports.file.level = 'info'
|
||||||
|
log.transports.ipc.level = false
|
||||||
log.variables.process = 'renderer'
|
log.variables.process = 'renderer'
|
||||||
log.transports.console.format = isDev
|
|
||||||
? `[{process}] {text}`
|
|
||||||
: `[{process}] {h}:{i}:{s}{scope} {level} › {text}`
|
|
||||||
contextBridge.exposeInMainWorld('log', log)
|
contextBridge.exposeInMainWorld('log', log)
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('ipcRenderer', {
|
contextBridge.exposeInMainWorld('ipcRenderer', {
|
||||||
|
|
@ -30,7 +27,7 @@ contextBridge.exposeInMainWorld('env', {
|
||||||
isElectron: true,
|
isElectron: true,
|
||||||
isEnableTitlebar:
|
isEnableTitlebar:
|
||||||
process.platform === 'win32' || process.platform === 'linux',
|
process.platform === 'win32' || process.platform === 'linux',
|
||||||
isLinux: process.platform === 'linux',
|
isLinux,
|
||||||
isMac: process.platform === 'darwin',
|
isMac,
|
||||||
isWin: process.platform === 'win32',
|
isWindows,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const pkg = require(`${process.cwd()}/package.json`)
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const { execSync } = require('child_process')
|
const { execSync } = require('child_process')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const { isLinux, isWindows, isMac } = require('../utils')
|
||||||
|
|
||||||
const electronVersion = pkg.devDependencies.electron.replaceAll('^', '')
|
const electronVersion = pkg.devDependencies.electron.replaceAll('^', '')
|
||||||
const betterSqlite3Version = pkg.dependencies['better-sqlite3'].replaceAll(
|
const betterSqlite3Version = pkg.dependencies['better-sqlite3'].replaceAll(
|
||||||
|
|
@ -18,9 +19,6 @@ const electronModuleVersion = releases.find(r =>
|
||||||
r.version.includes(electronVersion)
|
r.version.includes(electronVersion)
|
||||||
)?.deps?.modules
|
)?.deps?.modules
|
||||||
const argv = minimist(process.argv.slice(2))
|
const argv = minimist(process.argv.slice(2))
|
||||||
const isWin = process.platform === 'win32'
|
|
||||||
const isMac = process.platform === 'darwin'
|
|
||||||
const isLinux = process.platform === 'linux'
|
|
||||||
|
|
||||||
const projectDir = path.resolve(process.cwd(), '../../')
|
const projectDir = path.resolve(process.cwd(), '../../')
|
||||||
|
|
||||||
|
|
@ -119,7 +117,7 @@ const main = async () => {
|
||||||
if (argv.arm64) await build('arm64')
|
if (argv.arm64) await build('arm64')
|
||||||
if (argv.arm) await build('arm')
|
if (argv.arm) await build('arm')
|
||||||
} else {
|
} else {
|
||||||
if (isWin || isMac) {
|
if (isWindows || isMac) {
|
||||||
await build('x64')
|
await build('x64')
|
||||||
await build('arm64')
|
await build('arm64')
|
||||||
} else if (isLinux) {
|
} else if (isLinux) {
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,7 @@ import { app } from 'electron'
|
||||||
import type { FetchAudioSourceResponse } from '@/shared/api/Track'
|
import type { FetchAudioSourceResponse } from '@/shared/api/Track'
|
||||||
import UNM from '@unblockneteasemusic/rust-napi'
|
import UNM from '@unblockneteasemusic/rust-napi'
|
||||||
import { APIs as CacheAPIs } from '../shared/CacheAPIs'
|
import { APIs as CacheAPIs } from '../shared/CacheAPIs'
|
||||||
|
import { isProd } from 'utils'
|
||||||
const isDev = process.env.NODE_ENV === 'development'
|
|
||||||
const isProd = process.env.NODE_ENV === 'production'
|
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
port = Number(
|
port = Number(
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,10 @@ export const createFileIfNotExist = (file: string) => {
|
||||||
fs.writeFileSync(file, '')
|
fs.writeFileSync(file, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isDev = process.env.NODE_ENV === 'development'
|
||||||
|
export const isProd = process.env.NODE_ENV === 'production'
|
||||||
|
export const isWindows = process.platform === 'win32'
|
||||||
|
export const isMac = process.platform === 'darwin'
|
||||||
|
export const isLinux = process.platform === 'linux'
|
||||||
|
export const dirname = isDev ? process.cwd() : __dirname
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ const Linux = () => {
|
||||||
const TitleBar = () => {
|
const TitleBar = () => {
|
||||||
return (
|
return (
|
||||||
<div className='app-region-drag fixed z-30'>
|
<div className='app-region-drag fixed z-30'>
|
||||||
{window.env?.isWin ? <Win /> : <Linux />}
|
{window.env?.isWindows ? <Win /> : <Linux />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
packages/web/global.d.ts
vendored
2
packages/web/global.d.ts
vendored
|
|
@ -27,7 +27,7 @@ declare global {
|
||||||
isEnableTitlebar: boolean
|
isEnableTitlebar: boolean
|
||||||
isLinux: boolean
|
isLinux: boolean
|
||||||
isMac: boolean
|
isMac: boolean
|
||||||
isWin: boolean
|
isWindows: boolean
|
||||||
}
|
}
|
||||||
log?: ElectronLog
|
log?: ElectronLog
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { proxy, subscribe } from 'valtio'
|
import { proxy, subscribe } from 'valtio'
|
||||||
import { devtools } from 'valtio/utils'
|
|
||||||
import { Player } from '@/web/utils/player'
|
import { Player } from '@/web/utils/player'
|
||||||
import { merge } from 'lodash-es'
|
import { merge } from 'lodash-es'
|
||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
|
|
@ -34,7 +33,3 @@ subscribe(player, () => {
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
;(window as any).player = player
|
;(window as any).player = player
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devtools
|
|
||||||
devtools(state, 'state')
|
|
||||||
devtools(player, 'player')
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue