Skip to content

Commit 4fab9af

Browse files
committed
add tray icon (place holder but not designed)
1 parent 09d717d commit 4fab9af

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

electron/main.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { fileURLToPath } from "url"
22
import { join, dirname } from "path"
3-
import { app, BrowserWindow, Menu, Tray } from "electron"
3+
import { app, nativeImage, BrowserWindow, Menu, Tray } from "electron"
4+
// import { Store } from "./utils/store"
45

56
const __filename = fileURLToPath(import.meta.url)
67
const __dirname = dirname(__filename)
78

89
process.env.DIST = join(__dirname, "../dist")
9-
process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST, "../public")
10+
process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST, "../src/public")
11+
12+
// const store = new Store(app.getPath("userData"))
1013

1114
let win: BrowserWindow | null
1215
// Here, you can also use other preload
@@ -42,10 +45,19 @@ function setupMainWindow() {
4245

4346
function setupLogging() {}
4447

48+
function createNativeImage() {
49+
// const path = join(process.env.PUBLIC, "/assets/clock-icon.png")
50+
const path = join(process.env.PUBLIC, "/assets/logo.png")
51+
console.log("--->", path)
52+
const image = nativeImage.createFromPath(path)
53+
image.setTemplateImage(true)
54+
return image
55+
}
56+
4557
function createApp() {
4658
setupMainWindow()
4759
setupLogging()
48-
const tray = new Tray(join(process.env.PUBLIC, "logo.svg"))
60+
const tray = new Tray(createNativeImage())
4961
const contextMenu = Menu.buildFromTemplate([
5062
{ label: "Item1", type: "radio" },
5163
{ label: "Item2", type: "radio" },

electron/utils/store.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export class Store {
2+
private store: Map<string, any>
3+
private storePath: string
4+
5+
constructor(storePath: string) {
6+
this.store = new Map()
7+
this.storePath = storePath
8+
}
9+
10+
set(key: string, value: any) {
11+
this.store.set(key, value)
12+
this.persistent()
13+
}
14+
15+
get(key: string, defaultValue: any) {
16+
return this.store.get(key) || defaultValue
17+
}
18+
19+
// 检测变化才保存
20+
persistent() {
21+
console.log("persistent")
22+
// save to file
23+
}
24+
}

src/constants/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export const UPDATE_URL = `${REPO_URL}#keep-updated`
99
export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?sha=main&per_page=1`
1010
export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`
1111
export const RUNTIME_CONFIG_DOM = "danger-runtime-config"
12-
export const DEFAULT_API_HOST = "https://chatgpt1.nextweb.fun/api/proxy"
1312

1413
export enum Path {
15-
Home = "/chat",
1614
Chat = "/chat",
1715
Settings = "/chat/settings",
1816
NewChat = "/chat/new",

src/public/assets/logo.png

1.15 KB
Loading

0 commit comments

Comments
 (0)