Skip to content

Commit

Permalink
🐞 fix: 修复启动失败
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Nov 5, 2024
1 parent 201fd8d commit eb39b85
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
31 changes: 18 additions & 13 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { isDev, isMac, appName } from "./utils";
import { registerAllShortcuts, unregisterShortcuts } from "./shortcut";
import { initTray, MainTray } from "./tray";
import { initThumbar, Thumbar } from "./thumbar";
import { type StoreType, initStore } from "./store";
import Store from "electron-store";
import initAppServer from "../server";
import initIpcMain from "./ipcMain";
import log from "./logger";
import store from "./store";
// icon
import icon from "../../public/icons/favicon.png?asset";

Expand All @@ -29,6 +30,8 @@ class MainProcess {
mainWindow: BrowserWindow | null = null;
lyricWindow: BrowserWindow | null = null;
loadingWindow: BrowserWindow | null = null;
// store
store: Store<StoreType> | null = null;
// 托盘
mainTray: MainTray | null = null;
// 工具栏
Expand All @@ -46,10 +49,12 @@ class MainProcess {
process.exit(0);
} else this.showWindow();
// 准备就绪
app.whenReady().then(async () => {
app.on("ready", async () => {
log.info("🚀 Application Process Startup");
// 设置应用程序名称
electronApp.setAppUserModelId(app.getName());
// 初始化 store
this.store = initStore();
// 启动主服务进程
await initAppServer();
// 启动进程
Expand All @@ -68,7 +73,7 @@ class MainProcess {
this.loadingWindow,
this.mainTray,
this.thumbar,
store,
this.store,
);
// 注册快捷键
registerAllShortcuts(this.mainWindow!);
Expand Down Expand Up @@ -111,8 +116,8 @@ class MainProcess {
createMainWindow() {
// 窗口配置项
const options: BrowserWindowConstructorOptions = {
width: store.get("window").width,
height: store.get("window").height,
width: this.store?.get("window").width,
height: this.store?.get("window").height,
minHeight: 800,
minWidth: 1280,
// 菜单栏
Expand All @@ -132,8 +137,8 @@ class MainProcess {
}

// 配置网络代理
if (store.get("proxy")) {
this.mainWindow.webContents.session.setProxy({ proxyRules: store.get("proxy") });
if (this.store?.get("proxy")) {
this.mainWindow.webContents.session.setProxy({ proxyRules: this.store?.get("proxy") });
}

// 窗口打开处理程序
Expand Down Expand Up @@ -162,15 +167,15 @@ class MainProcess {
createLyricsWindow() {
// 初始化窗口
this.lyricWindow = this.createWindow({
width: store.get("lyric").width || 800,
height: store.get("lyric").height || 180,
width: this.store?.get("lyric").width || 800,
height: this.store?.get("lyric").height || 180,
minWidth: 440,
minHeight: 120,
maxWidth: 1600,
maxHeight: 300,
// 窗口位置
x: store.get("lyric").x,
y: store.get("lyric").y,
x: this.store?.get("lyric").x,
y: this.store?.get("lyric").y,
transparent: true,
backgroundColor: "rgba(0, 0, 0, 0)",
alwaysOnTop: true,
Expand Down Expand Up @@ -261,7 +266,7 @@ class MainProcess {
const bounds = this.lyricWindow?.getBounds();
if (bounds) {
const { width, height } = bounds;
store.set("lyric", { ...store.get("lyric"), width, height });
this.store?.set("lyric", { ...this.store?.get("lyric"), width, height });
}
});

Expand All @@ -279,7 +284,7 @@ class MainProcess {
saveBounds() {
if (this.mainWindow?.isFullScreen()) return;
const bounds = this.mainWindow?.getBounds();
if (bounds) store.set("window", bounds);
if (bounds) this.store?.set("window", bounds);
}
// 显示窗口
showWindow() {
Expand Down
38 changes: 19 additions & 19 deletions electron/main/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export interface StoreType {
}

// 初始化仓库
const store = new Store<StoreType>({
defaults: {
window: {
width: 1280,
height: 800,
export const initStore = () => {
return new Store<StoreType>({
defaults: {
window: {
width: 1280,
height: 800,
},
lyric: {
fontSize: 30,
mainColor: "#fff",
shadowColor: "rgba(0, 0, 0, 0.5)",
x: screen.getPrimaryDisplay().workAreaSize.width / 2 - 400,
y: screen.getPrimaryDisplay().workAreaSize.height - 90,
width: 800,
height: 180,
},
proxy: "",
},
lyric: {
fontSize: 30,
mainColor: "#fff",
shadowColor: "rgba(0, 0, 0, 0.5)",
x: screen.getPrimaryDisplay().workAreaSize.width / 2 - 400,
y: screen.getPrimaryDisplay().workAreaSize.height - 90,
width: 800,
height: 180,
},
proxy: "",
},
});

export default store;
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@pixi/filter-color-matrix": "^7.4.2",
"@pixi/sprite": "^7.4.2",
"@vueuse/core": "^10.11.1",
"NeteaseCloudMusicApi": "^4.23.3",
"NeteaseCloudMusicApi": "^4.24.0",
"axios": "^1.7.7",
"change-case": "^5.4.4",
"dayjs": "^1.11.13",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/Layout/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
key: "cloud",
link: "cloud",
label: "我的云盘",
show: isElectron && dataStore.loginType !== "uid",
show: isLogin() === 1,
icon: renderIcon("Cloud"),
},
{
Expand Down

0 comments on commit eb39b85

Please sign in to comment.