Skip to content

Commit f5c57c5

Browse files
committed
Move afterUninstall into api.ts & improvements
1 parent edf0663 commit f5c57c5

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

packages/electron-chrome-web-store/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Installs Chrome Web Store support in the specified session.
101101
- `denylist`: An array of denied extension IDs to install.
102102
- `beforeInstall`: A function which receives install details and returns a promise. Allows for prompting prior to install.
103103
- `afterInstall`: A function which receives install details. Allows for additional actions after install.
104-
- `afterUninstall`: A function which receives extension ID, extension, and manifest. Allows for additional actions after uninstall.
104+
- `afterUninstall`: A function which receives extension ID. Allows for additional actions after uninstall.
105105
- `overrideExtensionInstallStatus`: A function which receives the current state, extension ID, and manifest. Returns a string indicating the install status of the extension, or returns undefined to fallback to the default install status.
106106

107107
### `installExtension`

packages/electron-chrome-web-store/src/browser/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,17 @@ export function registerWebStoreApi(webStoreState: WebStoreState) {
331331

332332
try {
333333
await uninstallExtension(id, webStoreState)
334+
334335
queueMicrotask(() => {
335336
event.sender.send('chrome.management.onUninstalled', id)
336337
})
338+
339+
if (webStoreState.afterUninstall) {
340+
queueMicrotask(() => {
341+
webStoreState.afterUninstall?.({ id })
342+
})
343+
}
344+
337345
return Result.SUCCESS
338346
} catch (error) {
339347
console.error(error)

packages/electron-chrome-web-store/src/browser/installer.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ interface InstallExtensionOptions extends CommonExtensionOptions {
203203
loadExtensionOptions?: Electron.LoadExtensionOptions
204204
}
205205

206-
interface UninstallExtensionOptions extends CommonExtensionOptions {
207-
/** Called after an extension is uninstalled. */
208-
afterUninstall?: AfterUninstall
209-
}
210-
211206
/**
212207
* Install extension from the web store.
213208
*/
@@ -245,10 +240,7 @@ export async function installExtension(
245240
/**
246241
* Uninstall extension from the web store.
247242
*/
248-
export async function uninstallExtension(
249-
extensionId: string,
250-
opts: UninstallExtensionOptions = {},
251-
) {
243+
export async function uninstallExtension(extensionId: string, opts: CommonExtensionOptions = {}) {
252244
d('uninstalling %s', extensionId)
253245

254246
const session = opts.session || electronSession.defaultSession
@@ -260,14 +252,6 @@ export async function uninstallExtension(
260252
session.removeExtension(extensionId)
261253
}
262254

263-
if (opts.afterUninstall) {
264-
await opts.afterUninstall({
265-
id: extensionId,
266-
extension: existingExt,
267-
manifest: existingExt?.manifest,
268-
})
269-
}
270-
271255
const extensionDir = path.join(extensionsPath, extensionId)
272256
try {
273257
const stat = await fs.promises.stat(extensionDir)

packages/electron-chrome-web-store/src/browser/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ export type BeforeInstall = (
1515

1616
export type AfterInstall = (details: ExtensionInstallDetails) => Promise<void>
1717

18-
export type AfterUninstall = (details: {
19-
id: ExtensionId
20-
extension?: Electron.Extension
21-
manifest?: chrome.runtime.Manifest
22-
}) => Promise<void>
18+
export type AfterUninstall = (details: { id: ExtensionId }) => Promise<void>
2319

2420
export type CustomSetExtensionEnabled = (
2521
state: WebStoreState,

0 commit comments

Comments
 (0)