Skip to content

Commit

Permalink
set error message
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Nov 12, 2024
1 parent 27768b5 commit 21af690
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
22 changes: 13 additions & 9 deletions packages/electron-chrome-web-store/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,24 @@ export function setupChromeWebStore(session: Session, modulePath: string = __dir
await extractCrx(crx, unpackedDir)

// Load extension into session
await session.loadExtension(unpackedDir)
const ext = await session.loadExtension(unpackedDir)

return Result.SUCCESS
queueMicrotask(() => {
event.sender.send('chrome.management.onInstalled', getExtensionInfo(ext))
})

return { result: Result.SUCCESS }
} catch (error) {
console.error('Extension installation failed:', error)
return Result.INSTALL_ERROR
return {
result: Result.INSTALL_ERROR,
message: error instanceof Error ? error.message : String(error),
}
}
})

ipcMain.handle('chromeWebstore.completeInstall', async (event, id) => {
// TODO: Implement completion of extension installation
queueMicrotask(() => {
const ext = session.getExtension(id)
if (ext) {
event.sender.send('chrome.management.onInstalled', getExtensionInfo(ext))
}
})
return Result.SUCCESS
})

Expand Down Expand Up @@ -352,6 +353,9 @@ export function setupChromeWebStore(session: Session, modulePath: string = __dir

try {
await uninstallExtension(id)
queueMicrotask(() => {
event.sender.send('chrome.management.onUninstalled', id)
})
return Result.SUCCESS
} catch (error) {
console.error(error)
Expand Down
12 changes: 11 additions & 1 deletion packages/electron-chrome-web-store/src/renderer/web-store-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ interface WebstorePrivate {
}

function setupChromeWebStoreApi() {
const setExtensionError = (message?: string) => {
webFrame.executeJavaScript(`
if (typeof chrome !== 'undefined') {
if (!chrome.extension) chrome.extension = {};
chrome.extension.lastError = ${JSON.stringify(message ? { message } : null)};
}
`)
}

/**
* Implementation of Chrome's webstorePrivate for Electron.
*/
Expand All @@ -94,8 +103,9 @@ function setupChromeWebStoreApi() {

beginInstallWithManifest3: async (details, callback) => {
console.log('webstorePrivate.beginInstallWithManifest3', details)
const result = await ipcRenderer.invoke('chromeWebstore.beginInstall', details)
const { result, message } = await ipcRenderer.invoke('chromeWebstore.beginInstall', details)
console.log('webstorePrivate.beginInstallWithManifest3 result:', result)
setExtensionError(result === Result.SUCCESS ? null : message)
if (callback) callback(result)
return result
},
Expand Down

0 comments on commit 21af690

Please sign in to comment.