Skip to content

Commit

Permalink
✨ feat: 新增自定义字体 #156 & 网络代理 #159
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Apr 25, 2024
1 parent 8f5008d commit c6a1ca4
Show file tree
Hide file tree
Showing 181 changed files with 6,421 additions and 5,199 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- 📱 支持手机号登录
- 📅 自动进行每日签到及云贝签到
- 🎨 封面主题色自适应
- 🌚 Light / Dark 模式自动切换
- 📁 本地歌曲管理及分类(建议先使用 [音乐标签](https://www.cnblogs.com/vinlxc/p/11347744.html) 进行匹配后再使用)
- 🎵 **支持播放部分无版权歌曲(可能会与原曲不匹配,客户端独占功能)**
- ⬇️ 下载歌曲(最高支持 Hi-Res)
Expand Down
10 changes: 9 additions & 1 deletion electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ class MainProcess {
else {
this.mainWindow.loadURL(`http://127.0.0.1:${import.meta.env.MAIN_VITE_MAIN_PORT ?? 7899}`);
}

// 配置网络代理
const proxyRules = this.store.get("proxy");
if (proxyRules) {
this.mainWindow.webContents.session.setProxy({ proxyRules }, (result) => {
console.info("网络代理配置:", result);
});
}
}

// 主应用程序事件
Expand All @@ -161,7 +169,7 @@ class MainProcess {
// 创建主窗口
this.createWindow();
// 引入主 Ipc
mainIpcMain(this.mainWindow);
mainIpcMain(this.mainWindow, this.store);
// 系统托盘
createSystemTray(this.mainWindow);
// 注册快捷键
Expand Down
33 changes: 32 additions & 1 deletion electron/main/mainIpcMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { configureAutoUpdater } from "@main/utils/checkUpdates";
import { readDirAsync } from "@main/utils/readDirAsync";
import { parseFile } from "music-metadata";
import { download } from "electron-dl";
import { getFonts } from "font-list";
import getNeteaseMusicUrl from "@main/utils/getNeteaseMusicUrl";
import axios from "axios";
import fs from "fs/promises";

/**
* 监听主进程的 IPC 事件
* @param {BrowserWindow} win - 要监听 IPC 事件的程序窗口
* @param {Store} store - 存储对象
*/

const mainIpcMain = (win) => {
const mainIpcMain = (win, store) => {
// 窗口操作部分
ipcMain.on("window-min", (ev) => {
// 阻止最小化
Expand Down Expand Up @@ -243,6 +245,35 @@ const mainIpcMain = (win) => {
return false;
}
});

// 读取系统全部字体
ipcMain.handle("getAllFonts", async () => {
try {
const fonts = await getFonts();
return fonts;
} catch (error) {
console.error("获取系统字体时出错:", error);
return [];
}
});

// 配置网络代理
ipcMain.on("set-proxy", (_, config) => {
console.log(config);
const proxyRules = `${config.protocol}://${config.server}:${config.port}`;
store.set("proxy", proxyRules);
win.webContents.session.setProxy({ proxyRules }, () => {
console.info("网络代理配置完成");
});
});

// 取消代理
ipcMain.on("remove-proxy", () => {
store.set("proxy", "");
win.webContents.session.setProxy({ proxyRules: "" }, () => {
console.info("取消网络代理配置");
});
});
};

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "splayer",
"version": "2.0.6",
"version": "2.0.7",
"description": "A minimalist music player",
"main": "./out/main/index.js",
"author": "imsyy",
Expand Down Expand Up @@ -38,6 +38,7 @@
"electron-updater": "^6.1.8",
"express": "^4.19.2",
"express-http-proxy": "^2.0.0",
"font-list": "^1.5.1",
"howler": "^2.2.4",
"js-cookie": "^3.0.5",
"localforage": "^1.10.0",
Expand Down
Loading

0 comments on commit c6a1ca4

Please sign in to comment.