From 62e26cae7d213e34e2aac06b26041414bc92a190 Mon Sep 17 00:00:00 2001 From: alger Date: Fri, 10 Jan 2025 22:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=88=20style:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 4 + .eslintrc.cjs | 135 ++++++++++++++++++ .prettierignore | 6 + .prettierrc.yaml | 5 + src/main/index.ts | 18 +-- src/main/modules/config.ts | 5 +- src/main/modules/fileManager.ts | 15 +- src/main/modules/tray.ts | 14 +- src/main/modules/window.ts | 6 +- src/main/server.ts | 4 +- src/preload/index.d.ts | 2 +- src/renderer/App.vue | 2 +- src/renderer/api/music.ts | 20 +-- src/renderer/components/Coffee.vue | 2 + src/renderer/components/RecommendAlbum.vue | 4 +- src/renderer/components/RecommendSinger.vue | 2 +- .../components/common/InstallAppModal.vue | 33 +++-- src/renderer/components/common/SearchItem.vue | 3 +- src/renderer/components/common/SongItem.vue | 28 ++-- .../components/common/UpdateModal.vue | 72 +++++----- src/renderer/hooks/MusicHook.ts | 4 +- src/renderer/hooks/MusicListHook.ts | 2 +- src/renderer/layout/AppLayout.vue | 4 +- src/renderer/layout/components/MusicFull.vue | 8 +- src/renderer/layout/components/PlayBar.vue | 4 +- src/renderer/layout/components/SearchBar.vue | 6 +- src/renderer/layout/components/TitleBar.vue | 9 +- src/renderer/store/index.ts | 22 +-- src/renderer/type/user.ts | 4 +- src/renderer/types/electron.d.ts | 2 +- src/renderer/utils/fileOperation.ts | 2 +- src/renderer/utils/index.ts | 3 +- src/renderer/utils/request.ts | 39 ++--- src/renderer/utils/update.ts | 34 +++-- src/renderer/views/favorite/index.vue | 2 +- src/renderer/views/history/index.vue | 2 +- src/renderer/views/list/index.vue | 7 +- src/renderer/views/search/index.vue | 4 +- src/renderer/views/set/index.vue | 125 +++++++++------- src/renderer/views/user/index.vue | 26 ++-- 40 files changed, 450 insertions(+), 239 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.cjs create mode 100644 .prettierignore create mode 100644 .prettierrc.yaml diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a6f34fe --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +node_modules +dist +out +.gitignore diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..27da298 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,135 @@ +/* eslint-env node */ +require('@rushstack/eslint-patch/modern-module-resolution'); + +module.exports = { + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'eslint-config-airbnb-base', + '@vue/typescript/recommended', + 'plugin:vue/vue3-recommended', + 'plugin:vue-scoped-css/base', + '@electron-toolkit', + '@electron-toolkit/eslint-config-ts/eslint-recommended', + 'plugin:prettier/recommended' + ], + env: { + browser: true, + node: true, + jest: true, + es6: true + }, + globals: { + defineProps: 'readonly', + defineEmits: 'readonly' + }, + plugins: ['vue', '@typescript-eslint', 'simple-import-sort'], + parserOptions: { + parser: '@typescript-eslint/parser', + sourceType: 'module', + allowImportExportEverywhere: true, + ecmaFeatures: { + jsx: true + } + }, + settings: { + 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'] + }, + rules: { + 'vue/require-default-prop': 'off', + 'vue/multi-word-component-names': 'off', + 'no-nested-ternary': 'off', + 'no-console': 'off', + 'no-continue': 'off', + 'no-restricted-syntax': 'off', + 'no-return-assign': 'off', + 'no-unused-expressions': 'off', + 'no-return-await': 'off', + 'no-plusplus': 'off', + 'no-param-reassign': 'off', + 'no-shadow': 'off', + 'guard-for-in': 'off', + 'import/extensions': 'off', + 'import/no-unresolved': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/prefer-default-export': 'off', + 'import/first': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + 'vue/first-attribute-linebreak': 0, + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_' + } + ], + 'no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_' + } + ], + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/ban-types': 'off', + 'class-methods-use-this': 'off', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error' + }, + overrides: [ + { + files: ['*.vue'], + rules: { + 'vue/component-name-in-template-casing': [2, 'kebab-case'], + 'vue/require-default-prop': 0, + 'vue/multi-word-component-names': 0, + 'vue/no-reserved-props': 0, + 'vue/no-v-html': 0, + 'vue-scoped-css/enforce-style-type': [ + 'error', + { + allows: ['scoped'] + } + ], + '@typescript-eslint/explicit-function-return-type': 'off', + // 需要行尾分号 + 'prettier/prettier': ['error', { endOfLine: 'auto' }] + } + }, + { + files: ['*.ts', '*.tsx'], + rules: { + 'no-await-in-loop': 'off', + 'dot-notation': 'off', + 'constructor-super': 'off', + 'getter-return': 'off', + 'no-const-assign': 'off', + 'no-dupe-args': 'off', + 'no-dupe-class-members': 'off', + 'no-dupe-keys': 'off', + 'no-func-assign': 'off', + 'no-import-assign': 'off', + 'no-new-symbol': 'off', + 'no-obj-calls': 'off', + 'no-redeclare': 'off', + 'no-setter-return': 'off', + 'no-this-before-super': 'off', + 'no-undef': 'off', + 'no-unreachable': 'off', + 'no-unsafe-negation': 'off', + 'no-var': 'error', + 'prefer-const': 'error', + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', + 'valid-typeof': 'off', + 'consistent-return': 'off', + 'no-promise-executor-return': 'off', + 'prefer-promise-reject-errors': 'off', + '@typescript-eslint/explicit-function-return-type': 'off' + } + } + ] +}; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..9c6b791 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +out +dist +pnpm-lock.yaml +LICENSE.md +tsconfig.json +tsconfig.*.json diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..b7283f3 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,5 @@ +singleQuote: true +semi: true +printWidth: 100 +trailingComma: none +endOfLine: auto diff --git a/src/main/index.ts b/src/main/index.ts index 2500619..229bee0 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -3,11 +3,11 @@ import { app, globalShortcut, ipcMain, nativeImage } from 'electron'; import { join } from 'path'; import { loadLyricWindow } from './lyric'; -import { startMusicApi } from './server'; +import { initializeConfig } from './modules/config'; import { initializeFileManager } from './modules/fileManager'; import { initializeTray } from './modules/tray'; import { createMainWindow, initializeWindowManager } from './modules/window'; -import { initializeConfig } from './modules/config'; +import { startMusicApi } from './server'; // 导入所有图标 const iconPath = join(__dirname, '../../resources'); @@ -15,8 +15,8 @@ const icon = nativeImage.createFromPath( process.platform === 'darwin' ? join(iconPath, 'icon.icns') : process.platform === 'win32' - ? join(iconPath, 'favicon.ico') - : join(iconPath, 'icon.png') + ? join(iconPath, 'favicon.ico') + : join(iconPath, 'icon.png') ); let mainWindow: Electron.BrowserWindow; @@ -26,19 +26,19 @@ function initialize() { // 初始化各个模块 initializeConfig(); initializeFileManager(); - + // 创建主窗口 mainWindow = createMainWindow(icon); - + // 初始化窗口管理 initializeWindowManager(); - + // 初始化托盘 initializeTray(iconPath, mainWindow); - + // 启动音乐API startMusicApi(); - + // 加载歌词窗口 loadLyricWindow(ipcMain, mainWindow); } diff --git a/src/main/modules/config.ts b/src/main/modules/config.ts index d5ed62f..1d86464 100644 --- a/src/main/modules/config.ts +++ b/src/main/modules/config.ts @@ -1,5 +1,6 @@ import { app, ipcMain } from 'electron'; import Store from 'electron-store'; + import set from '../set.json'; interface StoreType { @@ -22,7 +23,7 @@ export function initializeConfig() { store = new Store({ name: 'config', defaults: { - set: set + set } }); @@ -39,4 +40,4 @@ export function initializeConfig() { }); return store; -} \ No newline at end of file +} diff --git a/src/main/modules/fileManager.ts b/src/main/modules/fileManager.ts index 4b7a93a..a2f91e3 100644 --- a/src/main/modules/fileManager.ts +++ b/src/main/modules/fileManager.ts @@ -1,8 +1,8 @@ -import { app, dialog, shell, ipcMain } from 'electron'; +import axios from 'axios'; +import { app, dialog, ipcMain, shell } from 'electron'; import Store from 'electron-store'; import * as fs from 'fs'; import * as path from 'path'; -import axios from 'axios'; /** * 初始化文件管理相关的IPC监听 @@ -29,11 +29,14 @@ export function initializeFileManager() { /** * 下载音乐功能 */ -async function downloadMusic(event: Electron.IpcMainEvent, { url, filename }: { url: string; filename: string }) { +async function downloadMusic( + event: Electron.IpcMainEvent, + { url, filename }: { url: string; filename: string } +) { try { const store = new Store(); - const downloadPath = store.get('set.downloadPath') as string || app.getPath('downloads'); - + const downloadPath = (store.get('set.downloadPath') as string) || app.getPath('downloads'); + // 直接使用配置的下载路径 const filePath = path.join(downloadPath, `${filename}.mp3`); @@ -66,4 +69,4 @@ async function downloadMusic(event: Electron.IpcMainEvent, { url, filename }: { } catch (error: any) { event.reply('music-download-complete', { success: false, error: error.message }); } -} \ No newline at end of file +} diff --git a/src/main/modules/tray.ts b/src/main/modules/tray.ts index e847874..479ca37 100644 --- a/src/main/modules/tray.ts +++ b/src/main/modules/tray.ts @@ -1,4 +1,4 @@ -import { app, Menu, nativeImage, Tray, BrowserWindow } from 'electron'; +import { app, BrowserWindow, Menu, nativeImage, Tray } from 'electron'; import { join } from 'path'; let tray: Tray | null = null; @@ -7,7 +7,9 @@ let tray: Tray | null = null; * 初始化系统托盘 */ export function initializeTray(iconPath: string, mainWindow: BrowserWindow) { - const trayIcon = nativeImage.createFromPath(join(iconPath, 'icon_16x16.png')).resize({ width: 16, height: 16 }); + const trayIcon = nativeImage + .createFromPath(join(iconPath, 'icon_16x16.png')) + .resize({ width: 16, height: 16 }); tray = new Tray(trayIcon); // 创建一个上下文菜单 @@ -16,15 +18,15 @@ export function initializeTray(iconPath: string, mainWindow: BrowserWindow) { label: '显示', click: () => { mainWindow.show(); - }, + } }, { label: '退出', click: () => { mainWindow.destroy(); app.quit(); - }, - }, + } + } ]); // 设置系统托盘图标的上下文菜单 @@ -40,4 +42,4 @@ export function initializeTray(iconPath: string, mainWindow: BrowserWindow) { }); return tray; -} \ No newline at end of file +} diff --git a/src/main/modules/window.ts b/src/main/modules/window.ts index 8b0241e..f9a1aa9 100644 --- a/src/main/modules/window.ts +++ b/src/main/modules/window.ts @@ -1,7 +1,7 @@ -import { BrowserWindow, shell, ipcMain, app, session } from 'electron'; import { is } from '@electron-toolkit/utils'; -import { join } from 'path'; +import { app, BrowserWindow, ipcMain, session, shell } from 'electron'; import Store from 'electron-store'; +import { join } from 'path'; const store = new Store(); @@ -116,4 +116,4 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow { } return mainWindow; -} \ No newline at end of file +} diff --git a/src/main/server.ts b/src/main/server.ts index dc9d9e5..d730de0 100644 --- a/src/main/server.ts +++ b/src/main/server.ts @@ -1,6 +1,7 @@ import { ipcMain } from 'electron'; import Store from 'electron-store'; import fs from 'fs'; +import server from 'netease-cloud-music-api-alger/server'; import os from 'os'; import path from 'path'; @@ -16,9 +17,6 @@ ipcMain.handle('unblock-music', async (_, id, data) => { return unblockMusic(id, data); }); -import server from 'netease-cloud-music-api-alger/server'; - - async function startMusicApi(): Promise { console.log('MUSIC API STARTED'); diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index 5d3ed40..c48875f 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -14,6 +14,6 @@ declare global { restart: () => void; unblockMusic: (id: number, data: any) => Promise; }; - $message:any + $message: any; } } diff --git a/src/renderer/App.vue b/src/renderer/App.vue index cb72b56..9da78ec 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -13,10 +13,10 @@