|
| 1 | +/* eslint-disable @typescript-eslint/no-unsafe-function-type */ |
1 | 2 | /* eslint-disable @typescript-eslint/no-empty-function */ |
2 | 3 | import { ChromeEvent } from '../extension/ChromeEvent'; |
3 | 4 | import { Extension } from '../extension/Extension'; |
@@ -27,6 +28,9 @@ export function createChrome(context: string, extension: Extension): typeof wind |
27 | 28 | extension: createExtensionType(extension, logger), |
28 | 29 | contextMenus: createContextMenusType(extension, logger), |
29 | 30 | commands: createCommandsType(extension, logger), |
| 31 | + notifications: createNotificationsType(extension, logger), |
| 32 | + webRequest: createWebRequestType(extension, logger), |
| 33 | + declarativeNetRequest: createDeclarativeNetRequestType(extension, logger), |
30 | 34 | }; |
31 | 35 |
|
32 | 36 | return chromeObj; |
@@ -90,6 +94,8 @@ function createRuntimeType(extension: Extension, logger: Logger): typeof chrome. |
90 | 94 |
|
91 | 95 | return port; |
92 | 96 | }, |
| 97 | + onConnect: new ChromeEvent<(port: chrome.runtime.Port) => void>(), |
| 98 | + onConnectExternal: new ChromeEvent<(port: chrome.runtime.Port) => void>(), |
93 | 99 | }; |
94 | 100 | } |
95 | 101 |
|
@@ -185,6 +191,7 @@ function createWindowsType(extension: Extension, logger: Logger): typeof chrome. |
185 | 191 |
|
186 | 192 | return Promise.resolve([]); |
187 | 193 | }, |
| 194 | + onBoundsChanged: new ChromeEvent<(window: chrome.windows.Window) => void>(), |
188 | 195 | }; |
189 | 196 | } |
190 | 197 |
|
@@ -273,3 +280,57 @@ function createCommandsType(extension: Extension, logger: Logger): typeof chrome |
273 | 280 | }, |
274 | 281 | }; |
275 | 282 | } |
| 283 | + |
| 284 | +/** |
| 285 | + * @see https://developer.chrome.com/docs/extensions/reference/api/notifications |
| 286 | + */ |
| 287 | +function createNotificationsType(extension: Extension, logger: Logger): typeof chrome.notifications { |
| 288 | + // TODO: implement |
| 289 | + return { |
| 290 | + create: (...args: unknown[]): string | number => { |
| 291 | + console.error('notifications.create not implemented', args); |
| 292 | + |
| 293 | + return -1; |
| 294 | + }, |
| 295 | + onClosed: new ChromeEvent<(notificationId: string) => void>(), |
| 296 | + onButtonClicked: new ChromeEvent<(notificationId: string) => void>(), |
| 297 | + onClicked: new ChromeEvent<(notificationId: string) => void>(), |
| 298 | + }; |
| 299 | +} |
| 300 | + |
| 301 | +/** |
| 302 | + * @see https://developer.chrome.com/docs/extensions/reference/api/webRequest |
| 303 | + */ |
| 304 | +function createWebRequestType(extension: Extension, logger: Logger): typeof chrome.webRequest { |
| 305 | + // TODO: implement |
| 306 | + return { |
| 307 | + onBeforeRequest: new ChromeEvent<(details: chrome.webRequest.WebRequestDetails) => void>(), |
| 308 | + onBeforeSendHeaders: new ChromeEvent<(details: chrome.webRequest.WebRequestDetails) => void>(), |
| 309 | + onHeadersReceived: new ChromeEvent<(details: chrome.webRequest.WebRequestDetails) => void>(), |
| 310 | + onCompleted: new ChromeEvent<(details: chrome.webRequest.WebRequestDetails) => void>(), |
| 311 | + onErrorOccurred: new ChromeEvent<(details: chrome.webRequest.WebRequestDetails) => void>(), |
| 312 | + }; |
| 313 | +} |
| 314 | + |
| 315 | +/** |
| 316 | + * @see https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest |
| 317 | + */ |
| 318 | +function createDeclarativeNetRequestType(extension: Extension, logger: Logger): typeof chrome.declarativeNetRequest { |
| 319 | + // TODO: implement |
| 320 | + return { |
| 321 | + getDynamicRules: async (callback?: (rules: chrome.declarativeNetRequest.Rule[]) => void): Promise<chrome.declarativeNetRequest.Rule[]> => { |
| 322 | + logger.log('declarativeNetRequest.getDynamicRules'); |
| 323 | + |
| 324 | + callback?.([]); |
| 325 | + |
| 326 | + return Promise.resolve([]); |
| 327 | + }, |
| 328 | + updateDynamicRules: async (_options: chrome.declarativeNetRequest.UpdateRuleOptions, callback?: Function): Promise<void> => { |
| 329 | + logger.log('declarativeNetRequest.updateDynamicRules'); |
| 330 | + |
| 331 | + callback?.(); |
| 332 | + |
| 333 | + return Promise.resolve(); |
| 334 | + }, |
| 335 | + }; |
| 336 | +} |
0 commit comments