mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 23:11:00 +08:00
refactor: 调整主进程模块
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils';
|
||||
import { app, ipcMain, nativeImage } from 'electron';
|
||||
import { app, ipcMain, nativeImage, session } from 'electron';
|
||||
import { join } from 'path';
|
||||
|
||||
import type { Language } from '../i18n/main';
|
||||
@@ -9,6 +9,7 @@ import { initializeConfig } from './modules/config';
|
||||
import { initializeFileManager } from './modules/fileManager';
|
||||
import { initializeFonts } from './modules/fonts';
|
||||
import { initializeLoginWindow } from './modules/loginWindow';
|
||||
import { initLxMusicHttp } from './modules/lxMusicHttp';
|
||||
import { initializeOtherApi } from './modules/otherApi';
|
||||
import { initializeRemoteControl } from './modules/remoteControl';
|
||||
import { initializeShortcuts, registerShortcuts } from './modules/shortcuts';
|
||||
@@ -17,7 +18,6 @@ import { setupUpdateHandlers } from './modules/update';
|
||||
import { createMainWindow, initializeWindowManager, setAppQuitting } from './modules/window';
|
||||
import { initWindowSizeManager } from './modules/window-size';
|
||||
import { startMusicApi } from './server';
|
||||
import { initLxMusicHttp } from './modules/lxMusicHttp';
|
||||
|
||||
// 导入所有图标
|
||||
const iconPath = join(__dirname, '../../resources');
|
||||
@@ -121,6 +121,19 @@ if (!isSingleInstance) {
|
||||
// 初始化窗口大小管理器
|
||||
initWindowSizeManager();
|
||||
|
||||
// 设置媒体设备权限 - 允许枚举音频输出设备
|
||||
session.defaultSession.setPermissionRequestHandler((_webContents, permission, callback) => {
|
||||
if (permission === ('media' as any) || permission === ('audioCapture' as any)) {
|
||||
callback(true);
|
||||
return;
|
||||
}
|
||||
callback(true);
|
||||
});
|
||||
|
||||
session.defaultSession.setPermissionCheckHandler(() => {
|
||||
return true;
|
||||
});
|
||||
|
||||
// 重新初始化配置管理以获取完整的配置存储
|
||||
const store = initializeConfig();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import { app, dialog, ipcMain, Notification, protocol, shell } from 'electron';
|
||||
import { app, dialog, ipcMain, nativeImage, Notification, protocol, shell } from 'electron';
|
||||
import Store from 'electron-store';
|
||||
import { fileTypeFromFile } from 'file-type';
|
||||
import { FlacTagMap, writeFlacTags } from 'flac-tagger';
|
||||
@@ -10,7 +10,6 @@ import * as mm from 'music-metadata';
|
||||
import * as NodeID3 from 'node-id3';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import sharp from 'sharp';
|
||||
|
||||
import { getStore } from './config';
|
||||
|
||||
@@ -659,19 +658,28 @@ async function downloadMusic(
|
||||
const originalSizeMB = (originalCoverBuffer.length / (1024 * 1024)).toFixed(2);
|
||||
console.log(`封面图大于2MB (${originalSizeMB} MB),开始压缩...`);
|
||||
try {
|
||||
// 使用 sharp 进行压缩
|
||||
coverImageBuffer = await sharp(originalCoverBuffer)
|
||||
.resize({
|
||||
width: 1600,
|
||||
height: 1600,
|
||||
fit: 'inside',
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.jpeg({
|
||||
quality: 80,
|
||||
mozjpeg: true
|
||||
})
|
||||
.toBuffer();
|
||||
// 使用 Electron nativeImage 进行压缩
|
||||
const image = nativeImage.createFromBuffer(originalCoverBuffer);
|
||||
const size = image.getSize();
|
||||
|
||||
// 计算新尺寸,保持宽高比,最大1600px
|
||||
const maxSize = 1600;
|
||||
let newWidth = size.width;
|
||||
let newHeight = size.height;
|
||||
|
||||
if (size.width > maxSize || size.height > maxSize) {
|
||||
const ratio = Math.min(maxSize / size.width, maxSize / size.height);
|
||||
newWidth = Math.round(size.width * ratio);
|
||||
newHeight = Math.round(size.height * ratio);
|
||||
}
|
||||
|
||||
// 调整大小并转换为 JPEG 格式(质量 80)
|
||||
const resizedImage = image.resize({
|
||||
width: newWidth,
|
||||
height: newHeight,
|
||||
quality: 'good'
|
||||
});
|
||||
coverImageBuffer = resizedImage.toJPEG(80);
|
||||
|
||||
const compressedSizeMB = (coverImageBuffer.length / (1024 * 1024)).toFixed(2);
|
||||
console.log(`封面图压缩完成,新大小: ${compressedSizeMB} MB`);
|
||||
@@ -747,10 +755,8 @@ async function downloadMusic(
|
||||
ARTIST: artistNames,
|
||||
ALBUM: songInfo?.al?.name || songInfo?.song?.album?.name || songInfo?.name || filename,
|
||||
LYRICS: lyricsContent || '',
|
||||
TRACKNUMBER: songInfo?.no ? String(songInfo.no) : undefined,
|
||||
DATE: songInfo?.publishTime
|
||||
? new Date(songInfo.publishTime).getFullYear().toString()
|
||||
: undefined
|
||||
TRACKNUMBER: songInfo?.no ? String(songInfo.no) : '',
|
||||
DATE: songInfo?.publishTime ? new Date(songInfo.publishTime).getFullYear().toString() : ''
|
||||
};
|
||||
|
||||
await writeFlacTags(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import match from '@unblockneteasemusic/server';
|
||||
|
||||
type Platform = 'qq' | 'migu' | 'kugou' | 'kuwo' | 'pyncmd' | 'joox' | 'bilibili';
|
||||
type Platform = 'qq' | 'migu' | 'kugou' | 'kuwo' | 'pyncmd' | 'joox';
|
||||
|
||||
interface SongData {
|
||||
name: string;
|
||||
@@ -30,7 +30,7 @@ interface UnblockResult {
|
||||
}
|
||||
|
||||
// 所有可用平台
|
||||
export const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'kuwo', 'pyncmd', 'bilibili'];
|
||||
export const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'kuwo', 'pyncmd'];
|
||||
|
||||
/**
|
||||
* 确保对象数据结构完整,处理null或undefined的情况
|
||||
|
||||
Reference in New Issue
Block a user