-
Notifications
You must be signed in to change notification settings - Fork 96
/
main.ts
228 lines (177 loc) · 8.28 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import {ActionType, ScanService, createIpcMainApiService} from "electron-rpc-api";
import {BrowserWindow} from "electron";
import {PasswordBasedPreset} from "fs-json-store-encryption-adapter";
import {UnionOf, ofType, unionize} from "@vladimiry/unionize";
import * as DbModel from "src/shared/model/database";
import {
AccountConfigCreatePatch,
AccountConfigUpdatePatch,
LoginFieldContainer,
NewPasswordFieldContainer,
PasswordFieldContainer,
} from "src/shared/model/container";
import {BaseConfig, Config, Settings} from "src/shared/model/options";
import {Controller, FuzzyLocale} from "src/electron-main/spell-check/model";
import {DbPatch} from "./common";
import {ElectronContextLocations} from "src/shared/model/electron";
import {FsDbAccount} from "src/shared/model/database";
import {PACKAGE_NAME} from "src/shared/constants";
export type IpcMainServiceScan = ScanService<typeof IPC_MAIN_API>;
export type IpcMainApiEndpoints = IpcMainServiceScan["ApiClient"];
export const ENDPOINTS_DEFINITION = {
getSpellCheckMetadata: ActionType.Promise<void, { locale: ReturnType<Controller["getCurrentLocale"]> }>(),
changeSpellCheckLocale: ActionType.Promise<{ locale: FuzzyLocale }>(),
spellCheck: ActionType.Promise<{ words: string[] }, { misspelledWords: string[] }>(),
addAccount: ActionType.Promise<AccountConfigCreatePatch, Settings>(),
updateAccount: ActionType.Promise<AccountConfigUpdatePatch, Settings>(),
changeAccountOrder: ActionType.Promise<LoginFieldContainer & { index: number }, Settings>(),
removeAccount: ActionType.Promise<LoginFieldContainer, Settings>(),
changeMasterPassword: ActionType.Promise<PasswordFieldContainer & NewPasswordFieldContainer, Settings>(),
dbPatch: ActionType.Promise<DbModel.DbAccountPk
& { forceFlush?: boolean }
& { patch: DbPatch }
& { metadata: Skip<FsDbAccount<"protonmail">["metadata"], "type"> },
DbModel.FsDbAccount["metadata"]>(),
dbGetAccountMetadata: ActionType.Promise<DbModel.DbAccountPk, DbModel.FsDbAccount["metadata"] | null>(),
dbGetAccountDataView: ActionType.Promise<DbModel.DbAccountPk,
{
folders: {
system: DbModel.View.Folder[];
custom: DbModel.View.Folder[];
};
} | undefined>(),
dbGetAccountMail: ActionType.Promise<DbModel.DbAccountPk & { pk: DbModel.Mail["pk"] }, DbModel.Mail>(),
dbExport: ActionType.Observable<DbModel.DbAccountPk & { mailPks?: Array<DbModel.Mail["pk"]> },
{ count: number; } | { progress: number; file: string; }>(),
dbSearchRootConversationNodes:
ActionType.Promise<DbModel.DbAccountPk
& { folderPks?: Array<DbModel.Folder["pk"]> }
& ({ query: string } | { mailPks: Array<DbModel.Folder["pk"]> }),
DbModel.View.RootConversationNode[]>(),
dbFullTextSearch: ActionType.Promise<DbModel.DbAccountPk & { query: string; folderPks?: Array<DbModel.Folder["pk"]>; },
{
uid: string;
mailsBundleItems: Array<{ mail: DbModel.View.Mail & { score: number; }; conversationSize: number; }>;
} & Pick<ReturnType<DbModel.MailsIndex["search"]>, "expandedTerms">>(),
dbIndexerOn: ActionType.Promise<UnionOf<typeof IPC_MAIN_API_DB_INDEXER_ON_ACTIONS>>(),
dbIndexerNotification: ActionType.Observable<void, UnionOf<typeof IPC_MAIN_API_DB_INDEXER_NOTIFICATION_ACTIONS>>(),
init: ActionType.Promise<void, InitResponse>(),
logout: ActionType.Promise(),
openAboutWindow: ActionType.Promise(),
openExternal: ActionType.Promise<{ url: string }>(),
openSettingsFolder: ActionType.Promise(),
patchBaseConfig: ActionType.Promise<BaseConfig, Config>(),
quit: ActionType.Promise(),
readConfig: ActionType.Promise<void, Config>(),
readSettings: ActionType.Promise<Partial<PasswordFieldContainer> & { savePassword?: boolean; }, Settings>(),
reEncryptSettings: ActionType.Promise<PasswordFieldContainer & { encryptionPreset: PasswordBasedPreset }, Settings>(),
settingsExists: ActionType.Promise<void, boolean>(),
loadDatabase: ActionType.Promise<Pick<Settings, "accounts">>(),
activateBrowserWindow: ActionType.Promise<BrowserWindow | void>(),
toggleBrowserWindow: ActionType.Promise<{ forcedState: boolean } | void>(),
toggleCompactLayout: ActionType.Promise<void, Config>(),
updateOverlayIcon: ActionType.Promise<{
hasLoggedOut: boolean;
unread: number;
trayIconColor?: string;
unreadBgColor?: string;
unreadTextColor?: string;
}>(),
hotkey: ActionType.Promise<{ type: "copy" | "paste" | "selectAll" }>(),
findInPageDisplay: ActionType.Promise<{ visible: boolean; }>(),
findInPage: ActionType.Promise<{ query: string; options?: Electron.FindInPageOptions; },
Pick<Electron.FoundInPageResult, "requestId"> | null>(),
findInPageStop: ActionType.Promise(),
findInPageNotification: ActionType.Observable<void, Electron.FoundInPageResult | { requestId: null }>(),
selectAccount: ActionType.Promise<{ databaseView?: boolean; reset?: boolean }>(),
updateCheck: ActionType.Promise<void, Array<{ title: string; url?: string; date: string; }>>(),
toggleControls: ActionType.Promise<Pick<Required<Config>, "hideControls"> | void, void>(),
toggleLocalDbMailsListViewMode: ActionType.Promise<void, Config>(),
notification: ActionType.Observable<void, UnionOf<typeof IPC_MAIN_API_NOTIFICATION_ACTIONS>>(),
};
export interface InitResponse {
electronLocations: ElectronContextLocations;
hasSavedPassword?: boolean;
snapPasswordManagerServiceHint?: boolean;
keytarSupport: boolean;
checkUpdateAndNotify: boolean;
}
export const IPC_MAIN_API = createIpcMainApiService({
channel: `${PACKAGE_NAME}:ipcMain-api`,
apiDefinition: ENDPOINTS_DEFINITION,
});
export const IPC_MAIN_API_DB_INDEXER_ON_ACTIONS = unionize({
Bootstrapped: ofType<{}>(),
ProgressState: ofType<{
key: DbModel.DbAccountPk;
status: {
indexing?: boolean;
searching?: boolean;
};
} | {
status: {
indexing?: boolean;
};
}>(),
IndexingResult: ofType<{
uid: string;
}>(),
SearchResult: ofType<{
data: ReturnType<DbModel.MailsIndex["search"]>;
uid: string;
}>(),
},
{
tag: "type",
value: "payload",
tagPrefix: "ipc_main_api_db_indexer_on:",
},
);
export const IPC_MAIN_API_DB_INDEXER_NOTIFICATION_ACTIONS = unionize({
Bootstrap: ofType<{}>(),
// TODO consider splitting huge data portion to chunks, see "ramda.splitEvery"
Index: ofType<{
key: DbModel.DbAccountPk;
remove: Array<Pick<DbModel.IndexableMail, "pk">>;
add: DbModel.IndexableMail[];
uid: string;
}>(),
Search: ofType<{
key: DbModel.DbAccountPk;
query: string;
uid: string;
}>(),
},
{
tag: "type",
value: "payload",
tagPrefix: "ipc_main_api_db_indexer_notification_actions:",
},
);
// WARN: do not put sensitive data or any data to the main process notification stream, only status-like signals
export const IPC_MAIN_API_NOTIFICATION_ACTIONS = unionize({
Bootstrap: ofType<{}>(),
ActivateBrowserWindow: ofType<{}>(),
TargetUrl: ofType<{ url: string }>(),
DbPatchAccount: ofType<{
key: DbModel.DbAccountPk;
entitiesModified: boolean;
metadataModified: boolean;
stat: { mails: number, folders: number; contacts: number; unread: number; };
}>(),
DbIndexerProgressState: ofType<Extract<UnionOf<typeof IPC_MAIN_API_DB_INDEXER_ON_ACTIONS>, { type: "ProgressState" }>["payload"]>(),
Locale: ofType<{ locale: ReturnType<Controller["getCurrentLocale"]> }>(),
ConfigUpdated: ofType<Config>(),
OpenOptions: ofType<{}>(),
LogOut: ofType<{}>(),
SignedInStateChange: ofType<{ signedIn: boolean }>(),
ErrorMessage: ofType<{ message: string }>(),
InfoMessage: ofType<{ message: string }>(),
TrayIconDataURL: ofType<string>(),
},
{
tag: "type",
value: "payload",
tagPrefix: "ipc_main_api_notification:",
},
);