-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support chrome_url_overrides for custom newtab page
- Loading branch information
1 parent
946c25b
commit 420d08f
Showing
7 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/electron-chrome-extensions/src/browser/manifest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getExtensionUrl, validateExtensionResource } from './api/common' | ||
import { ExtensionContext } from './context' | ||
|
||
export async function readUrlOverrides(ctx: ExtensionContext, extension: Electron.Extension) { | ||
const manifest = extension.manifest as chrome.runtime.Manifest | ||
const urlOverrides = ctx.store.urlOverrides | ||
let updated = false | ||
|
||
if (typeof manifest.chrome_url_overrides === 'object') { | ||
for (const [name, uri] of Object.entries(manifest.chrome_url_overrides!)) { | ||
const validatedPath = await validateExtensionResource(extension, uri) | ||
if (!validatedPath) { | ||
console.error( | ||
`Extension ${extension.id} attempted to override ${name} with invalid resource: ${uri}`, | ||
) | ||
continue | ||
} | ||
|
||
const url = getExtensionUrl(extension, uri)! | ||
const currentUrl = urlOverrides[name] | ||
if (currentUrl !== url) { | ||
urlOverrides[name] = url | ||
updated = true | ||
} | ||
} | ||
} | ||
|
||
if (updated) { | ||
ctx.emit('url-overrides-updated', urlOverrides) | ||
} | ||
} | ||
|
||
export function readLoadedExtensionManifest(ctx: ExtensionContext, extension: Electron.Extension) { | ||
readUrlOverrides(ctx, extension) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters