Browse Source

修改了一些东西

feat/icon
谢亚昕 3 weeks ago
parent
commit
3c434df31c
  1. 19
      config/index.ts
  2. 5
      electron.vite.config.ts
  3. 20
      package.json
  4. 7
      src/common/event/update/common.ts
  5. 10
      src/common/event/update/main.ts
  6. 14
      src/common/event/update/renderer.ts
  7. 12
      src/main/commands/SettingCommand.ts
  8. 2
      src/main/modules/commands/index.ts
  9. 2
      src/main/modules/tabs/Tab.ts
  10. 62
      src/main/modules/updater/hot/gen.ts
  11. 8
      src/main/modules/updater/index.ts
  12. 6
      src/main/modules/window-manager/index.ts
  13. 2
      src/main/modules/window-manager/windowsMap.ts
  14. 2
      src/main/utils/index.ts
  15. 8
      src/preload/index.d.ts
  16. 2
      src/preload/index.ts
  17. 2
      src/renderer/src/bridge/PopupMenu.ts
  18. 12
      src/renderer/src/components/CodeEditor/code-editor.vue
  19. 1
      src/renderer/src/global.d.ts
  20. 21
      src/types/global.d.ts
  21. 4
      src/types/popup-menu.ts
  22. 6
      tsconfig.node.json
  23. 4
      tsconfig.web.json

19
config/index.ts

@ -1,20 +1,17 @@
interface IConfig {
app_title: string
default_config: {
language: "zh" | "en" // i18n
"common.theme": "light" | "dark" | "auto" // 主题
language: "zh" | "en"
"common.theme": "light" | "dark" | "auto"
"desktop:wallpaper": string
"update.repo"?: string // 更新地址
"update.owner"?: string // 更新通道
"update.repo"?: string
"update.owner"?: string
"update.allowDowngrade": boolean
"update.allowPrerelease": boolean
"editor.bg": string // 更新通道
"editor.logoType": "logo" | "bg" // 更新通道
"editor.fontFamily": string // 更新通道
// "snippet.storagePath": string // 代码片段保存位置
// "bookmark.storagePath": string // 书签保存位置
// backup_rule: string // 备份规则
storagePath: string // 存储地址
"editor.bg": string
"editor.logoType": "logo" | "bg"
"editor.fontFamily": string
storagePath: string
}
}
export default {

5
electron.vite.config.ts

@ -18,7 +18,8 @@ export default defineConfig({
alias: {
config: resolve("config"),
main: resolve("src/main"),
res: resolve("resources"),
"common": resolve("src/common"),
"@res": resolve("resources"),
},
},
plugins: [externalizeDepsPlugin()],
@ -31,6 +32,7 @@ export default defineConfig({
resolve: {
alias: {
config: resolve("config"),
"common": resolve("src/common"),
"@": resolve("src/renderer/src"),
"@res": resolve("resources"),
},
@ -39,6 +41,7 @@ export default defineConfig({
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/style/global" as *;\n`,
api: "modern-compiler"
},
},
},

20
package.json

@ -27,19 +27,10 @@
"dependencies": {
"@electron-toolkit/preload": "^3.0.1",
"@electron-toolkit/utils": "^3.0.0",
"@types/debug": "^4.1.12",
"@unocss/reset": "^0.64.1",
"@vueuse/core": "^12.7.0",
"electron-updater": "^6.3.9",
"inversify": "^6.2.2",
"lowdb": "^7.0.1",
"reflect-metadata": "^0.2.2",
"sass": "^1.85.0",
"unplugin-auto-import": "^19.1.0",
"unplugin-vue-components": "^28.4.0",
"unplugin-vue-macros": "^2.14.2",
"unplugin-vue-router": "^0.11.2",
"vue-router": "^4.5.0"
"reflect-metadata": "^0.2.2"
},
"devDependencies": {
"@electron-toolkit/eslint-config": "^1.0.2",
@ -47,12 +38,15 @@
"@electron-toolkit/tsconfig": "^1.0.1",
"@intlify/unplugin-vue-i18n": "^6.0.3",
"@rushstack/eslint-patch": "^1.10.5",
"@types/debug": "^4.1.12",
"@types/node": "^20.17.19",
"@unocss/preset-rem-to-px": "^0.64.1",
"@unocss/reset": "^0.64.1",
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vueuse/core": "^12.7.0",
"debug": "^4.4.0",
"electron": "^31.7.7",
"electron-builder": "^24.13.3",
@ -64,14 +58,20 @@
"monaco-editor": "^0.52.2",
"prettier": "^3.5.1",
"rotating-file-stream": "^3.2.6",
"sass": "^1.85.0",
"simplebar-vue": "^2.4.0",
"typescript": "^5.7.3",
"unocss": "^0.64.1",
"unplugin-auto-import": "^19.1.0",
"unplugin-vue-components": "^28.4.0",
"unplugin-vue-macros": "^2.14.2",
"unplugin-vue-router": "^0.11.2",
"vite": "^5.4.14",
"vite-plugin-monaco-editor": "^1.1.0",
"vite-plugin-vue-layouts": "^0.11.0",
"vue": "^3.5.13",
"vue-i18n": "^11.1.1",
"vue-router": "^4.5.0",
"vue-tsc": "^2.1.10"
}
}

7
src/common/event/update/common.ts

@ -0,0 +1,7 @@
const keys = ["progress"] as const
type AllKeys = (typeof keys)[number]
export type{
AllKeys
}

10
src/common/event/update/main.ts

@ -0,0 +1,10 @@
import { broadcast } from "main/utils"
import { AllKeys } from "./common"
function emitProgress(...argu) {
broadcast<AllKeys>("progress", ...argu)
}
export {
emitProgress
}

14
src/common/event/update/renderer.ts

@ -0,0 +1,14 @@
import type { AllKeys } from "./common"
const curProgress = ref(0)
api.on<AllKeys>("progress", () => {
curProgress.value = 10
})
function useUpdate() {
return {
curProgress,
}
}
export { useUpdate }

12
src/main/commands/SettingCommand.ts

@ -0,0 +1,12 @@
// import { inject } from "inversify"
// import Setting from "main/modules/setting"
// class SettingCommand {
// constructor(@inject(Setting) private _Setting: Setting) {
// console.log(this._Setting)
// }
// getAll() {
// return this._Setting.config()
// }
// }

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

@ -1,4 +1,4 @@
import { IMenuItemOption, IPopupMenuOption } from "#"
import { IMenuItemOption, IPopupMenuOption } from "#/popup-menu"
import { ipcMain, Menu, MenuItem } from "electron"
import { inject } from "inversify"
import IOC from "main/_ioc"

2
src/main/modules/tabs/Tab.ts

@ -3,7 +3,7 @@ import { join } from "node:path"
import BaseClass from "main/base/base"
import _debug from "debug"
// import { Layout } from "./Constant"
import FuckHTML from "res/fuck.html?asset"
import FuckHTML from "@res/fuck.html?asset"
import { fileURLToPath, pathToFileURL } from "node:url"
const debug = _debug("app:tab")

62
src/main/modules/updater/hot/gen.ts

@ -0,0 +1,62 @@
import { spawn } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
import os from "node:os"
import { app } from "electron"
function getUpdateScriptTemplate() {
return process.platform === "win32"
? `
@echo off
timeout /t 2
taskkill /IM "{{EXE_NAME}}" /F
xcopy /Y /E "{{UPDATE_DIR}}\\*" "{{APP_PATH}}"
start "" "{{EXE_PATH}}"
`
: `
#!/bin/bash
sleep 2
pkill -f "{{EXE_NAME}}"
cp -Rf "{{UPDATE_DIR}}/*" "{{APP_PATH}}/"
open "{{EXE_PATH}}"
`
}
function generateUpdateScript() {
const scriptContent = getUpdateScriptTemplate()
.replace(/{{APP_PATH}}/g, process.platform === "win32" ? "%APP_PATH%" : "$APP_PATH")
.replace(/{{UPDATE_DIR}}/g, process.platform === "win32" ? "%UPDATE_DIR%" : "$UPDATE_DIR")
.replace(/{{EXE_PATH}}/g, process.platform === "win32" ? "%EXE_PATH%" : "$EXE_PATH")
.replace(/{{EXE_NAME}}/g, process.platform === "win32" ? "%EXE_NAME%" : "$EXE_NAME")
const scriptPath = path.join(os.tmpdir(), `update.${process.platform === "win32" ? "bat" : "sh"}`)
fs.writeFileSync(scriptPath, scriptContent)
return scriptPath
}
app.on("will-quit", event => {
event.preventDefault()
// 假设已下载更新到临时目录
const updateTempDir = path.join(os.tmpdir(), "app-update")
const appPath = app.getAppPath()
const appExePath = process.execPath
// 生成动态脚本
const scriptPath = generateUpdateScript()
fs.chmodSync(scriptPath, 0o755)
// 执行脚本
const child = spawn(scriptPath, [], {
detached: true,
shell: true,
env: {
APP_PATH: appPath,
UPDATE_DIR: updateTempDir,
EXE_PATH: appExePath,
},
})
child.unref()
app.exit()
})

8
src/main/modules/updater/index.ts

@ -12,6 +12,7 @@ const { autoUpdater } = pkg
@injectable()
export class Updater extends BaseClass {
public events = new EventEmitter()
private timer: ReturnType<typeof setInterval> | null = null
constructor(
// @inject(Setting) private _Setting: Setting
@ -60,7 +61,8 @@ export class Updater extends BaseClass {
init() {
// 定期检查更新
this.checkForUpdates()
setInterval(
this.timer && clearInterval(this.timer)
this.timer = setInterval(
() => {
this.checkForUpdates()
},
@ -70,6 +72,10 @@ export class Updater extends BaseClass {
destroy() {
// 清理工作
if(this.timer){
clearInterval(this.timer)
this.timer = null
}
}
private async checkForUpdates() {

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

@ -246,7 +246,11 @@ export default class WindowManager extends BaseClass {
}
showCurrentWindow() {
debug(`current open window: ${this.#windows.map(v => v.$$opts!.name).join(",")}`)
if(this.#windows.length) {
debug(`current open window: ${this.#windows.map(v => v.$$opts!.name).join(",")}`)
} else {
debug(`all closed`)
}
}
#onClose(name: string) {

2
src/main/modules/window-manager/windowsMap.ts

@ -1,7 +1,7 @@
import config from "config"
import { BrowserWindowConstructorOptions } from "electron"
import { getFileUrl } from "main/utils"
import icon from "res/icon.png?asset"
import icon from "@res/icon.png?asset"
import { join } from "path"
export type Param = Partial<IConfig> & Required<Pick<IConfig, "name">>

2
src/main/utils/index.ts

@ -16,7 +16,7 @@ export function isPromise(value: () => any) {
return value && Object.prototype.toString.call(value) === "[object Promise]"
}
export const broadcast = (event: string, ...args: any[]) => {
export const broadcast = <T extends string>(event: T, ...args: any[]) => {
webContents.getAllWebContents().forEach(browser => browser.send(event, ...args))
}

8
src/preload/index.d.ts

@ -1,8 +0,0 @@
import { ElectronAPI } from "@electron-toolkit/preload"
declare global {
interface Window {
electron: ElectronAPI
api: unknown
}
}

2
src/preload/index.ts

@ -1,7 +1,7 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron"
import { electronAPI } from "@electron-toolkit/preload"
import { call, callLong, callSync } from "./call"
import { IPopupMenuOption } from "#"
import { IPopupMenuOption } from "#/popup-menu"
document.addEventListener("DOMContentLoaded", () => {
const initStyle = document.createElement("style")
initStyle.textContent = `

2
src/renderer/src/bridge/PopupMenu.ts

@ -4,7 +4,7 @@
* @homepage: https://oldj.net
*/
import { IMenuItemOption } from "#"
import { IMenuItemOption } from "#/popup-menu"
import type { PopupOptions } from "electron"
let _idx: number = 0

12
src/renderer/src/components/CodeEditor/code-editor.vue

@ -98,7 +98,6 @@ function updateModel(name: string, content: string) {
const code = model.getValue()
emit("update:modelValue", code)
emit("change", code)
console.log(343)
}
})
if (oldModel) {
@ -186,7 +185,13 @@ onMounted(() => {
}
},
)
})
})
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
console.log(newModule);
})
}
onBeforeUnmount(() => {
if (editorRef.value) {
editorRef.value.removeEventListener("resize", resizeLayout)
@ -196,9 +201,8 @@ onBeforeUnmount(() => {
if (oldModel) {
oldModel.dispose()
}
editor?.dispose()
editor.dispose()
editor = null
console.log("editor dispose")
}
})
const style = computed(() => {

1
src/renderer/src/global.d.ts

@ -1 +0,0 @@
declare const api

21
src/types/global.d.ts

@ -0,0 +1,21 @@
type Api = {
call: (command: string, ...args: any[]) => Promise<any>
callLong: (command: string, ...args: any[]) => Promise<any>
callSync: (command: string, ...args: any[]) => any
send: (command: string, ...argu: any[]) => any
sendSync: (command: string, ...argu: any[]) => any
on: <T extends string>(command: T, cb: (event: IpcRendererEvent, ...args: any[]) => void) => () => void
once: (command: string, cb: (event: IpcRendererEvent, ...args: any[]) => void) => () => void
off: (command: string, cb: (event: IpcRendererEvent, ...args: any[]) => void) => void
offAll: (command: string) => void
popupMenu: (options: IPopupMenuOption) => void
}
declare const electron: typeof import("@electron-toolkit/preload").electronAPI
declare const api: Api
interface Window {
electron: typeof import("@electron-toolkit/preload").electronAPI
api: Api
}

4
src/types/index.d.ts → src/types/popup-menu.ts

@ -1,4 +1,6 @@
interface IMenuItemOption extends Electron.MenuItemConstructorOptions {
import type { PopupOptions } from "electron"
export interface IMenuItemOption extends Electron.MenuItemConstructorOptions {
// 参见:https://www.electronjs.org/docs/api/menu-item
_click_evt?: string
}

6
tsconfig.node.json

@ -1,6 +1,7 @@
{
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "config/**/*", "src/types/**/*", "packages/locales/main.ts"],
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "config/**/*", "src/types/**/*", "packages/locales/main.ts",
"src/common/**/*.main.ts", "src/common/**/main.ts", "src/common/**/*.common.ts", "src/common/**/common.ts"],
"compilerOptions": {
"composite": true,
"emitDecoratorMetadata": true,
@ -13,7 +14,8 @@
"config": ["config/index.ts"],
"config/*": ["config/*"],
"main/*": ["src/main/*"],
"res/*": ["resources/*"],
"common/*": ["src/common/*"],
"@res/*": ["resources/*"],
"locales/*": ["packages/locales/*"],
}
}

4
tsconfig.web.json

@ -10,6 +10,9 @@
"src/types/**/*",
"config/**/*",
"./typed-router.d.ts",
"src/common/**/*.renderer.ts",
"src/common/**/renderer.ts",
"src/common/**/*.common.ts", "src/common/**/common.ts",
],
"vueCompilerOptions": {
"plugins": ["unplugin-vue-macros/volar"],
@ -24,6 +27,7 @@
"#/*": ["src/types/*"],
"config": ["config/index.ts"],
"config/*": ["config/*"],
"common/*": ["src/common/*"],
"@/*": [
"src/renderer/src/*"
],

Loading…
Cancel
Save