extension: Give precedence to toggles over default options (fixes #5825)

Also fixes #5696
This commit is contained in:
Daniel Jacobs 2023-03-16 10:42:09 -04:00 committed by Mike Welsh
parent 9530da22e2
commit b7c20a6c60
3 changed files with 13 additions and 3 deletions

View File

@ -12,7 +12,10 @@ declare global {
* [[PublicAPI]] instance itself.
*/
RufflePlayer?:
| { config?: DataLoadOptions | URLLoadOptions | object }
| {
config?: DataLoadOptions | URLLoadOptions | object;
conflict?: Record<string, unknown> | null;
}
| PublicAPI;
}
}
@ -33,11 +36,11 @@ export class PublicAPI {
* The configuration object used when Ruffle is instantiated.
*/
config: DataLoadOptions | URLLoadOptions | object;
conflict: Record<string, unknown> | null;
private sources: Record<string, typeof SourceAPI>;
private invoked: boolean;
private newestName: string | null;
private conflict: Record<string, unknown> | null;
/**
* Construct the Ruffle public API.

View File

@ -666,6 +666,13 @@ export class RufflePlayer extends HTMLElement {
try {
this.loadedConfig = {
...DEFAULT_CONFIG,
...(window.RufflePlayer?.conflict &&
window.RufflePlayer?.conflict["newestName"] === "extension"
? (window.RufflePlayer?.conflict["config"] as Record<
string,
unknown
>)
: {}),
...(window.RufflePlayer?.config ?? {}),
...this.config,
...options,

View File

@ -16,8 +16,8 @@ function handleMessage(message: Message) {
case "load": {
const api = window.RufflePlayer ?? {};
api.config = {
...api.config,
...message.config,
...api.config,
};
window.RufflePlayer = PublicAPI.negotiate(api, "extension");
return {};