从webpack迁移到vite

pull/1583/head
lyswhut 2023-08-07 15:17:52 +08:00
parent 31e16a7ed7
commit 028bf5919d
166 changed files with 3071 additions and 11869 deletions

84
.eslintrc.base.cjs Normal file
View File

@ -0,0 +1,84 @@
const baseRule = {
'no-new': 'off',
camelcase: 'off',
'no-return-assign': 'off',
'space-before-function-paren': ['error', 'never'],
'no-var': 'error',
'no-fallthrough': 'off',
'prefer-promise-reject-errors': 'off',
eqeqeq: 'off',
'no-multiple-empty-lines': [1, { max: 2 }],
'comma-dangle': [2, 'always-multiline'],
'standard/no-callback-literal': 'off',
'prefer-const': 'off',
'no-labels': 'off',
'node/no-callback-literal': 'off',
'multiline-ternary': 'off',
}
const typescriptRule = {
...baseRule,
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/restrict-template-expressions': [1, {
allowBoolean: true,
allowAny: true,
}],
'@typescript-eslint/restrict-plus-operands': [1, {
allowBoolean: true,
allowAny: true,
}],
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/comma-dangle': 'off',
}
const vueRule = {
...baseRule,
'vue/multi-word-component-names': 'off',
'vue/max-attributes-per-line': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/use-v-on-exact': 'off',
}
exports.base = {
extends: ['standard'],
plugins: ['html'],
rules: baseRule,
parser: '@babel/eslint-parser',
}
exports.typescript = {
files: ['*.ts'],
rules: typescriptRule,
parser: '@typescript-eslint/parser',
extends: [
'standard-with-typescript',
],
}
exports.vue = {
files: ['*.vue'],
rules: vueRule,
parser: 'vue-eslint-parser',
extends: [
// 'plugin:vue/vue3-essential',
'plugin:vue/base',
'plugin:vue/vue3-recommended',
'plugin:vue-pug/vue3-recommended',
// "plugin:vue/strongly-recommended"
'standard-with-typescript',
],
parserOptions: {
sourceType: 'module',
parser: {
// Script parser for `<script>`
js: '@typescript-eslint/parser',
// Script parser for `<script lang="ts">`
ts: '@typescript-eslint/parser',
},
extraFileExtensions: ['.vue'],
},
}

View File

@ -1,91 +1,18 @@
const javascript = {
'no-new': 'off',
camelcase: 'off',
'no-return-assign': 'off',
'space-before-function-paren': ['error', 'never'],
'no-var': 'error',
'no-fallthrough': 'off',
'prefer-promise-reject-errors': 'off',
eqeqeq: 'off',
'no-multiple-empty-lines': [1, { max: 2 }],
'comma-dangle': [2, 'always-multiline'],
'standard/no-callback-literal': 'off',
'prefer-const': 'off',
'no-labels': 'off',
'node/no-callback-literal': 'off',
'multiline-ternary': 'off',
}
const typescript = {
...javascript,
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/restrict-template-expressions': [1, {
allowBoolean: true,
}],
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/comma-dangle': 'off',
}
const vue = {
...typescript,
'vue/multi-word-component-names': 'off',
'vue/max-attributes-per-line': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/use-v-on-exact': 'off',
}
delete vue['@typescript-eslint/restrict-template-expressions']
const { base, typescript } = require('./.eslintrc.base.cjs')
module.exports = {
root: true,
extends: [
'standard',
],
plugins: [
'html',
],
parser: '@babel/eslint-parser',
parserOptions: {
// "requireConfigFile": false
},
rules: javascript,
ignorePatterns: ['vendors', '*.min.js', 'dist'],
...base,
overrides: [
{
files: ['*.vue'],
rules: vue,
parser: 'vue-eslint-parser',
extends: [
'plugin:vue/base',
// "plugin:vue/strongly-recommended"
'plugin:vue/vue3-recommended',
'plugin:vue-pug/vue3-recommended',
'standard-with-typescript',
],
...typescript,
parserOptions: {
sourceType: 'module',
parser: {
// Script parser for `<script>`
js: '@typescript-eslint/parser',
// Script parser for `<script lang="ts">`
ts: '@typescript-eslint/parser',
},
extraFileExtensions: ['.vue'],
},
},
{
files: ['*.ts'],
rules: typescript,
parser: '@typescript-eslint/parser',
extends: [
'standard-with-typescript',
],
parserOptions: {
project: './src/**/tsconfig.json',
project: './tsconfig.json',
},
},
],
ignorePatterns: [
'dist',
'build',
],
}

25
.github/workflows/eslint.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: Run eslint check
on:
pull_request:
branches:
- dev
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out git repository
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install Dependencies
run: npm ci
- name: Eslint check
run: npm run lint

View File

@ -17,6 +17,7 @@ module.exports = {
// filter: [
// 'electron-builder',
// 'electron-updater',
// 'electron-log',
// ],
// target: 'patch',

View File

@ -52,6 +52,8 @@
目前本项目的原始发布地址只有**GitHub**及**蓝奏网盘**,其他渠道均为第三方转载发布,与本项目无关!
为了提高使用门槛本软件内的默认设置、UI操作不以新手友好为目标所以使用前建议先根据你的喜好浏览调整一遍软件设置阅读一遍[音乐播放列表机制](https://lyswhut.github.io/lx-music-doc/desktop/faq/playlist)及[可用的鼠标、键盘快捷操作](https://lyswhut.github.io/lx-music-doc/desktop/faq/hotkey)
#### Scheme URL支持
从v1.17.0起支持 Scheme URL可以使用此功能从浏览器等场景下调用LX Music我们开发了一个[油猴脚本](https://github.com/lyswhut/lx-music-script#readme)配套使用,<br>

View File

@ -1,9 +0,0 @@
const isDev = process.env.NODE_ENV === 'development'
module.exports = {
modules: {
localIdentName: isDev ? '[path][name]__[local]--[hash:base64:5]' : '[hash:base64:5]',
exportLocalsConvention: 'camelCase',
},
sourceMap: isDev,
}

View File

@ -1,48 +0,0 @@
const path = require('path')
const ESLintPlugin = require('eslint-webpack-plugin')
const isDev = process.env.NODE_ENV === 'development'
module.exports = {
target: 'electron-main',
output: {
filename: '[name].js',
library: {
type: 'commonjs2',
},
path: path.join(__dirname, '../../dist'),
},
externals: {
'font-list': 'font-list',
'better-sqlite3': 'better-sqlite3',
'electron-font-manager': 'electron-font-manager',
bufferutil: 'bufferutil',
'utf-8-validate': 'utf-8-validate',
'qrc_decode.node': isDev ? path.join(__dirname, '../../build/Release/qrc_decode.node') : path.join('../build/Release/qrc_decode.node'),
},
resolve: {
alias: {
'@main': path.join(__dirname, '../../src/main'),
'@renderer': path.join(__dirname, '../../src/renderer'),
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
'@common': path.join(__dirname, '../../src/common'),
},
extensions: ['.tsx', '.ts', '.js', '.mjs', '.json', '.node'],
},
module: {
rules: [
{
test: /\.node$/,
use: 'node-loader',
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new ESLintPlugin(),
],
}

View File

@ -1,28 +0,0 @@
const path = require('path')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const baseConfig = require('./webpack.config.base')
module.exports = merge(baseConfig, {
mode: 'development',
entry: {
main: path.join(__dirname, '../../src/main/index-dev.ts'),
// 'dbService.worker': path.join(__dirname, '../../src/main/worker/dbService/index.ts'),
},
devtool: 'eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
},
webpackStaticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
webpackUserApiPath: `"${path.join(__dirname, '../../src/main/modules/userApi').replace(/\\/g, '\\\\')}"`,
}),
],
performance: {
maxEntrypointSize: 1024 * 1024 * 50,
maxAssetSize: 1024 * 1024 * 30,
},
})

View File

@ -1,49 +0,0 @@
const path = require('path')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const baseConfig = require('./webpack.config.base')
// const { dependencies } = require('../../package.json')
const buildConfig = require('../webpack-build-config')
module.exports = merge(baseConfig, {
mode: 'production',
entry: {
main: path.join(__dirname, '../../src/main/index.ts'),
// 'dbService.worker': path.join(__dirname, '../../src/main/worker/dbService/index.ts'),
},
node: {
__dirname: false,
__filename: false,
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, '../../src/main/modules/userApi/renderer/user-api.html'),
to: path.join(__dirname, '../../dist/userApi/renderer/user-api.html'),
},
{
from: path.join(__dirname, '../../src/common/theme/images/*').replace(/\\/g, '/'),
to: path.join(__dirname, '../../dist/theme_images/[name][ext]'),
},
],
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
],
performance: {
maxEntrypointSize: 1024 * 1024 * 10,
maxAssetSize: 1024 * 1024 * 20,
},
optimization: {
minimize: buildConfig.minimize,
},
})

View File

@ -1,146 +1,3 @@
process.env.NODE_ENV = 'production'
const chalk = require('chalk')
const del = require('del')
const webpack = require('webpack')
const Spinnies = require('spinnies')
const mainConfig = './main/webpack.config.prod'
const rendererConfig = './renderer/webpack.config.prod'
const rendererLyricConfig = './renderer-lyric/webpack.config.prod'
const rendererScriptConfig = './renderer-scripts/webpack.config.prod'
const errorLog = chalk.bgRed.white(' ERROR ') + ' '
const okayLog = chalk.bgGreen.white(' OKAY ') + ' '
const { Worker, isMainThread, parentPort } = require('worker_threads')
function build() {
console.time('build')
del.sync(['dist/**', 'build/**'])
const spinners = new Spinnies({ color: 'blue' })
spinners.add('main', { text: 'main building' })
spinners.add('renderer', { text: 'renderer building' })
spinners.add('renderer-lyric', { text: 'renderer-lyric building' })
spinners.add('renderer-scripts', { text: 'renderer-scripts building' })
let results = ''
// m.on('success', () => {
// process.stdout.write('\x1B[2J\x1B[0f')
// console.log(`\n\n${results}`)
// console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
// process.exit()
// })
function handleSuccess() {
process.stdout.write('\x1B[2J\x1B[0f')
console.log(`\n\n${results}`)
console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
console.timeEnd('build')
process.exit()
}
Promise.all([
pack(mainConfig).then(result => {
results += result + '\n\n'
spinners.succeed('main', { text: 'main build success!' })
}).catch(err => {
spinners.fail('main', { text: 'main build fail :(' })
console.log(`\n ${errorLog}failed to build main process`)
console.error(`\n${err}\n`)
process.exit(1)
}),
pack(rendererConfig).then(result => {
results += result + '\n\n'
spinners.succeed('renderer', { text: 'renderer build success!' })
}).catch(err => {
spinners.fail('renderer', { text: 'renderer build fail :(' })
console.log(`\n ${errorLog}failed to build renderer process`)
console.error(`\n${err}\n`)
process.exit(1)
}),
pack(rendererLyricConfig).then(result => {
results += result + '\n\n'
spinners.succeed('renderer-lyric', { text: 'renderer-lyric build success!' })
}).catch(err => {
spinners.fail('renderer-lyric', { text: 'renderer-lyric build fail :(' })
console.log(`\n ${errorLog}failed to build renderer-lyric process`)
console.error(`\n${err}\n`)
process.exit(1)
}),
pack(rendererScriptConfig).then(result => {
results += result + '\n\n'
spinners.succeed('renderer-scripts', { text: 'renderer-scripts build success!' })
}).catch(err => {
spinners.fail('renderer-scripts', { text: 'renderer-scripts build fail :(' })
console.log(`\n ${errorLog}failed to build renderer-scripts process`)
console.error(`\n${err}\n`)
process.exit(1)
}),
]).then(handleSuccess)
}
function pack(config) {
return new Promise((resolve, reject) => {
const worker = new Worker(__filename)
const subChannel = new MessageChannel()
worker.postMessage({ port: subChannel.port1, config }, [subChannel.port1])
subChannel.port2.on('message', ({ status, message }) => {
switch (status) {
case 'success': return resolve(message)
case 'error': return reject(message)
}
})
})
}
function runPack(config) {
return new Promise((resolve, reject) => {
config = require(config)
config.mode = 'production'
webpack(config, (err, stats) => {
if (err) reject(err.stack || err)
else if (stats.hasErrors()) {
let err = ''
stats.toString({
chunks: false,
modules: false,
colors: true,
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
})
reject(err)
} else {
resolve(stats.toString({
chunks: false,
colors: true,
}))
}
})
})
}
if (isMainThread) build()
else {
parentPort.once('message', ({ port, config }) => {
// assert(port instanceof MessagePort)
runPack(config).then((result) => {
port.postMessage({
status: 'success',
message: result,
})
}).catch((err) => {
port.postMessage({
status: 'error',
message: err,
})
}).finally(() => {
port.close()
})
})
}
require('./vite/pack')

View File

@ -1,152 +0,0 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const HTMLPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const vueLoaderConfig = require('../vue-loader.config')
const { mergeCSSLoader } = require('../utils')
const isDev = process.env.NODE_ENV === 'development'
module.exports = {
target: 'electron-renderer',
entry: {
'renderer-lyric': path.join(__dirname, '../../src/renderer-lyric/main.ts'),
},
output: {
filename: '[name].js',
library: {
type: 'commonjs2',
},
path: path.join(__dirname, '../../dist'),
publicPath: '',
},
resolve: {
alias: {
'@': path.join(__dirname, '../../src'),
'@main': path.join(__dirname, '../../src/main'),
'@renderer': path.join(__dirname, '../../src/renderer'),
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
'@static': path.join(__dirname, '../../src/static'),
'@common': path.join(__dirname, '../../src/common'),
},
extensions: ['.tsx', '.ts', '.js', '.json', '.vue', '.node'],
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
},
},
{
test: /\.node$/,
use: 'node-loader',
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig,
},
{
test: /\.pug$/,
loader: 'pug-plain-loader',
},
{
test: /\.css$/,
oneOf: mergeCSSLoader(),
},
{
test: /\.less$/,
oneOf: mergeCSSLoader({
loader: 'less-loader',
options: {
sourceMap: true,
},
}),
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
exclude: path.join(__dirname, '../../src/renderer/assets/svgs'),
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'imgs/[name]-[contenthash:8][ext]',
},
},
{
test: /\.svg$/,
include: path.join(__dirname, '../../src/renderer/assets/svgs'),
use: [
{
loader: 'svg-sprite-loader',
options: {
symbolId: 'icon-[name]',
},
},
'svg-transform-loader',
'svgo-loader',
],
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'media/[name]-[contenthash:8][ext]',
},
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'fonts/[name]-[contenthash:8][ext]',
},
},
],
},
plugins: [
new HTMLPlugin({
filename: 'lyric.html',
template: path.join(__dirname, '../../src/renderer-lyric/index.html'),
isProd: process.env.NODE_ENV == 'production',
browser: process.browser,
__dirname,
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: isDev ? '[name].css' : '[name].[contenthash:8].css',
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:8].css',
}),
new ESLintPlugin({
extensions: ['js', 'vue'],
formatter: require('eslint-formatter-friendly'),
}),
],
}

View File

@ -1,26 +0,0 @@
const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
module.exports = merge(baseConfig, {
mode: 'development',
devtool: 'eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
},
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
}),
],
performance: {
hints: false,
},
})

View File

@ -1,49 +0,0 @@
// const path = require('path')
const webpack = require('webpack')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
const buildConfig = require('../webpack-build-config')
// const { dependencies } = require('../../package.json')
// let whiteListedModules = ['vue']
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
module.exports = merge(baseConfig, {
mode: 'production',
devtool: false,
externals: [
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
],
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
}),
],
optimization: {
minimize: buildConfig.minimize,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
],
},
performance: {
maxEntrypointSize: 1024 * 1024 * 10,
maxAssetSize: 1024 * 1024 * 20,
hints: 'warning',
},
node: {
__dirname: false,
__filename: false,
},
})

View File

@ -1,57 +0,0 @@
const path = require('path')
const ESLintPlugin = require('eslint-webpack-plugin')
module.exports = {
target: 'electron-renderer',
entry: {
'user-api-preload': path.join(__dirname, '../../src/main/modules/userApi/renderer/preload.js'),
},
output: {
filename: '[name].js',
library: {
type: 'commonjs2',
},
path: path.join(__dirname, '../../dist'),
publicPath: '',
},
resolve: {
alias: {
'@': path.join(__dirname, '../../src'),
'@main': path.join(__dirname, '../../src/main'),
'@renderer': path.join(__dirname, '../../src/renderer'),
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
'@static': path.join(__dirname, '../../src/static'),
'@common': path.join(__dirname, '../../src/common'),
},
extensions: ['.tsx', '.ts', '.js', '.json', '.vue', '.node'],
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
},
},
{
test: /\.node$/,
use: 'node-loader',
},
],
},
plugins: [
new ESLintPlugin({
extensions: ['js'],
formatter: require('eslint-formatter-friendly'),
}),
],
}

View File

@ -1,24 +0,0 @@
const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
module.exports = merge(baseConfig, {
mode: 'development',
devtool: 'eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
},
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
}),
],
performance: {
hints: false,
},
})

View File

@ -1,45 +0,0 @@
// const path = require('path')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
const buildConfig = require('../webpack-build-config')
// const { dependencies } = require('../../package.json')
// let whiteListedModules = ['vue']
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
module.exports = merge(baseConfig, {
mode: 'production',
devtool: false,
externals: [
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
],
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
],
optimization: {
minimize: buildConfig.minimize,
minimizer: [
new TerserPlugin(),
],
},
performance: {
maxEntrypointSize: 1024 * 1024 * 10,
maxAssetSize: 1024 * 1024 * 20,
hints: 'warning',
},
node: {
__dirname: false,
__filename: false,
},
})

View File

@ -1,158 +0,0 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const HTMLPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const vueLoaderConfig = require('../vue-loader.config')
const { mergeCSSLoader } = require('../utils')
const isDev = process.env.NODE_ENV === 'development'
module.exports = {
target: 'electron-renderer',
entry: {
renderer: path.join(__dirname, '../../src/renderer/main.ts'),
},
output: {
filename: '[name].js',
library: {
type: 'commonjs2',
},
path: path.join(__dirname, '../../dist'),
publicPath: '',
},
resolve: {
alias: {
'@': path.join(__dirname, '../../src'),
'@main': path.join(__dirname, '../../src/main'),
'@renderer': path.join(__dirname, '../../src/renderer'),
'@lyric': path.join(__dirname, '../../src/renderer-lyric'),
'@static': path.join(__dirname, '../../src/static'),
'@common': path.join(__dirname, '../../src/common'),
},
extensions: ['.tsx', '.ts', '.js', '.json', '.vue', '.node'],
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
},
parser: {
worker: [
'*audioContext.audioWorklet.addModule()',
'...',
],
},
},
{
test: /\.node$/,
use: 'node-loader',
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig,
},
{
test: /\.pug$/,
loader: 'pug-plain-loader',
},
{
test: /\.css$/,
oneOf: mergeCSSLoader(),
},
{
test: /\.less$/,
oneOf: mergeCSSLoader({
loader: 'less-loader',
options: {
sourceMap: true,
},
}),
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
exclude: path.join(__dirname, '../../src/renderer/assets/svgs'),
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'imgs/[name]-[contenthash:8][ext]',
},
},
{
test: /\.svg$/,
include: path.join(__dirname, '../../src/renderer/assets/svgs'),
use: [
{
loader: 'svg-sprite-loader',
options: {
symbolId: 'icon-[name]',
},
},
'svg-transform-loader',
'svgo-loader',
],
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'media/[name]-[contenthash:8][ext]',
},
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: 'fonts/[name]-[contenthash:8][ext]',
},
},
],
},
plugins: [
new HTMLPlugin({
filename: 'index.html',
template: path.join(__dirname, '../../src/renderer/index.html'),
isProd: process.env.NODE_ENV == 'production',
browser: process.browser,
__dirname,
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: isDev ? '[name].css' : '[name].[contenthash:8].css',
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:8].css',
}),
new ESLintPlugin({
extensions: ['js', 'vue'],
formatter: require('eslint-formatter-friendly'),
}),
],
}

View File

@ -1,27 +0,0 @@
const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
module.exports = merge(baseConfig, {
mode: 'development',
devtool: 'eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
},
// ENVIRONMENT: 'process.env',
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
staticPath: `"${path.join(__dirname, '../../src/static').replace(/\\/g, '\\\\')}"`,
}),
],
performance: {
hints: false,
},
})

View File

@ -1,62 +0,0 @@
const path = require('path')
const webpack = require('webpack')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
const buildConfig = require('../webpack-build-config')
// const { dependencies } = require('../../package.json')
// let whiteListedModules = ['vue', 'vue-router', 'vuex', 'vue-i18n']
module.exports = merge(baseConfig, {
mode: 'production',
devtool: false,
externals: [
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)),
],
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, '../../src/static'),
to: path.join(__dirname, '../../dist/static'),
},
],
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
// ENVIRONMENT: 'process.env',
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
}),
],
optimization: {
minimize: buildConfig.minimize,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: 'initial',
minChunks: 2,
},
},
performance: {
maxEntrypointSize: 1024 * 1024 * 10,
maxAssetSize: 1024 * 1024 * 20,
hints: 'warning',
},
node: {
__dirname: false,
__filename: false,
},
})

View File

@ -1,250 +1,3 @@
process.env.NODE_ENV = 'development'
const chalk = require('chalk')
const electron = require('electron')
const path = require('path')
// const { say } = require('cfonts')
const { spawn } = require('child_process')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackHotMiddleware = require('webpack-hot-middleware')
const mainConfig = require('./main/webpack.config.dev')
const rendererConfig = require('./renderer/webpack.config.dev')
const rendererLyricConfig = require('./renderer-lyric/webpack.config.dev')
const rendererScriptConfig = require('./renderer-scripts/webpack.config.dev')
const { Arch } = require('electron-builder')
const replaceLib = require('./build-before-pack')
let electronProcess = null
let manualRestart = false
let hotMiddlewareRenderer
let hotMiddlewareRendererLyric
function startRenderer() {
return new Promise((resolve, reject) => {
// rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
// rendererConfig.mode = 'development'
const compiler = webpack(rendererConfig)
hotMiddlewareRenderer = webpackHotMiddleware(compiler, {
log: false,
heartbeat: 2500,
})
compiler.hooks.compilation.tap('compilation', compilation => {
// console.log(Object.keys(compilation.hooks))
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddlewareRenderer.publish({ action: 'reload' })
cb()
})
})
// compiler.hooks.done.tap('done', stats => {
// // logStats('Renderer', 'Compile done')
// // logStats('Renderer', stats)
// })
const server = new WebpackDevServer({
port: 9080,
hot: true,
historyApiFallback: true,
static: {
directory: path.join(__dirname, '../src/common/theme/images'),
publicPath: '/theme_images',
},
client: {
logging: 'warn',
overlay: true,
},
setupMiddlewares(middlewares, devServer) {
devServer.app.use(hotMiddlewareRenderer)
devServer.middleware.waitUntilValid(resolve)
return middlewares
},
}, compiler)
server.start()
})
}
function startRendererLyric() {
return new Promise((resolve, reject) => {
// rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
// rendererConfig.mode = 'development'
const compiler = webpack(rendererLyricConfig)
hotMiddlewareRendererLyric = webpackHotMiddleware(compiler, {
log: false,
heartbeat: 2500,
})
compiler.hooks.compilation.tap('compilation', compilation => {
// console.log(Object.keys(compilation.hooks))
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
hotMiddlewareRendererLyric.publish({ action: 'reload' })
cb()
})
})
// compiler.hooks.done.tap('done', stats => {
// // logStats('Renderer', 'Compile done')
// // logStats('Renderer', stats)
// })
const server = new WebpackDevServer({
port: 9081,
hot: true,
historyApiFallback: true,
// static: {
// directory: path.join(__dirname, '../'),
// },
client: {
logging: 'warn',
overlay: true,
},
setupMiddlewares(middlewares, devServer) {
devServer.app.use(hotMiddlewareRenderer)
devServer.middleware.waitUntilValid(resolve)
return middlewares
},
}, compiler)
server.start()
})
}
function startRendererScripts() {
return new Promise((resolve, reject) => {
// mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
// mainConfig.mode = 'development'
const compiler = webpack(rendererScriptConfig)
compiler.watch({}, (err, stats) => {
if (err) {
console.log(err)
return
}
resolve()
})
})
}
function startMain() {
return new Promise((resolve, reject) => {
// mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
// mainConfig.mode = 'development'
const compiler = webpack(mainConfig)
compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
hotMiddlewareRenderer.publish({ action: 'compiling' })
hotMiddlewareRendererLyric.publish({ action: 'compiling' })
done()
})
compiler.watch({}, (err, stats) => {
if (err) {
console.log(err)
return
}
// logStats('Main', stats)
if (electronProcess && electronProcess.kill) {
manualRestart = true
process.kill(electronProcess.pid)
electronProcess = null
startElectron()
setTimeout(() => {
manualRestart = false
}, 5000)
}
resolve()
})
})
}
function startElectron() {
let args = [
'--inspect=5858',
// 'NODE_ENV=development',
path.join(__dirname, '../dist/main.js'),
]
// detect yarn or npm and process commandline args accordingly
if (process.env.npm_execpath.endsWith('yarn.js')) {
args = args.concat(process.argv.slice(3))
} else if (process.env.npm_execpath.endsWith('npm-cli.js')) {
args = args.concat(process.argv.slice(2))
}
electronProcess = spawn(electron, args)
electronProcess.stdout.on('data', data => {
electronLog(data, 'blue')
})
electronProcess.stderr.on('data', data => {
electronLog(data, 'red')
})
electronProcess.on('close', () => {
if (!manualRestart) process.exit()
})
}
const logs = [
'Manifest version 2 is deprecated, and support will be removed in 2023',
'"Extension server error: Operation failed: Permission denied", source: devtools://devtools/bundled',
// https://github.com/electron/electron/issues/32133
'"Electron sandbox_bundle.js script failed to run"',
'"TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))",',
]
function electronLog(data, color) {
let log = data.toString()
if (/[0-9A-z]+/.test(log)) {
// 抑制某些无关的报错日志
if (color == 'red' && typeof log === 'string' && logs.some(l => log.includes(l))) return
console.log(chalk[color](log))
}
}
function init() {
const Spinnies = require('spinnies')
const spinners = new Spinnies({ color: 'blue' })
spinners.add('main', { text: 'main compiling' })
spinners.add('renderer', { text: 'renderer compiling' })
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
function handleSuccess(name) {
spinners.succeed(name, { text: name + ' compile success!' })
}
function handleFail(name) {
spinners.fail(name, { text: name + ' compile fail!' })
}
replaceLib({ electronPlatformName: process.platform, arch: Arch[process.arch] })
Promise.all([
startRenderer().then(() => handleSuccess('renderer')).catch((err) => {
console.error(err.message)
return handleFail('renderer')
}),
startRendererLyric().then(() => handleSuccess('renderer-lyric')).catch((err) => {
console.error(err.message)
return handleFail('renderer-lyric')
}),
startRendererScripts().then(() => handleSuccess('renderer-scripts')).catch((err) => {
console.error(err.message)
return handleFail('renderer-scripts')
}),
startMain().then(() => handleSuccess('main')).catch(() => handleFail('main')),
]).then(startElectron).catch(err => {
console.error(err)
})
}
init()
require('./vite/runner-dev')

View File

@ -1,65 +0,0 @@
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const cssLoaderConfig = require('./css-loader.config')
const chalk = require('chalk')
// merge css-loader
exports.mergeCSSLoader = beforeLoader => {
const loader = [
// 这里匹配 `<style module>`
{
resourceQuery: /module/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
},
},
{
loader: 'css-loader',
options: cssLoaderConfig,
},
'postcss-loader',
],
},
// 这里匹配普通的 `<style>` 或 `<style scoped>`
{
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false,
},
},
'css-loader',
'postcss-loader',
],
},
]
if (beforeLoader) {
loader[0].use.push(beforeLoader)
loader[1].use.push(beforeLoader)
}
return loader
}
exports.logStats = (proc, data) => {
let log = ''
log += chalk.yellow.bold(`${proc} Process`)
log += '\n'
if (typeof data === 'object') {
data.toString({
colors: true,
chunks: false,
}).split(/\r?\n/).forEach(line => {
log += ' ' + line + '\n'
})
} else {
log += ` ${data}\n`
}
console.log(log)
}

View File

@ -0,0 +1,77 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/main'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@main': path.join(rootPath, 'src/main'),
},
browserField: false,
},
build: {
lib: {
entry: `${isProd ? 'index.ts' : 'index-dev.ts'}`,
formats: ['cjs'],
fileName: 'main',
},
outDir: path.join(rootPath, 'dist/main'),
emptyOutDir: true,
reportCompressedSize: false,
modulePreload: false,
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
commonjsOptions: {
dynamicRequireTargets: ['*.js'],
ignoreDynamicRequires: true,
},
rollupOptions: {
external: [
'electron',
'better-sqlite3',
'font-list',
'electron-font-manager',
...builtinModules.flatMap(m => [m, `node:${m}`]),
],
input: {
main: `src/main/${isProd ? 'index.ts' : 'index-dev.ts'}`,
'dbService.worker': 'src/main/worker/dbService/index.ts',
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
format: 'cjs',
// manualChunks(id, info) {
// // return 'main'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
__USER_API_PATH__: `"${path.join(rootPath, 'src/main/modules/userApi').replace(/\\/g, '\\\\')}"`,
__QRC_DECODE_NODE_PATH__: `"${(isProd ? '../../build/Release' : path.join(rootPath, 'build/Release')).replace(/\\/g, '\\\\')}"`,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/main'),
}
export default config

View File

@ -0,0 +1,74 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
import vue from '@vitejs/plugin-vue'
import renderer from 'vite-plugin-electron-renderer'
import postcssConfig from './postcss.config'
// const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/renderer-lyric'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@lyric': path.join(rootPath, 'src/renderer-lyric'),
},
browserField: true,
},
plugins: [vue(), renderer()],
build: {
target: 'esnext',
outDir: path.join(rootPath, 'dist/renderer-lyric'),
modulePreload: false,
emptyOutDir: true,
reportCompressedSize: false,
assetsDir: './',
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external,
input: {
'renderer-lyric': 'src/renderer-lyric/index.html',
},
output: {
entryFileNames: '[name].js',
format: 'cjs',
// manualChunks(id, info) {
// return 'renderer'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
css: {
postcss: postcssConfig,
},
optimizeDeps: {
include: [],
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
server: {
port: 9081,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer-lyric'),
}
export default config

View File

@ -0,0 +1,61 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
// const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const config: UserConfig = {
mode: process.env.NODE_ENV,
root: path.join(rootPath, 'src/main'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
},
browserField: true,
},
build: {
lib: {
entry: 'modules/userApi/renderer/preload.js',
formats: ['cjs'],
fileName: 'user-api-preload',
},
outDir: path.join(rootPath, 'dist/preload'),
modulePreload: {
polyfill: false,
},
emptyOutDir: true,
reportCompressedSize: false,
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external: ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])],
input: {
'user-api-preload': 'src/main/modules/userApi/renderer/preload.js',
},
output: {
entryFileNames: '[name].js',
// manualChunks(id, info) {
// // return 'main'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/scripts'),
}
export default config

View File

@ -0,0 +1,105 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
import vue from '@vitejs/plugin-vue'
import renderer from 'vite-plugin-electron-renderer'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import postcssConfig from './postcss.config'
const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/renderer'),
base: './',
publicDir: isProd ? false : path.join(rootPath, 'src/common/theme'),
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@renderer': path.join(rootPath, 'src/renderer'),
},
browserField: true,
},
plugins: [
vue(),
renderer(),
createSvgIconsPlugin({
iconDirs: [path.join(rootPath, 'src/renderer/assets/svgs')],
}),
],
build: {
target: 'esnext',
outDir: path.join(rootPath, 'dist/renderer'),
modulePreload: false,
emptyOutDir: true,
reportCompressedSize: false,
// assetsDir: 'chunks',
assetsDir: './',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external,
input: {
renderer: 'src/renderer/index.html',
},
output: {
entryFileNames: '[name].js',
format: 'cjs',
experimentalMinChunkSize: 50_000,
// manualChunks: {
// 'iconv-lite': ['iconv-lite'],
// },
},
logLevel: 'warn',
},
commonjsOptions: {
include: [
/vendors/,
/node_modules/,
/utils\/musicMeta/,
],
},
},
css: {
postcss: postcssConfig,
},
optimizeDeps: {
// // exclude: [],
include: [
'@common/utils/musicMeta',
'@renderer/utils/musicSdk/kg/vendors/infSign.min',
],
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
server: {
port: 9080,
},
worker: {
plugins: [renderer()],
rollupOptions: {
output: {
// entryFileNames: '[name].js',
inlineDynamicImports: true,
format: 'iife',
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
// format: 'es',
},
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer'),
}
export default config

View File

@ -0,0 +1,27 @@
import fs from 'node:fs'
import path from 'node:path'
const rootPath = path.join(__dirname, '../../')
const assets = [
[
path.join(rootPath, './src/main/modules/userApi/renderer/user-api.html'),
path.join(rootPath, './dist/main/user-api.html'),
],
[
path.join(rootPath, './src/static'),
path.join(rootPath, './dist/static'),
],
[
path.join(rootPath, './src/common/theme/theme_images'),
path.join(rootPath, './dist/renderer/theme_images'),
],
] as const
export default async() => {
for (const [from, to] of assets) {
await fs.promises.cp(from, to, {
recursive: true,
})
}
}

62
build-config/vite/pack.ts Normal file
View File

@ -0,0 +1,62 @@
import del from 'del'
import Spinnies from 'spinnies'
import { createLogger } from 'vite'
import colors from 'picocolors'
import { runBuildWorker, type TaksName } from './utils'
// import rendererConfig from './configs/renderer'
import copyAssets from './copyAssets'
const logger = createLogger('info')
const runMainThread = async() => {
console.time('Build time')
del.sync(['dist/**', 'build/**', 'node_modules/.vite/**'])
const noop = () => {}
const spinners = new Spinnies({ color: 'blue' })
spinners.add('renderer', { text: 'renderer compiling' })
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
spinners.add('main', { text: 'main compiling' })
const handleResult = (name: TaksName) => {
return (success: boolean) => {
if (success) {
spinners.succeed(name, { text: name + ' compile success!' })
} else {
spinners.fail(name, { text: name + ' compile fail!' })
}
return success
}
}
const buildTasks = [
runBuildWorker('renderer', noop).then(handleResult('renderer')),
runBuildWorker('renderer-lyric', noop).then(handleResult('renderer-lyric')),
runBuildWorker('renderer-scripts', noop).then(handleResult('renderer-scripts')),
runBuildWorker('main', noop).then(handleResult('main')),
// build(rendererConfig, noop).then(handleResult('renderer')),
]
if (!await Promise.all(buildTasks).then((result) => result.every(s => s))) {
console.timeEnd('Build time')
throw new Error('Build failed')
}
await copyAssets()
// listr.run().then(() => {
logger.info(colors.green('\nAll task build successfully'))
// })
console.timeEnd('Build time')
}
void runMainThread().then(() => {
process.exit(0)
}).catch(err => {
console.log(err)
throw err
})

View File

@ -0,0 +1,119 @@
import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process'
import path from 'node:path'
import colors from 'picocolors'
import del from 'del'
import electron from 'electron'
import { createLogger } from 'vite'
import { type TaksName, build, runBuildWorker } from './utils'
import Spinnies from 'spinnies'
import replaceLib from '../build-before-pack'
import { Arch } from 'electron-builder'
import mainConfig from './configs/main'
const logger = createLogger('info')
del.sync(['dist/**', 'node_modules/.vite/**'])
const logs = [
'Manifest version 2 is deprecated, and support will be removed in 2023',
'"Extension server error: Operation failed: Permission denied", source: devtools://devtools/bundled',
// https://github.com/electron/electron/issues/32133
'"Electron sandbox_bundle.js script failed to run"',
'"TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))",',
]
function electronLog(data: Buffer, color: 'red' | 'blue') {
let log = data.toString()
if (/[0-9A-z]+/.test(log)) {
// 抑制某些无关的报错日志
if (color == 'red' && typeof log === 'string' && logs.some(l => log.includes(l))) return
logger.info(colors[color](log))
}
}
export const runElectron = () => {
let args = [
'--inspect=5858',
// 'NODE_ENV=development',
path.join(__dirname, '../../dist/main/main.js'),
]
// detect yarn or npm and process commandline args accordingly
if (process.env.npm_execpath?.endsWith('yarn.js')) {
args = args.concat(process.argv.slice(3))
} else if (process.env.npm_execpath?.endsWith('npm-cli.js')) {
args = args.concat(process.argv.slice(2))
}
const electronProcess = spawn(electron as unknown as string, args)
electronProcess.stdout.on('data', data => {
electronLog(data, 'blue')
})
electronProcess.stderr.on('data', data => {
electronLog(data, 'red')
})
electronProcess.on('close', () => {
process.exit()
})
return electronProcess
}
const runMainThread = async() => {
console.time('init')
// let server: ViteDevServer | undefined
let electronProcess: ChildProcessWithoutNullStreams | undefined
const noop = () => {}
const handleUpdate = () => {
logger.info(colors.green('\nrebuild the electron main process successfully'))
if (electronProcess) {
electronProcess.removeAllListeners()
electronProcess.kill()
}
electronProcess = runElectron()
logger.info(colors.green('\nrestart electron app...'))
}
const spinners = new Spinnies({ color: 'blue' })
spinners.add('renderer', { text: 'renderer compiling' })
spinners.add('renderer-lyric', { text: 'renderer-lyric compiling' })
spinners.add('renderer-scripts', { text: 'renderer-scripts compiling' })
spinners.add('main', { text: 'main compiling' })
const handleResult = (name: TaksName) => {
return (success: boolean) => {
if (success) {
spinners.succeed(name, { text: name + ' compile success!' })
} else {
spinners.fail(name, { text: name + ' compile fail!' })
}
return success
}
}
const buildTasks = [
runBuildWorker('renderer', noop).then(handleResult('renderer')),
runBuildWorker('renderer-lyric', noop).then(handleResult('renderer-lyric')),
runBuildWorker('renderer-scripts', handleUpdate).then(handleResult('renderer-scripts')),
replaceLib({ electronPlatformName: process.platform, arch: Arch[process.arch as any] }).then(async() => {
return build(mainConfig, handleUpdate).then(handleResult('main'))
}),
]
if (!await Promise.all(buildTasks).then((result) => result.every(s => s))) return
// listr.run().then(() => {
electronProcess = runElectron()
logger.info(colors.green('\nAll task build successfully'))
// })
console.timeEnd('init')
}
void runMainThread()

140
build-config/vite/utils.ts Normal file
View File

@ -0,0 +1,140 @@
import path from 'node:path'
import { Worker, MessageChannel } from 'worker_threads'
import {
type UserConfig,
mergeConfig,
build as viteBuild,
createServer,
} from 'vite'
export type BuildSuatus = 'success' | 'error' | 'updated'
export type TaksName = 'main' | 'renderer' | 'renderer-lyric' | 'renderer-scripts'
/**
* build code
* @param config vite config
* @param onUpdated new build event
* @returns is success
*/
export const build = async(config: UserConfig, onUpdated: () => void): Promise<boolean> => {
if (config.mode == 'production') {
if (config.build) config.build.watch = null
return viteBuild(config).then((output) => {
// output
// console.log(output)
return true
})
}
return config.server
? createBuildServer(config, onUpdated)
: buildDev(config, onUpdated)
}
/**
* build code in dev
* @param config vite config
* @param onUpdated new build event
* @returns is success
*/
const buildDev = async(config: UserConfig, onUpdated: () => void) => {
return new Promise<boolean>(resolve => {
let firstBundle = true
let isError = false
config = mergeConfig(config, {
plugins: [
{
name: 'vite:file-watcher',
buildEnd(err?: Error) {
// console.log('buildEnd', err !== undefined, err)
isError = err !== undefined
},
closeBundle() {
// console.log('closeBundle')
if (firstBundle) {
firstBundle = false
resolve(!isError)
} else {
if (isError) return
onUpdated()
}
},
},
],
})
void viteBuild(config)
})
}
export const createBuildServer = async(config: UserConfig, onUpdated: () => void) => {
return new Promise<boolean>(resolve => {
let firstBundle = true
let isError = false
void createServer({
...mergeConfig(config, {
plugins: [
{
name: 'vite:file-watcher',
buildEnd(err?: Error) {
// console.log('buildEnd', err !== undefined, err)
isError = err !== undefined
},
closeBundle() {
// console.log('closeBundle')
if (firstBundle) {
firstBundle = false
// resolve(!isError)
} else {
if (isError) return
onUpdated()
}
},
},
],
}),
configFile: false,
}).then(async server => {
return server.listen().then(() => {
resolve(true)
})
}).catch((error) => {
console.log(error)
resolve(false)
})
// return build(config, () => {
// // server.ws.send({ type: 'full-reload' })
// onUpdated()
// })
})
}
/**
* build code in worker
* @param config vite config
* @param onUpdated new build event
* @returns is success
*/
export const runBuildWorker = async(taskName: TaksName, onUpdated: () => void) => new Promise<boolean>((resolve) => {
const worker = new Worker(path.resolve(__dirname, './worker.ts'), {
execArgv: ['--require', 'ts-node/register'],
})
const subChannel = new MessageChannel()
worker.postMessage({ port: subChannel.port1, taskName }, [subChannel.port1])
subChannel.port2.on('message', ({ status }: { status: BuildSuatus }) => {
// console.log(status)
switch (status) {
case 'updated':
onUpdated()
break
case 'success':
resolve(true)
break
case 'error':
resolve(false)
break
}
})
})

View File

@ -0,0 +1,33 @@
import { parentPort, type MessagePort } from 'node:worker_threads'
import { type TaksName, build } from './utils'
import mainConfig from './configs/main'
import rendererConfig from './configs/renderer'
import rendererLyricConfig from './configs/renderer-lyric'
import rendererScriptConfig from './configs/renderer-scripts'
const configs = {
main: mainConfig,
renderer: rendererConfig,
'renderer-lyric': rendererLyricConfig,
'renderer-scripts': rendererScriptConfig,
}
if (!parentPort) throw new Error('Require run in worker')
parentPort.once('message', ({ port, taskName }: {
port: MessagePort
taskName: TaksName
}) => {
// assert(port instanceof MessagePort)
const sendStatus = () => {
port.postMessage({
status: 'updated',
})
}
void build(configs[taskName], sendStatus).then((status) => {
port.postMessage({
status: status ? 'success' : 'error',
})
})
})

View File

@ -1,12 +0,0 @@
const isDev = process.env.NODE_ENV === 'development'
module.exports = {
// preserveWhitepace: true,
compilerOptions: {
whitespace: 'preserve',
},
extractCSS: !isDev,
// cssModules: {
// localIndetName: '',
// },
}

View File

@ -1,3 +0,0 @@
module.exports = {
minimize: false,
}

11733
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,11 @@
"name": "lx-music-desktop",
"version": "2.4.0-beta.3",
"description": "一个免费的音乐查找助手",
"main": "./dist/main.js",
"main": "./dist/main/main.js",
"productName": "lx-music-desktop",
"scripts": {
"pack": "node build-config/pack.js && npm run pack:win:setup:x64",
"pack:win": "node build-config/pack.js && npm run pack:win:setup:x64 && npm run pack:win:setup:x86 && npm run pack:win:setup:arm64 && npm run pack:win:setup:x86_64 && npm run pack:win:7z",
"pack": "ts-node build-config/pack.js && npm run pack:win:setup:x64",
"pack:win": "ts-node build-config/pack.js && npm run pack:win:setup:x64 && npm run pack:win:setup:x86 && npm run pack:win:setup:arm64 && npm run pack:win:setup:x86_64 && npm run pack:win:7z",
"pack:win:setup:x86_64": "cross-env TARGET=Setup ARCH=x86_64 electron-builder -w=nsis --x64 --ia32 -p never",
"pack:win:setup:x64": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p never",
"pack:win:setup:x86": "cross-env TARGET=Setup ARCH=x86 electron-builder -w=nsis --ia32 -p never",
@ -19,7 +19,7 @@
"pack:win:7z:x64": "cross-env TARGET=green ARCH=win_x64 electron-builder -w=7z --x64 -p never",
"pack:win:7z:x86": "cross-env TARGET=green ARCH=win_x86 electron-builder -w=7z --ia32 -p never",
"pack:win:7z:arm64": "cross-env TARGET=green ARCH=win_arm64 electron-builder -w=7z --arm64 -p never",
"pack:linux": "node build-config/pack.js && npm run pack:linux:deb && npm run pack:linux:appImage && npm run pack:linux:rpm && npm run pack:linux:pacman",
"pack:linux": "ts-node build-config/pack.js && npm run pack:linux:deb && npm run pack:linux:appImage && npm run pack:linux:rpm && npm run pack:linux:pacman",
"pack:linux:appImage": "cross-env ARCH=x64 electron-builder -l=AppImage -p never",
"pack:linux:deb": "npm run pack:linux:deb:x64 && npm run pack:linux:deb:arm64 && npm run pack:linux:deb:armv7l",
"pack:linux:deb:x64": "cross-env ARCH=x64 electron-builder -l=deb --x64 -p never",
@ -27,10 +27,10 @@
"pack:linux:deb:armv7l": "cross-env ARCH=armv7l electron-builder -l=deb --armv7l -p never",
"pack:linux:rpm": "cross-env ARCH=x64 electron-builder -l=rpm --x64 -p never",
"pack:linux:pacman": "cross-env ARCH=x64 electron-builder -l=pacman --x64 -p never",
"pack:mac": "node build-config/pack.js && npm run pack:mac:dmg && npm run pack:mac:dmg:arm64",
"pack:mac": "ts-node build-config/pack.js && npm run pack:mac:dmg && npm run pack:mac:dmg:arm64",
"pack:mac:dmg": "cross-env electron-builder -m=dmg -p never",
"pack:mac:dmg:arm64": "cross-env electron-builder -m=dmg --arm64 -p never",
"pack:dir": "node build-config/pack.js && electron-builder --dir",
"pack:dir": "ts-node build-config/pack.js && electron-builder --dir",
"publish": "node publish",
"publish:win:setup:x64:always": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p always",
"publish:win:setup:x64": "cross-env TARGET=Setup ARCH=x64 electron-builder -w=nsis --x64 -p always",
@ -54,18 +54,11 @@
"publish:linux:appImage": "cross-env ARCH=x64 electron-builder -l=AppImage -p onTagOrDraft",
"publish:linux:rpm": "cross-env ARCH=x64 electron-builder -l=rpm --x64 -p onTagOrDraft",
"publish:linux:pacman": "cross-env ARCH=x64 electron-builder -l=pacman --x64 -p onTagOrDraft",
"dev": "cross-env NODE_OPTIONS=--max-http-header-size=200000 node build-config/runner-dev.js",
"clean:electron": "rimraf dist",
"clean": "rimraf dist && rimraf build",
"dev": "cross-env NODE_OPTIONS=--max-http-header-size=200000 ts-node build-config/runner-dev.js",
"build:theme": "node src/common/theme/createThemes.js",
"build:src": "node build-config/pack.js",
"build:main": "cross-env NODE_ENV=production webpack --config build-config/main/webpack.config.prod.js --progress",
"build:renderer": "cross-env NODE_ENV=production webpack --config build-config/renderer/webpack.config.prod.js --progress",
"build:renderer-lyric": "cross-env NODE_ENV=production webpack --config build-config/renderer-lyric/webpack.config.prod.js --progress",
"build:renderer-scripts": "cross-env NODE_ENV=production webpack --config build-config/renderer-scripts/webpack.config.prod.js --progress",
"build": "npm run clean:electron && npm run build:main && npm run build:renderer && npm run build:renderer-lyric && npm run build:renderer-scripts",
"lint": "eslint --ext .ts,.js,.vue -f node_modules/eslint-formatter-friendly src",
"lint:fix": "eslint --ext .ts,.js,.vue -f node_modules/eslint-formatter-friendly --fix src",
"build": "ts-node build-config/pack.js",
"lint": "eslint --ext .ts,.js,.vue src",
"lint:fix": "eslint --ext .ts,.js,.vue --fix src",
"postinstall": "electron-builder install-app-deps",
"dp": "cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://127.0.0.1:2081 npm run pack",
"up": "cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://127.0.0.1:2081 npm i"
@ -219,66 +212,41 @@
"@tsconfig/recommended": "^1.0.2",
"@types/better-sqlite3": "^7.6.4",
"@types/needle": "^3.2.0",
"@types/node": "^20.4.8",
"@types/spinnies": "^0.5.0",
"@types/tunnel": "^0.0.3",
"@types/ws": "8.5.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@volar/vue-language-plugin-pug": "^1.6.5",
"@vitejs/plugin-vue": "^4.2.3",
"@vue/eslint-config-typescript": "^11.0.3",
"@vue/language-plugin-pug": "^1.8.8",
"babel-loader": "^9.1.3",
"browserslist": "^4.21.9",
"@vue/tsconfig": "^0.4.0",
"browserslist": "^4.21.10",
"chalk": "^4.1.2",
"changelog-parser": "^3.0.1",
"copy-webpack-plugin": "^11.0.0",
"core-js": "^3.32.0",
"cross-env": "^7.0.3",
"css-loader": "^6.8.1",
"css-minimizer-webpack-plugin": "^5.0.1",
"del": "^6.1.1",
"electron": "^22.3.18",
"electron-builder": "^24.6.3",
"electron-debug": "^3.2.0",
"electron-devtools-installer": "^3.2.0",
"electron-to-chromium": "^1.4.477",
"electron-to-chromium": "^1.4.485",
"electron-updater": "^6.1.4",
"eslint": "^8.46.0",
"eslint-config-standard": "^17.1.0",
"eslint-config-standard-with-typescript": "^35.0.0",
"eslint-formatter-friendly": "github:lyswhut/eslint-friendly-formatter#2170d1320e2fad13615a9dcf229669f0bb473a53",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.16.0",
"eslint-plugin-vue": "^9.16.1",
"eslint-plugin-vue-pug": "^0.6.0",
"eslint-webpack-plugin": "^4.0.1",
"html-webpack-plugin": "^5.5.3",
"less": "^4.1.3",
"less-loader": "^11.1.3",
"mini-css-extract-plugin": "^2.7.6",
"node-loader": "^2.0.0",
"postcss": "^8.4.27",
"postcss-loader": "^7.3.3",
"less": "^4.2.0",
"postcss-pxtorem": "^6.0.0",
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0",
"rimraf": "^5.0.1",
"spinnies": "github:lyswhut/spinnies#233305c58694aa3b053e3ab9af9049993f918b9d",
"svg-sprite-loader": "^6.0.11",
"svg-transform-loader": "^2.0.13",
"svgo-loader": "^4.0.0",
"terser": "^5.19.2",
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vue-eslint-parser": "^9.3.1",
"vue-loader": "^17.2.2",
"vue-template-compiler": "^2.7.14",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-hot-middleware": "github:lyswhut/webpack-hot-middleware#329c4375134b89d39da23a56a94db651247c74a1",
"webpack-merge": "^5.9.0"
"vite": "^4.4.8",
"vite-plugin-electron-renderer": "^0.14.5",
"vite-plugin-svg-icons": "^2.0.1",
"vue-eslint-parser": "^9.3.1"
},
"dependencies": {
"@simonwep/pickr": "^1.8.2",
@ -287,7 +255,7 @@
"comlink": "~4.3.1",
"crypto-js": "^4.1.1",
"electron-font-manager": "github:lyswhut/electron-font-manager#6d2f5ecf850c4fe34812b9394913680462ee0dae",
"electron-log": "^4.4.8",
"electron-log": "^5.0.0-beta.25",
"electron-store": "^8.1.0",
"font-list": "^1.5.0",
"iconv-lite": "^0.6.3",
@ -302,7 +270,7 @@
"utf-8-validate": "^6.0.3",
"vue": "~3.2.47",
"vue-router": "^4.2.4",
"ws": "^8.13.0"
"ws": "github:lyswhut/ws#76966d23e9b610422d8395cdd3a6b1ca0e1f25c4"
},
"overrides": {
"got": "^11",

View File

@ -22,3 +22,4 @@
### 其他
- 更新 electron 到 v22.3.18
- 代码构建工具从webpack迁移到vite提升代码打包速度与开发模式启动速度在我电脑上构建时间从60s降到21s开发模式启动时间从60s降到10s

15
src/common/.eslintrc.cjs Normal file
View File

@ -0,0 +1,15 @@
/* eslint-env node */
const { base, typescript } = require('../../.eslintrc.base.cjs')
module.exports = {
root: true,
...base,
overrides: [
{
...typescript,
parserOptions: {
project: './tsconfig.json',
},
},
],
}

View File

@ -1,5 +1,5 @@
import { join } from 'path'
import { homedir } from 'os'
import path from 'node:path'
import os from 'node:os'
const isMac = process.platform == 'darwin'
const isWin = process.platform == 'win32'
@ -102,7 +102,7 @@ const defaultSetting: LX.AppSetting = {
'list.actionButtonsVisible': false,
'download.enable': false,
'download.savePath': join(homedir(), 'Desktop'),
'download.savePath': path.join(os.homedir(), 'Desktop'),
'download.fileName': '歌名 - 歌手',
'download.maxDownloadNum': 3,
'download.skipExistFile': true,

View File

@ -6,7 +6,7 @@ const ignoreErrorMessage = [
]
process.on('uncaughtException', err => {
if (ignoreErrorMessage.includes(err.message)) return
if (ignoreErrorMessage.includes(err?.message)) return
console.error('An uncaught error occurred!')
console.error(err)
log.error(err)

View File

@ -8,7 +8,7 @@
* @param {string} c1 rgb(a) color2
* @returns color
*/
exports.RGB_Linear_Blend=(p,c0,c1)=>{
export const RGB_Linear_Blend=(p,c0,c1)=>{
var i=parseInt,r=Math.round,P=1-p,[a,b,c,d]=c0.split(","),[e,f,g,h]=c1.split(","),x=d||h,j=x?","+(!d?h:!h?d:r((parseFloat(d)*P+parseFloat(h)*p)*1000)/1000+")"):")";
return"rgb"+(x?"a(":"(")+r(i(a[3]=="a"?a.slice(5):a.slice(4))*P+i(e[3]=="a"?e.slice(5):e.slice(4))*p)+","+r(i(b)*P+i(f)*p)+","+r(i(c)*P+i(g)*p)+j;
}
@ -20,7 +20,7 @@ exports.RGB_Linear_Blend=(p,c0,c1)=>{
* @param {string} c1 rgb(a) color2
* @returns color
*/
exports.RGB_Log_Blend=(p,c0,c1)=>{
export const RGB_Log_Blend=(p,c0,c1)=>{
var i=parseInt,r=Math.round,P=1-p,[a,b,c,d]=c0.split(","),[e,f,g,h]=c1.split(","),x=d||h,j=x?","+(!d?h:!h?d:r((parseFloat(d)*P+parseFloat(h)*p)*1000)/1000+")"):")";
return"rgb"+(x?"a(":"(")+r((P*i(a[3]=="a"?a.slice(5):a.slice(4))**2+p*i(e[3]=="a"?e.slice(5):e.slice(4))**2)**0.5)+","+r((P*i(b)**2+p*i(f)**2)**0.5)+","+r((P*i(c)**2+p*i(g)**2)**0.5)+j;
}
@ -32,7 +32,7 @@ exports.RGB_Log_Blend=(p,c0,c1)=>{
* @param {string} c0 rgb(a) color
* @returns color
*/
exports.RGB_Linear_Shade=(p,c0)=>{
export const RGB_Linear_Shade=(p,c0)=>{
var i=parseInt,r=Math.round,[a,b,c,d]=c0.split(","),n=p<0,t=n?0:255*p,P=n?1+p:1-p;
return"rgb"+(d?"a(":"(")+r(i(a[3]=="a"?a.slice(5):a.slice(4))*P+t)+","+r(i(b)*P+t)+","+r(i(c)*P+t)+(d?","+d:")");
}
@ -44,7 +44,7 @@ exports.RGB_Linear_Shade=(p,c0)=>{
* @param {string} c0 rgb(a) color
* @returns color
*/
exports.RGB_Log_Shade=(p,c0)=>{
export const RGB_Log_Shade=(p,c0)=>{
var i=parseInt,r=Math.round,[a,b,c,d]=c0.split(","),n=p<0,t=n?0:p*255**2,P=n?1+p:1-p;
return"rgb"+(d?"a(":"(")+r((P*i(a[3]=="a"?a.slice(5):a.slice(4))**2+t)**0.5)+","+r((P*i(b)**2+t)**0.5)+","+r((P*i(c)**2+t)**0.5)+(d?","+d:")");
}
@ -56,7 +56,7 @@ exports.RGB_Log_Shade=(p,c0)=>{
* @param {string} color
* @returns color
*/
exports.RGB_Alpha_Shade = (p, color) => {
export const RGB_Alpha_Shade = (p, color) => {
var i = parseInt
var n = p < 0
var [r, g, b, a] = color.split(",")

View File

@ -1,8 +1,8 @@
//! 更新默认主题配置后,需要执行 npm run build:theme 重新构建index.json
const fs = require('fs')
const path = require('path')
const { createThemeColors } = require('./utils')
import fs from 'fs'
import path from 'path'
import { createThemeColors } from './utils'
const defaultThemes = [
{

View File

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

Before

Width:  |  Height:  |  Size: 353 KiB

After

Width:  |  Height:  |  Size: 353 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

Before

Width:  |  Height:  |  Size: 997 KiB

After

Width:  |  Height:  |  Size: 997 KiB

View File

@ -1,6 +1,6 @@
const { RGB_Linear_Shade, RGB_Alpha_Shade } = require('./colorUtils')
import { RGB_Linear_Shade, RGB_Alpha_Shade } from './colorUtils'
exports.createThemeColors = (rgbaColor, fontRgbaColor, isDark) => {
export const createThemeColors = (rgbaColor, fontRgbaColor, isDark) => {
const colors = {
'--color-primary': rgbaColor,
}

View File

@ -1,11 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@common/*": ["common/*"],
},
"typeRoots": [
"./types"
],
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@common/*": ["common/*"],
},
},
}

View File

@ -1,4 +1,4 @@
import type { I18n } from '@/lang/i18n'
import type { I18n } from '@root/lang/i18n'
declare global {

View File

@ -1,4 +1,4 @@
import { type Message } from '@/lang'
import { type Message } from '@root/lang'
// interface DownloadList {

View File

@ -1,6 +1,5 @@
import log from 'electron-log'
log.transports.file.level = 'info'
export const isLinux = process.platform == 'linux'
export const isWin = process.platform == 'win32'

View File

@ -1,4 +1,4 @@
const { getNow, TimeoutTools } = require('./utils')
import { getNow, TimeoutTools } from './utils'
// const fontFormateRxp = /(?=<\d+,\d+>).*?/g
const fontSplitRxp = /(?=<\d+,\d+>).*?/g
@ -25,7 +25,7 @@ const createAnimation = (dom, duration, isVertical) => new window.Animation(new
// https://jsfiddle.net/ceqpnbky/
// https://jsfiddle.net/ceqpnbky/1/
module.exports = class FontPlayer {
export default class FontPlayer {
constructor({
time = 0,
rate = 1,

View File

@ -1,9 +1,9 @@
const LinePlayer = require('./line-player')
const FontPlayer = require('./font-player')
import LinePlayer from './line-player'
import FontPlayer from './font-player'
const fontTimeExp = /<(\d+),(\d+)>/g
module.exports = class Lyric {
export default class Lyric {
constructor({
lyric = '',
extendedLyrics = [],

View File

@ -1,4 +1,4 @@
const { getNow, TimeoutTools } = require('./utils')
import { getNow, TimeoutTools } from './utils'
const timeFieldExp = /^(?:\[[\d:.]+\])+/g
const timeExp = /\d{1,3}(:\d{1,3}){0,2}(?:\.\d{1,3})/g
@ -43,7 +43,7 @@ const parseExtendedLyric = (lrcLinesMap, extendedLyric) => {
}
}
module.exports = class LinePlayer {
export default class LinePlayer {
constructor({ offset = 0, rate = 1, onPlay = function() { }, onSetLyric = function() { } } = {}) {
this.tags = {}
this.lines = null

View File

@ -1,7 +1,7 @@
const getNow = exports.getNow = typeof performance == 'object' && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date)
export const getNow = typeof performance == 'object' && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date)
exports.TimeoutTools = class TimeoutTools {
export class TimeoutTools {
constructor(thresholdTime = 80) {
this.invokeTime = 0
this.animationFrameId = null

View File

@ -1,8 +1,8 @@
import fs from 'fs'
import crypto from 'crypto'
import { gzip, gunzip } from 'zlib'
import fs from 'node:fs'
import crypto from 'node:crypto'
import { gzip, gunzip } from 'node:zlib'
import path from 'node:path'
import { log } from '@common/utils'
import path from 'path'
export const joinPath = (...paths: string[]): string => path.join(...paths)

15
src/lang/.eslintrc.cjs Normal file
View File

@ -0,0 +1,15 @@
/* eslint-env node */
const { base, typescript } = require('../../.eslintrc.base.cjs')
module.exports = {
root: true,
...base,
overrides: [
{
...typescript,
parserOptions: {
project: './tsconfig.json',
},
},
],
}

18
src/main/.eslintrc.cjs Normal file
View File

@ -0,0 +1,18 @@
/* eslint-env node */
const { base, typescript } = require('../../.eslintrc.base.cjs')
module.exports = {
root: true,
...base,
overrides: [
{
...typescript,
parserOptions: {
project: './tsconfig.json',
},
},
],
ignorePatterns: [
'vendors',
],
}

View File

@ -1,4 +1,4 @@
import { join, dirname } from 'path'
import path from 'node:path'
import { existsSync, mkdirSync, renameSync } from 'fs'
import { app, shell, screen, nativeTheme, dialog } from 'electron'
import { URL_SCHEME_RXP } from '@common/constants'
@ -10,22 +10,19 @@ import { createAppEvent, createListEvent } from '@main/event'
import { isMac, log } from '@common/utils'
import createWorkers from './worker'
import { migrateDBData } from './utils/migrate'
import { openDirInExplorer } from '@common/utils/electron'
import { encodePath, openDirInExplorer } from '@common/utils/electron'
export const initGlobalData = () => {
global.isDev = process.env.NODE_ENV !== 'production'
const envParams = parseEnvParams()
global.envParams = {
cmdParams: envParams.cmdParams,
deeplink: envParams.deeplink,
}
if (global.isDev) {
// eslint-disable-next-line no-undef
global.staticPath = webpackStaticPath
} else {
global.staticPath = join(__dirname, '/static')
}
global.staticPath =
process.env.NODE_ENV !== 'production'
? __STATIC_PATH__
: path.join(encodePath(__dirname), '../static')
}
export const initSingleInstanceHandle = () => {
@ -75,10 +72,10 @@ export const applyElectronEnvParams = () => {
export const setUserDataPath = () => {
// windows平台下如果应用目录下存在 portable 文件夹则将数据存在此文件下
if (process.platform == 'win32') {
const portablePath = join(dirname(app.getPath('exe')), '/portable')
const portablePath = path.join(path.dirname(app.getPath('exe')), '/portable')
if (existsSync(portablePath)) {
app.setPath('appData', portablePath)
const appDataPath = join(portablePath, '/userData')
const appDataPath = path.join(portablePath, '/userData')
if (!existsSync(appDataPath)) mkdirSync(appDataPath)
app.setPath('userData', appDataPath)
}
@ -86,12 +83,12 @@ export const setUserDataPath = () => {
const userDataPath = app.getPath('userData')
global.lxOldDataPath = userDataPath
global.lxDataPath = join(userDataPath, 'LxDatas')
global.lxDataPath = path.join(userDataPath, 'LxDatas')
if (!existsSync(global.lxDataPath)) mkdirSync(global.lxDataPath)
}
export const registerDeeplink = (startApp: () => void) => {
if (global.isDev && process.platform === 'win32') {
if (process.env.NODE_ENV !== 'production' && process.platform === 'win32') {
// Set the path of electron.exe and your app.
// These two additional parameters are only available on windows.
// console.log(process.execPath, process.argv)
@ -117,8 +114,8 @@ export const registerDeeplink = (startApp: () => void) => {
export const listenerAppEvent = (startApp: () => void) => {
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
if (global.isDev) {
console.log('navigation to url:', navigationUrl)
if (process.env.NODE_ENV !== 'production') {
console.log('navigation to url:', navigationUrl.length > 130 ? navigationUrl.substring(0, 130) + '...' : navigationUrl)
return
}
if (!navigationUrlWhiteList.some(url => url.test(navigationUrl))) {
@ -240,13 +237,13 @@ export const initAppSetting = async() => {
if (!isInitialized) {
let dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
if (dbFileExists === null) {
const backPath = join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
const backPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
dialog.showMessageBoxSync({
type: 'warning',
message: 'Database verify failed',
detail: `数据库表结构校验失败,我们将把有问题的数据库备份到:${backPath}\n若此问题导致你的数据丢失你可以尝试从备份文件找回它们。\n\nThe database table structure verification failed, we will back up the problematic database to: ${backPath}\nIf this problem causes your data to be lost, you can try to retrieve them from the backup file.`,
})
renameSync(join(global.lxDataPath, 'lx.data.db'), backPath)
renameSync(path.join(global.lxDataPath, 'lx.data.db'), backPath)
openDirInExplorer(backPath)
dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
}

View File

@ -26,5 +26,5 @@ app.on('ready', () => {
})
// Require `main` process to boot app
require('./index')
import('./index')

View File

@ -1,4 +1,5 @@
import { app } from 'electron'
import './utils/logInit'
import '@common/error'
import {
initGlobalData,

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'

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'

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))
}

View File

@ -1,2 +0,0 @@
exports.userApis = []

View File

@ -0,0 +1,2 @@
export const userApis: LX.UserApi.UserApiInfo[] = []

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

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]

View File

@ -10,4 +10,5 @@ const names = {
for (const key of Object.keys(names)) {
names[key] = `userApi_${key}`
}
module.exports = names
export default names

View File

@ -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 })
}

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()

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()

View File

@ -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
}

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 = ({

View File

@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
// "module": "esnext",
"resolveJsonModule": true,
"typeRoots": [
"./types"
],

View File

@ -43,7 +43,7 @@ declare global {
// }
// }
var isDev: boolean
// var isDev: boolean
var envParams: LX.EnvParams
var staticPath: string
var lxDataPath: string

View File

@ -9,6 +9,7 @@
// // }
// // }
declare const webpackStaticPath: string
declare const webpackUserApiPath: string
declare const __STATIC_PATH__: string
declare const __USER_API_PATH__: string
declare const __QRC_DECODE_NODE_PATH__: string

View File

@ -0,0 +1,4 @@
import log from 'electron-log'
log.transports.file.level = 'info'
log.initialize()

View File

@ -1,8 +1,8 @@
import Store from 'electron-store'
import { dialog, shell } from 'electron'
import { join } from 'path'
import fs from 'fs'
import log from 'electron-log'
import path from 'node:path'
import fs from 'node:fs'
import { log } from '@common/utils'
type Stores = Record<string, Store>
@ -27,8 +27,8 @@ export default (name: string, isIgnoredError = true, isShowErrorAlert = true): S
if (!isIgnoredError) throw error
const backPath = join(global.lxDataPath, name + '.json.bak')
fs.renameSync(join(global.lxDataPath, name + '.json'), backPath)
const backPath = path.join(global.lxDataPath, name + '.json.bak')
fs.renameSync(path.join(global.lxDataPath, name + '.json'), backPath)
if (isShowErrorAlert) {
dialog.showMessageBoxSync({
type: 'error',

View File

@ -18,20 +18,20 @@ const initTables = (db: Database.Database) => {
// 打开、初始化数据库
export const init = (lxDataPath: string): boolean | null => {
const databasePath = path.join(lxDataPath, 'lx.data.db')
const nativeBinding = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
const nativeBinding = path.join(__dirname, '../../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
let dbFileExists = true
try {
db = new Database(databasePath, {
fileMustExist: true,
nativeBinding,
verbose: global.isDev ? console.log : undefined,
verbose: process.env.NODE_ENV !== 'production' ? console.log : undefined,
})
} catch (error) {
console.log(error)
db = new Database(databasePath, {
nativeBinding,
verbose: global.isDev ? console.log : undefined,
verbose: process.env.NODE_ENV !== 'production' ? console.log : undefined,
})
initTables(db)
dbFileExists = false

View File

@ -1,15 +1,15 @@
import { Worker } from 'worker_threads'
import { Worker } from 'node:worker_threads'
import * as Comlink from 'comlink'
import nodeEndpoint from 'comlink/dist/esm/node-adapter'
import path from 'node:path'
// import dbService from '../dbService/index'
export type DBSeriveTypes = Comlink.Remote<LX.WorkerDBSeriveListTypes>
export declare type DBSeriveTypes = Comlink.Remote<LX.WorkerDBSeriveListTypes>
export const createDBServiceWorker = () => {
const worker: Worker = new Worker(new URL(
/* webpackChunkName: 'dbService.worker' */
'../dbService',
import.meta.url,
))
// console.log(new URL('../dbService', import.meta.url))
// console.log(__dirname)
const worker: Worker = new Worker(path.join(__dirname, './dbService.worker'))
return Comlink.wrap<LX.WorkerDBSeriveListTypes>(nodeEndpoint(worker))
}

View File

@ -1,9 +1,9 @@
import { parentPort } from 'worker_threads'
import worker from 'node:worker_threads'
import * as Comlink from 'comlink'
import nodeEndpoint from 'comlink/dist/esm/node-adapter'
export const exposeWorker = (obj: any) => {
if (parentPort == null) return
Comlink.expose(obj, nodeEndpoint(parentPort))
if (worker.parentPort == null) return
Comlink.expose(obj, nodeEndpoint(worker.parentPort))
}

View File

@ -0,0 +1,16 @@
/* eslint-env node */
const { base, typescript, vue } = require('../../.eslintrc.base.cjs')
module.exports = {
root: true,
...base,
overrides: [
vue,
{
...typescript,
parserOptions: {
project: './tsconfig.json',
},
},
],
}

View File

@ -1,25 +1,22 @@
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
const requireComponent = require.context('./', true, /\.vue$/)
const requireComponent = import.meta.glob(['./**/*.vue', '!./**/components/**/*.vue'], { eager: true })
const vueFileRxp = /\.vue$/
const vueIndexFileRxp = /\/index\.vue$/
export default app => {
requireComponent.keys().forEach(fileName => {
const filePath = fileName.replace(/^\.\//, '')
Object.entries(requireComponent).forEach(([path, module]) => {
path = path.replace(/^\.\//, '')
let fileName = vueIndexFileRxp.test(path)
? path.replace(vueIndexFileRxp, '')
: path.replace(vueFileRxp, '')
if (!filePath.split('/').every((path, index, arr) => {
const char = path.charAt(0)
return vueFileRxp.test(path) || char.toUpperCase() !== char || arr[index + 1] == 'index.vue'
})) return
let componentName = upperFirst(camelCase(fileName))
const componentConfig = requireComponent(fileName)
// console.log(componentName)
let componentName = upperFirst(camelCase(filePath.replace(/\.\w+$/, '')))
if (componentName.endsWith('Index')) componentName = componentName.replace(/Index$/, '')
app.component(componentName, componentConfig.default || componentConfig)
app.component(componentName, module.default)
})
}

View File

@ -58,7 +58,7 @@
<script>
import { ref } from '@common/utils/vueTools'
import { setting, themeList } from '@lyric/store/state'
import { setting } from '@lyric/store/state'
import { updateSetting } from '@lyric/store/action'
export default {
@ -105,7 +105,6 @@ export default {
}
return {
setting,
themeList,
isShowThemeList,
handleClose,

View File

@ -198,7 +198,7 @@ export default {
// // -webkit-text-fill-color: #fff;
// // -webkit-text-stroke: thin #124628;
// }
.lyric-space {
.lyricSpace {
height: 80%;
}
// .lyric-text {
@ -224,7 +224,7 @@ export default {
}
}
}
.lrc-active-zoom {
.lrcActiveZoom {
:global {
.line-content {
&.active {
@ -246,21 +246,21 @@ export default {
}
}
}
.font-weight-font {
.fontWeightFont {
:global {
.font-mode > .line {
font-weight: bold;
}
}
}
.font-weight-line {
.fontWeightLine {
:global {
.line-mode > .line {
font-weight: bold;
}
}
}
.font-weight-extended {
.fontWeightExtended {
:global {
.extended {
font-weight: bold;

View File

@ -196,7 +196,7 @@ export default {
// // -webkit-text-fill-color: #fff;
// // -webkit-text-stroke: thin #124628;
// }
.lyric-space {
.lyricSpace {
width: 80%;
height: 100%;
}
@ -223,7 +223,7 @@ export default {
}
}
}
.lrc-active-zoom {
.lrcActiveZoom {
:global {
.line-content {
&.active {
@ -245,21 +245,21 @@ export default {
}
}
}
.font-weight-font {
.fontWeightFont {
:global {
.font-mode > .line {
font-weight: bold;
}
}
}
.font-weight-line {
.fontWeightLine {
:global {
.line-mode > .line {
font-weight: bold;
}
}
}
.font-weight-extended {
.fontWeightExtended {
:global {
.extended {
font-weight: bold;

View File

@ -27,5 +27,6 @@
}
if (/theme=(.+)(#|$)/.test(window.location.search)) applyThemeColor(RegExp.$1)
</script>
<script type="module" src="/main.ts"></script>
</body>
</html>

View File

@ -6,7 +6,7 @@ import mountComponents from './components'
import App from './App.vue'
import '@/common/error'
import '@root/common/error'
import { getSetting, onMainWindowInited, onSettingChanged, sendConnectMainWindowEvent } from './utils/ipc'
import { initSetting, mergeSetting } from './store/action'
import { init as initMainWindowChannel } from './core/mainWindowChannel'

View File

@ -1,5 +1,5 @@
import type { I18n } from '@/lang'
import { createI18n, i18nPlugin, useI18n } from '@/lang'
import type { I18n } from '@root/lang'
import { createI18n, i18nPlugin, useI18n } from '@root/lang'
window.i18n = createI18n()

View File

@ -2,12 +2,13 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"isolatedModules": true,
"moduleResolution": "nodenext",
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@common/*": ["common/*"],
// "@renderer/*": ["renderer/*"],
"@lyric/*": ["renderer-lyric/*"],
"@static/*": ["static/*"],
"@/*": ["./*"],
"@root/*": ["./*"],
},
"typeRoots": [ /* Specify multiple folders that act like './node_modules/@types'. */
"./types"

View File

@ -0,0 +1,19 @@
/* eslint-env node */
const { base, typescript, vue } = require('../../.eslintrc.base.cjs')
module.exports = {
root: true,
...base,
overrides: [
vue,
{
...typescript,
parserOptions: {
project: './tsconfig.json',
},
},
],
ignorePatterns: [
'vendors',
],
}

View File

@ -51,7 +51,7 @@ export default {
default: false,
},
},
emits: ['update:model-value', 'change'],
emits: ['update:modelValue', 'change'],
data() {
return {
checked: false,
@ -80,7 +80,7 @@ export default {
modelValue = checked
} else modelValue = checked ? this.value : ''
}
this.$emit('update:model-value', modelValue)
this.$emit('update:modelValue', modelValue)
this.$emit('change', modelValue)
},
setValue(value) {

View File

@ -52,7 +52,7 @@ export default {
// default: true,
// },
},
emits: ['update:model-value', 'submit', 'change'],
emits: ['update:modelValue', 'submit', 'change'],
methods: {
handleInput(event) {
let value = event.target.value
@ -60,7 +60,7 @@ export default {
value = value.trim()
event.target.value = value
}
this.$emit('update:model-value', value)
this.$emit('update:modelValue', value)
},
focus() {
this.$refs.dom_input.focus()
@ -78,7 +78,7 @@ export default {
// if (dom_input.selectionStart == dom_input.selectionEnd) {
const value = text.substring(0, dom_input.selectionStart) + str + text.substring(dom_input.selectionEnd, text.length)
event.target.value = value
this.$emit('update:model-value', value)
this.$emit('update:modelValue', value)
// } else {
// clipboardWriteText(text.substring(dom_input.selectionStart, dom_input.selectionEnd))
// }

View File

@ -48,13 +48,13 @@ export default {
default: 'name',
},
},
emits: ['update:model-value', 'menu-click'],
emits: ['update:modelValue', 'menu-click'],
setup(props, { emit }) {
const visible = computed(() => props.modelValue)
const location = computed(() => props.xy)
const onHide = () => {
emit('update:model-value', false)
emit('update:modelValue', false)
menuClick(null)
}

View File

@ -42,7 +42,7 @@ export default {
default: '',
},
},
emits: ['update:model-value', 'change'],
emits: ['update:modelValue', 'change'],
data() {
return {
show: false,
@ -84,7 +84,7 @@ export default {
handleClick(item) {
// console.log(this.modelValue)
if (item === this.modelValue) return
this.$emit('update:model-value', this.itemKey ? item[this.itemKey] : item)
this.$emit('update:modelValue', this.itemKey ? item[this.itemKey] : item)
this.$emit('change', item)
},
handleShow() {

View File

@ -1,6 +1,6 @@
<template>
<div :class="[$style.sliderContent, { [$style.disabled]: disabled }, className]">
<div :class="[$style.slider ]">
<div :class="[$style.slider]">
<div ref="dom_sliderBar" :class="$style.sliderBar" :style="{ transform: `scaleX(${(value - min) / (max - min) || 0})` }" />
</div>
<div :class="$style.sliderMask" @mousedown="handleSliderMsDown" />
@ -86,7 +86,7 @@ export default {
<style lang="less" module>
@import '@renderer/assets/styles/layout.less';
.slider-content {
.sliderContent {
flex: none;
position: relative;
width: 100px;
@ -125,7 +125,7 @@ export default {
// opacity: .5;
// }
.slider-bar {
.sliderBar {
position: absolute;
left: 0;
top: 0;

View File

@ -1,9 +1,9 @@
<template>
<ul :class="[$style.list, $style[align]]" role="tablist">
<li
v-for="item in list" :key="item[itemKey]" :class="[$style.listItem, {[$style.active]: modelValue == item[itemKey]}]" tabindex="-1"
role="tab" :aria-label="item[itemLabel]" ignore-tip :aria-selected="modelValue == item[itemKey]"
@click="handleToggle(item[itemKey])"
v-for="item in list"
:key="item[itemKey]" :class="[$style.listItem, {[$style.active]: modelValue == item[itemKey]}]" tabindex="-1" role="tab"
:aria-label="item[itemLabel]" ignore-tip :aria-selected="modelValue == item[itemKey]" @click="handleToggle(item[itemKey])"
>
<span :class="$style.label">{{ item[itemLabel] }}</span>
</li>
@ -37,11 +37,11 @@ export default {
default: '',
},
},
emits: ['update:model-value', 'change'],
emits: ['update:modelValue', 'change'],
setup(props, { emit }) {
const handleToggle = id => {
if (id == props.modelValue) return
emit('update:model-value', id)
emit('update:modelValue', id)
emit('change', id)
}

View File

@ -54,19 +54,19 @@
// // div.list-item(@click="handleListItemClick($event, index)" @contextmenu="handleListItemRightClick($event, index)"
// // :class="[{ selected: rightClickSelectedIndex == index }, { active: selectedList.includes(item) }]")
// // div.list-item-cell.nobreak.center(:style="{ width: rowWidth.r1 }" style="padding-left: 3px; padding-right: 3px;" :class="$style.noSelect" @click.stop) {{index + 1}}
// // div.list-item-cell.nobreak.center(:style="{ width: rowWidth.r1 }" style="padding-left: 3px; padding-right: 3px;" :class="$style.noSelect" @click.stop) {{ index + 1 }}
// // div.list-item-cell.auto(:style="{ width: rowWidth.r2 }" :aria-label="item.name + (item.meta._qualitys.flac32bit ? ` - ${$t('tag__lossless_24bit')}` : (item.meta._qualitys.ape || item.meta._qualitys.flac || item.meta._qualitys.wav) ? ` - ${$t('tag__lossless')}` : item.meta._qualitys['320k'] ? ` - ${$t('tag__high_quality')}` : '') + (sourceTag ? ` - ${item.source}` : '')")
// // span.select {{item.name}}
// // span.badge.badge-theme-primary(:class="[$style.labelQuality, $style.noSelect]" v-if="item.meta._qualitys.flac32bit") {{$t('tag__lossless_24bit')}}
// // span.badge.badge-theme-primary(:class="[$style.labelQuality, $style.noSelect]" v-else-if="item.meta._qualitys.ape || item.meta._qualitys.flac || item.meta._qualitys.wav") {{$t('tag__lossless')}}
// // span.badge.badge-theme-secondary(:class="[$style.labelQuality, $style.noSelect]" v-else-if="item.meta._qualitys['320k']") {{$t('tag__high_quality')}}
// // span.badge.badge-theme-tertiary(:class="[$style.labelQuality, $style.noSelect]" v-if="sourceTag") {{item.source}}
// // span.select {{ item.name }}
// // span.badge.badge-theme-primary(:class="[$style.labelQuality, $style.noSelect]" v-if="item.meta._qualitys.flac32bit") {{ $t('tag__lossless_24bit') }}
// // span.badge.badge-theme-primary(:class="[$style.labelQuality, $style.noSelect]" v-else-if="item.meta._qualitys.ape || item.meta._qualitys.flac || item.meta._qualitys.wav") {{ $t('tag__lossless') }}
// // span.badge.badge-theme-secondary(:class="[$style.labelQuality, $style.noSelect]" v-else-if="item.meta._qualitys['320k']") {{ $t('tag__high_quality') }}
// // span.badge.badge-theme-tertiary(:class="[$style.labelQuality, $style.noSelect]" v-if="sourceTag") {{ item.source }}
// // div.list-item-cell(:style="{ width: rowWidth.r3 }" :aria-label="item.singer")
// // span.select {{item.singer}}
// // span.select {{ item.singer }}
// // div.list-item-cell(:style="{ width: rowWidth.r4 }" :aria-label="item.albumName")
// // span.select {{item.meta.albumName}}
// // span.select {{ item.meta.albumName }}
// // div.list-item-cell(:style="{ width: rowWidth.r5 }")
// // span(:class="[$style.time, $style.noSelect]") {{item.meta.interval || '--/--'}}
// // span(:class="[$style.time, $style.noSelect]") {{ item.meta.interval || '--/--' }}
// // div.list-item-cell(:style="{ width: rowWidth.r6 }" style="padding-left: 0; padding-right: 0;")
// // material-list-buttons(:index="index" :class="$style.btns"
// // :remove-btn="false" @btn-click="handleListBtnClick"

View File

@ -22,7 +22,7 @@ import { watch, ref, onBeforeUnmount } from '@common/utils/vueTools'
import { defaultList, loveList, userLists } from '@renderer/store/list/state'
import { addListMusics, moveListMusics, createUserList, getMusicExistListIds } from '@renderer/store/list/action'
import useKeyDown from '@renderer/utils/compositions/useKeyDown'
import { useI18n } from '@/lang'
import { useI18n } from '@root/lang'
export default {
props: {
@ -207,7 +207,7 @@ export default {
color: var(--color-primary);
}
.btn-content {
.btnContent {
flex: auto;
max-height: 100%;
padding-right: 15px;

Some files were not shown because too many files have changed in this diff Show More