从webpack迁移到vite

This commit is contained in:
lyswhut
2023-08-07 18:49:14 +08:00
parent 31e16a7ed7
commit 028bf5919d
166 changed files with 3071 additions and 11869 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
import WebSocket from 'ws'
import { encryptMsg, decryptMsg } from './utils'
import * as modules from './modules'
// import { action as commonAction } from '@/store/modules/common'
// import { getStore } from '@/store'
// import { action as commonAction } from '@root/store/modules/common'
// import { getStore } from '@root/store'
import registerSyncListHandler from './syncList'
import log from '../log'
import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants'
+1 -1
View File
@@ -1,6 +1,6 @@
import handleAuth from './auth'
import { connect as socketConnect, disconnect as socketDisconnect, sendSyncStatus, sendSyncMessage } from './client'
// import { getSyncHost } from '@/utils/data'
// import { getSyncHost } from '@root/utils/data'
import { SYNC_CODE } from '@common/constants'
import log from '../log'
import { parseUrl } from './utils'
+3 -3
View File
@@ -1,6 +1,6 @@
import { Tray, Menu, nativeImage } from 'electron'
import { isWin } from '@common/utils'
import { join } from 'path'
import path from 'node:path'
import {
hideWindow as hideMainWindow,
isExistWindow as isExistMainWindow,
@@ -45,7 +45,7 @@ export const createTray = () => {
themeId = global.lx.appSetting['tray.themeId']
let theme = themeList.find(item => item.id === themeId) ?? themeList[0]
const iconPath = join(global.staticPath, 'images/tray', theme.fileName + '.png')
const iconPath = path.join(global.staticPath, 'images/tray', theme.fileName + '.png')
// 托盘
tray = new Tray(nativeImage.createFromPath(iconPath))
@@ -140,7 +140,7 @@ export const createMenu = () => {
export const setTrayImage = (themeId: number) => {
if (!tray) return
let theme = themeList.find(item => item.id === themeId) ?? themeList[0]
const iconPath = join(global.staticPath, 'images/tray', theme.fileName + '.png')
const iconPath = path.join(global.staticPath, 'images/tray', theme.fileName + '.png')
tray.setImage(nativeImage.createFromPath(iconPath))
}
-2
View File
@@ -1,2 +0,0 @@
exports.userApis = []
+2
View File
@@ -0,0 +1,2 @@
export const userApis: LX.UserApi.UserApiInfo[] = []
+8 -7
View File
@@ -1,7 +1,7 @@
import { mainSend } from '@common/mainIpc'
import { BrowserWindow } from 'electron'
import fs from 'fs'
import { join } from 'path'
import path from 'node:path'
import { openDevTools as handleOpenDevTools } from '@main/utils'
import { encodePath } from '@common/utils/electron'
@@ -27,15 +27,16 @@ const winEvent = () => {
export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
await closeWindow()
dir ??= global.isDev ? webpackUserApiPath : join(encodePath(__dirname), 'userApi')
dir ??= process.env.NODE_ENV !== 'production' ? path.join(__USER_API_PATH__, 'renderer') : encodePath(__dirname)
if (!html) {
html = await fs.promises.readFile(join(dir, 'renderer/user-api.html'), 'utf8')
html = await fs.promises.readFile(path.join(dir, 'user-api.html'), 'utf8')
}
const preloadUrl = global.isDev
? `${join(encodePath(__dirname), '../dist/user-api-preload.js')}`
: `${join(encodePath(__dirname), 'user-api-preload.js')}`
// console.log(preloadUrl)
const preloadUrl = process.env.NODE_ENV !== 'production'
? `${path.join(encodePath(__dirname), '../dist/user-api-preload.js')}`
: `${path.join(encodePath(__dirname), '../preload/user-api-preload.js')}`
// console.log(preloadUrl, html)
/**
* Initial window options
+5 -5
View File
@@ -1,8 +1,8 @@
const { contextBridge, ipcRenderer } = require('electron')
const needle = require('needle')
const zlib = require('zlib')
const { createCipheriv, publicEncrypt, constants, randomBytes, createHash } = require('crypto')
const USER_API_RENDERER_EVENT_NAME = require('../rendererEvent/name')
import { contextBridge, ipcRenderer } from 'electron'
import needle from 'needle'
import zlib from 'zlib'
import { createCipheriv, publicEncrypt, constants, randomBytes, createHash } from 'crypto'
import USER_API_RENDERER_EVENT_NAME from '../rendererEvent/name'
for (const key of Object.keys(process.env)) {
if (/^(?:http_proxy|https_proxy|NO_PROXY)$/i.test(key)) delete process.env[key]
@@ -10,4 +10,5 @@ const names = {
for (const key of Object.keys(names)) {
names[key] = `userApi_${key}`
}
module.exports = names
export default names
@@ -104,7 +104,7 @@ export const loadApi = async(apiId: string) => {
// // const path = require('path')
// // // eslint-disable-next-line no-undef
// // userApi.script = require('fs').readFileSync(join(global.isDev ? __userApi : __dirname, 'renderer/test-api.js')).toString()
// // userApi.script = require('fs').readFileSync(join(process.env.NODE_ENV !== 'production' ? __userApi : __dirname, 'renderer/test-api.js')).toString()
// console.log('load api', userApi.name)
// mainSend(global.modules.userApiWindow, USER_API_RENDERER_EVENT_NAME.init, { userApi })
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { join } from 'path'
import path from 'node:path'
import { BrowserWindow } from 'electron'
import { debounce, isLinux, isWin } from '@common/utils'
import { initWindowSize } from './utils'
@@ -139,7 +139,7 @@ export const createWindow = () => {
},
})
const winURL = global.isDev ? 'http://localhost:9081/lyric.html' : `file://${join(encodePath(__dirname), 'lyric.html')}`
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9081' : `file://${path.join(encodePath(__dirname), '../renderer-lyric/index.html')}`
void browserWindow.loadURL(winURL + `?dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent()
+2 -2
View File
@@ -1,5 +1,5 @@
import { BrowserWindow, dialog } from 'electron'
import { join } from 'path'
import path from 'node:path'
import { createTaskBarButtons, getWindowSizeInfo } from './utils'
import { isLinux, isWin } from '@common/utils'
import { openDevTools as handleOpenDevTools } from '@main/utils'
@@ -96,7 +96,7 @@ export const createWindow = () => {
}
browserWindow = new BrowserWindow(options)
const winURL = global.isDev ? 'http://localhost:9080' : `file://${join(encodePath(__dirname), 'index.html')}`
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9080' : `file://${path.join(encodePath(__dirname), '../renderer/index.html')}`
void browserWindow.loadURL(winURL + `?dt=${!!global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent()
@@ -1,5 +1,5 @@
import { createInflate, constants as zlibConstants } from 'node:zlib'
// import path from 'path'
import path from 'node:path'
import { mainHandle } from '@common/mainIpc'
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
@@ -38,9 +38,9 @@ const decode = async(str: string): Promise<string> => {
const handleDecode = async(lrc: string, tlrc: string, rlrc: string) => {
if (!qrc_decode) {
// const nativeBindingPath = path.join(__dirname, '../build/Release/qrc_decode.node')
// const nativeBindingPath = isDev ? path.join(__dirname, '../build/Release/qrc_decode.node')
// const nativeBindingPath = process.env.NODE_ENV !== 'production' ? path.join(__dirname, '../build/Release/qrc_decode.node')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const addon = require('qrc_decode.node')
const addon = require(path.join(__QRC_DECODE_NODE_PATH__, 'qrc_decode.node'))
// console.log(addon)
qrc_decode = addon.qrc_decode
}
+2 -2
View File
@@ -1,5 +1,5 @@
// import fs from 'fs'
import { join } from 'path'
import path from 'node:path'
import { type WindowSize, windowSizeList } from '@common/config'
import { nativeImage } from 'electron'
@@ -8,7 +8,7 @@ export const getWindowSizeInfo = (windowSizeId: number | string): WindowSize =>
}
const getIconPath = (name: string): Electron.NativeImage => {
return nativeImage.createFromPath(join(global.staticPath, 'images/taskbar', name + '.png'))
return nativeImage.createFromPath(path.join(global.staticPath, 'images/taskbar', name + '.png'))
}
export const createTaskBarButtons = ({