@@ -4,8 +4,10 @@ import { APP_PROTOCOL } from "@follow/shared/constants"
4
4
import { env } from "@follow/shared/env"
5
5
import { imageRefererMatches , selfRefererMatches } from "@follow/shared/image"
6
6
import { app , BrowserWindow , session } from "electron"
7
+ import type { Cookie } from "electron/main"
7
8
import squirrelStartup from "electron-squirrel-startup"
8
9
10
+ import { DEVICE_ID } from "./constants/system"
9
11
import { isDev , isMacOS } from "./env"
10
12
import { initializeAppStage0 , initializeAppStage1 } from "./init"
11
13
import { updateProxy } from "./lib/proxy"
@@ -14,6 +16,7 @@ import { store } from "./lib/store"
14
16
import { registerAppTray } from "./lib/tray"
15
17
import { setAuthSessionToken , updateNotificationsToken } from "./lib/user"
16
18
import { registerUpdater } from "./updater"
19
+ import { cleanupOldRender } from "./updater/hot-updater"
17
20
import {
18
21
createMainWindow ,
19
22
getMainWindow ,
@@ -23,6 +26,9 @@ import {
23
26
24
27
if ( isDev ) console . info ( "[main] env loaded:" , env )
25
28
29
+ const apiURL = process . env [ "VITE_API_URL" ] || import . meta. env . VITE_API_URL
30
+
31
+ console . info ( "[main] device id:" , DEVICE_ID )
26
32
if ( squirrelStartup ) {
27
33
app . quit ( )
28
34
}
@@ -56,7 +62,7 @@ function bootstrap() {
56
62
// This method will be called when Electron has finished
57
63
// initialization and is ready to create browser windows.
58
64
// Some APIs can only be used after this event occurs.
59
- app . whenReady ( ) . then ( ( ) => {
65
+ app . whenReady ( ) . then ( async ( ) => {
60
66
// Default open or close DevTools by F12 in development
61
67
// and ignore CommandOrControl + R in production.
62
68
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
@@ -69,6 +75,28 @@ function bootstrap() {
69
75
70
76
mainWindow = createMainWindow ( )
71
77
78
+ // restore cookies
79
+ const cookies = store . get ( "cookies" ) as Cookie [ ]
80
+ if ( cookies ) {
81
+ Promise . all (
82
+ cookies . map ( ( cookie ) => {
83
+ const setCookieDetails : Electron . CookiesSetDetails = {
84
+ url : apiURL ,
85
+ name : cookie . name ,
86
+ value : cookie . value ,
87
+ domain : cookie . domain ,
88
+ path : cookie . path ,
89
+ secure : cookie . secure ,
90
+ httpOnly : cookie . httpOnly ,
91
+ expirationDate : cookie . expirationDate ,
92
+ sameSite : cookie . sameSite as "unspecified" | "no_restriction" | "lax" | "strict" ,
93
+ }
94
+
95
+ return mainWindow . webContents . session . cookies . set ( setCookieDetails )
96
+ } ) ,
97
+ )
98
+ }
99
+
72
100
updateProxy ( )
73
101
registerUpdater ( )
74
102
registerAppTray ( )
@@ -135,7 +163,7 @@ function bootstrap() {
135
163
}
136
164
} )
137
165
138
- app . on ( "before-quit" , ( ) => {
166
+ app . on ( "before-quit" , async ( ) => {
139
167
// store window pos when before app quit
140
168
const window = getMainWindow ( )
141
169
if ( ! window || window . isDestroyed ( ) ) return
@@ -147,6 +175,12 @@ function bootstrap() {
147
175
x : bounds . x ,
148
176
y : bounds . y ,
149
177
} )
178
+ await session . defaultSession . cookies . flushStore ( )
179
+
180
+ const cookies = await session . defaultSession . cookies . get ( { } )
181
+ store . set ( "cookies" , cookies )
182
+
183
+ await cleanupOldRender ( )
150
184
} )
151
185
152
186
const handleOpen = async ( url : string ) => {
@@ -158,7 +192,6 @@ function bootstrap() {
158
192
const token = urlObj . searchParams . get ( "token" )
159
193
const userId = urlObj . searchParams . get ( "userId" )
160
194
161
- const apiURL = process . env [ "VITE_API_URL" ] || import . meta. env . VITE_API_URL
162
195
if ( token && apiURL ) {
163
196
setAuthSessionToken ( token )
164
197
mainWindow . webContents . session . cookies . set ( {
0 commit comments