mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-24 08:07:23 +08:00
🌈 style: 优化代码格式化
This commit is contained in:
+9
-9
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<StoreType>({
|
||||
name: 'config',
|
||||
defaults: {
|
||||
set: set
|
||||
set
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,4 +40,4 @@ export function initializeConfig() {
|
||||
});
|
||||
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -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<void> {
|
||||
console.log('MUSIC API STARTED');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user