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