-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated settings approach to follow the resolver pattern
- Loading branch information
Showing
8 changed files
with
187 additions
and
85 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
how-to/web-interop-support-context-and-intents/client/src/content/api.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
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
2 changes: 1 addition & 1 deletion
2
how-to/web-interop-support-context-and-intents/client/src/platform/apps/apps.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
2 changes: 1 addition & 1 deletion
2
how-to/web-interop-support-context-and-intents/client/src/platform/iframe-broker.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
104 changes: 104 additions & 0 deletions
104
...erop-support-context-and-intents/client/src/platform/settings/settings-resolver-helper.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,104 @@ | ||
import type OpenFin from "@openfin/core"; | ||
import type { Logger } from "../../shapes/logger-shapes"; | ||
import type { SettingsResolverOptions, SettingsResolverResponse } from "../../shapes/setting-shapes"; | ||
import { clearSettings, getSettings, saveSettings } from "./settings"; | ||
|
||
/** | ||
* An helper for updating and resolving settings. | ||
*/ | ||
export class SettingsResolverHelper { | ||
private readonly _logger: Logger; | ||
|
||
private readonly _settingsResolverOptions?: SettingsResolverOptions; | ||
|
||
private readonly _defaultSettingsResolverHeight: number; | ||
|
||
private readonly _defaultSettingsResolverWidth: number; | ||
|
||
private readonly _dialogElement: HTMLDialogElement | null = null; | ||
|
||
private _dialogClient: OpenFin.ChannelClient | null = null; | ||
|
||
/** | ||
* Create an instance of the Settings Resolver Helper. | ||
* @param settingsResolverOptions options for the helper | ||
* @param logger the logger to use. | ||
*/ | ||
constructor(settingsResolverOptions: SettingsResolverOptions, logger: Logger) { | ||
this._defaultSettingsResolverHeight = 715; | ||
this._defaultSettingsResolverWidth = 665; | ||
this._settingsResolverOptions = { | ||
height: this._defaultSettingsResolverHeight, | ||
width: this._defaultSettingsResolverWidth, | ||
...settingsResolverOptions | ||
}; | ||
this._logger = logger; | ||
this._dialogElement = document.createElement("dialog"); | ||
this._dialogElement.id = "settings-resolver-dialog"; | ||
this._dialogElement.style.height = `${this._settingsResolverOptions.height}px`; | ||
this._dialogElement.style.width = `${this._settingsResolverOptions.width}px`; | ||
this._dialogElement.style.padding = "0px"; | ||
this._dialogElement.style.backgroundColor = "var(--brand-background)"; | ||
// Create a new iframe element | ||
const settingsResolver = document.createElement("iframe"); | ||
|
||
// Set the source of the iframe | ||
settingsResolver.src = settingsResolverOptions.url; | ||
settingsResolver.style.height = "99%"; | ||
settingsResolver.style.width = "100%"; | ||
|
||
// Append the iframe to the dialog | ||
this._dialogElement.append(settingsResolver); | ||
|
||
// Append the dialog to the body | ||
document.body.append(this._dialogElement); | ||
} | ||
|
||
/** | ||
* Launch the settings resolver. | ||
* @returns nothing. | ||
*/ | ||
public async showSettings(): Promise<void> { | ||
if (this._dialogElement) { | ||
this._dialogElement.showModal(); | ||
} | ||
if (!this._dialogClient && this._dialogClient === null) { | ||
const settingsResolverChannel = "settings-resolver"; | ||
console.log("Connecting to settings resolver", settingsResolverChannel); | ||
this._dialogClient = await fin.InterApplicationBus.Channel.connect(settingsResolverChannel); | ||
|
||
// eslint-disable-next-line @typescript-eslint/await-thenable | ||
await this._dialogClient.register("settings-resolver-response", async (payload, sender) => { | ||
const response = payload as { | ||
settingsResolverResponse?: SettingsResolverResponse; | ||
errorMessage?: string; | ||
}; | ||
if (response.settingsResolverResponse) { | ||
if ( | ||
response.settingsResolverResponse.action === "save-reload" && | ||
response.settingsResolverResponse.settings | ||
) { | ||
await saveSettings(response.settingsResolverResponse.settings); | ||
location.reload(); | ||
} else if (response.settingsResolverResponse.action === "reset-reload") { | ||
await clearSettings(); | ||
location.reload(); | ||
} | ||
} else if (response.errorMessage) { | ||
this._logger.error(response.errorMessage); | ||
} | ||
if (this._dialogElement) { | ||
this._dialogElement.close(); | ||
} | ||
}); | ||
} | ||
if (this._dialogElement && this._dialogClient) { | ||
const settings = await getSettings(); | ||
await this._dialogClient.dispatch("apply-settings", { | ||
customData: { | ||
settings | ||
} | ||
}); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...d-intents/client/src/platform/settings.ts → .../client/src/platform/settings/settings.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
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