Browse Source

fix bug

feat/icon
谢亚昕 3 weeks ago
parent
commit
dcdc4aa857
  1. 2
      package.json
  2. 15
      src/main/App.ts
  3. 18
      src/main/commands/BasicCommand.ts
  4. 21
      src/main/modules/commands/index.ts
  5. 12
      src/main/modules/window-manager/index.ts

2
package.json

@ -2,7 +2,7 @@
"name": "zephyr",
"type": "module",
"private": true,
"version": "1.0.0",
"version": "0.0.1",
"description": "An Electron application with Vue and TypeScript",
"main": "./out/main/index.js",
"author": "example.com",

15
src/main/App.ts

@ -70,15 +70,12 @@ class App extends BaseClass {
this._Zephyr.init()
electronApp.setAppUserModelId("top.xieyaxin")
this._WindowManager.showMainWindow()
const mainWindow = this._WindowManager.getMainWindow()
if (mainWindow) {
nativeTheme.themeSource = "light"
mainWindow.setTitleBarOverlay({
height: 29, // the smallest size of the title bar on windows accounting for the border on windows 11
color: "#F8F8F8",
symbolColor: "#000000",
})
}
this._Command.invoke("BasicCommand.setTheme", "light")
this._Command.invoke("BasicCommand.setTitlBar", {
height: 29,
color: "#F8F8F8",
symbolColor: "#000000",
})
})
app.on("will-quit", () => {
this.destroy()

18
src/main/commands/BasicCommand.ts

@ -1,17 +1,23 @@
import { app, dialog } from "electron"
import { app, dialog, nativeTheme, TitleBarOverlayOptions } from "electron"
import { inject } from "inversify"
import Commands from "main/modules/commands"
import Tabs from "main/modules/tabs"
import WindowManager from "main/modules/window-manager"
export default class BasicCommand {
constructor(
@inject(Commands) private _Commands: Commands,
@inject(WindowManager) private _WindowManager: WindowManager,
@inject(Tabs) private _Tabs: Tabs,
) {
//
console.log(this._Commands)
) {}
setTheme(theme: typeof nativeTheme.themeSource) {
nativeTheme.themeSource = theme
}
setTitlBar(options: TitleBarOverlayOptions) {
const mainWindow = this._WindowManager.getMainWindow()
if (mainWindow) {
mainWindow.setTitleBarOverlay(options)
}
}
toggleDevTools() {

21
src/main/modules/commands/index.ts

@ -18,14 +18,27 @@ export default class Commands extends BaseClass {
super()
}
private async handleCommand(command: string, ...argus) {
const splitClass = command.split(".")
const run = await this._IOC.getAsync<any>(splitClass[0])
if (run) {
const result: Promise<any> | any = run[splitClass[1]](...argus)
return result
}
return null
}
public async invoke(command, ...argus) {
const result = await this.handleCommand(command, ...argus)
return result
}
init() {
ipcMain.addListener("command", async (event, key, command: string, ...argus) => {
// console.log(event.sender);
try {
const splitClass = command.split(".")
const run = await this._IOC.getAsync<any>(splitClass[0])
if (run) {
const result: Promise<any> | any = run[splitClass[1]](...argus)
const result = await this.handleCommand(command, ...argus)
if (result) {
if (isPromise(result)) {
result
.then((res: any) => {

12
src/main/modules/window-manager/index.ts

@ -18,6 +18,9 @@ export { WindowManager }
export default class WindowManager extends BaseClass {
constructor() {
super()
this.isMainShowReady = new Promise(resolve => {
this.isMainShowResolve = resolve
})
}
destroy() {
@ -51,6 +54,13 @@ export default class WindowManager extends BaseClass {
showMainWindow() {
this.#showWin(this.mainInfo)
this.isMainShowResolve()
}
private isMainShowResolve
private isMainShowReady
async waitMainShowReady() {
await this.isMainShowReady
}
showWindow(name: string, opts?: Partial<IConfig>) {
@ -246,7 +256,7 @@ export default class WindowManager extends BaseClass {
}
showCurrentWindow() {
if(this.#windows.length) {
if (this.#windows.length) {
debug(`current open window: ${this.#windows.map(v => v.$$opts!.name).join(",")}`)
} else {
debug(`all closed`)

Loading…
Cancel
Save