Skip to content

Commit

Permalink
Merge branch 'main' into workspace/v16.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnman committed Jan 22, 2024
2 parents bd32ae3 + b186bc6 commit 4eb52b7
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 16 deletions.
2 changes: 1 addition & 1 deletion how-to/integrate-with-snap-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This example demonstrates connecting to and using layouts with Snap.

The package utilized by this example is [@openfin/snap-sdk](https://www.npmjs.com/package/@openfin/snap-sdk).

> The **@openfin/snap-sdk** is currently in beta, this sample requires the Snap Asset Url for the Snap Server. Please ask OpenFin for the url and then replace the `SNAP_ASSET_URL` in `manifest.fin.json` with it.
> The **@openfin/snap-sdk** is currently in beta. The version of the Snap SDK is referenced in package.json and the app asset defined in `manifest.fin.json`.
## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion how-to/integrate-with-snap-basic/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"appAssets": [
{
"src": "SNAP_ASSET_URL",
"src": "https://cdn.openfin.co/release/snap/0.2.0/snap.zip",
"alias": "openfin-snap",
"version": "0.2.0",
"target": "OpenFinSnap.exe",
Expand Down
2 changes: 1 addition & 1 deletion how-to/integrate-with-snap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This example demonstrates saving and restoring native applications as part of a

The package utilized by this example is [@openfin/snap-sdk](https://www.npmjs.com/package/@openfin/snap-sdk).

> The **@openfin/snap-sdk** is currently in beta, this sample requires the Snap Asset Url for the Snap Server. Please ask OpenFin for the url and then replace the `SNAP_ASSET_URL` in `manifest.fin.json` with it.
> The **@openfin/snap-sdk** is currently in beta. The version of the Snap SDK is referenced in package.json and the app asset defined in `manifest.fin.json`.
## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion how-to/integrate-with-snap/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"appAssets": [
{
"src": "SNAP_ASSET_URL",
"src": "https://cdn.openfin.co/release/snap/0.2.0/snap.zip",
"alias": "openfin-snap",
"version": "0.2.0",
"target": "OpenFinSnap.exe",
Expand Down
96 changes: 92 additions & 4 deletions how-to/register-with-dock-basic/client/src/dock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
Dock,
DockButtonNames,
type DockButton,
type RegistrationMetaInfo,
type WorkspaceButtonsConfig
type DockProviderRegistration,
type WorkspaceButtonsConfig,
type DockProviderConfig
} from "@openfin/workspace";
import {
CustomActionCallerType,
Expand All @@ -11,6 +14,11 @@ import {
type CustomActionsMap
} from "@openfin/workspace-platform";

let platformTitle: string | undefined;
let platformIcon: string | undefined;
let customIconUrl: string | undefined;
let customOpenUrl: string | undefined;
let registration: DockProviderRegistration | undefined;
/**
* Register the dock provider.
* @param id The id to register the provider with.
Expand All @@ -37,7 +45,11 @@ export async function register(
console.log("Initializing the dock provider.");

try {
const metaInfo = await Dock.register({
platformTitle = title;
platformIcon = icon;
customIconUrl = options.customIconUrl;
customOpenUrl = options.customOpenUrl;
registration = await Dock.register({
id,
title,
icon,
Expand Down Expand Up @@ -90,9 +102,9 @@ export async function register(
}
]
});
console.log(metaInfo);
console.log(registration);
console.log("Dock provider initialized.");
return metaInfo;
return registration;
} catch (err) {
console.error("An error was encountered while trying to register the content dock provider", err);
}
Expand Down Expand Up @@ -132,3 +144,79 @@ export function dockGetCustomActions(): CustomActionsMap {
}
};
}

/**
* Create the configuration for the dock, including a drop down for favorites if there are any. Normally, you would pass this into the initial
* register method above, but this is only for demonstrating the ability to change the dock dynamically.
* @param isEnabled Passes a boolean accounting for buttons in the dock being usable or not.
* @returns The dock configuration.
*/
function buildDockConfiguration(isEnabled: boolean): DockProviderConfig {
const buttons: DockButton[] = [
{
tooltip: "Google",
iconUrl: "https://www.google.com/favicon.ico",
action: {
id: "launch-google"
},
disabled: !isEnabled
},
{
tooltip: "Bing",
iconUrl: "https://www.bing.com/favicon.ico",
action: {
id: "launch-bing"
},
disabled: !isEnabled
},
{
tooltip: "Custom",
iconUrl: customIconUrl,
action: {
id: "launch-custom",
customData: customOpenUrl
},
disabled: !isEnabled
},
{
type: DockButtonNames.DropdownButton,
tooltip: "Social",
iconUrl: "http://localhost:8080/assets/spanner.svg",
options: [
{
tooltip: "Twitter",
action: {
id: "launch-tools",
customData: "twitter"
}
},
{
tooltip: "Facebook",
action: {
id: "launch-tools",
customData: "facebook"
}
}
],
disabled: !isEnabled
}
];

return {
title: platformTitle ?? "",
icon: platformIcon ?? "",
workspaceComponents: ["home", "notifications", "store", "switchWorkspace"],
disableUserRearrangement: false,
buttons
};
}

/**
* Update the dock when something has changed.
* @param isEnabled Tells us whether or not the Dock buttons should be clickable.
*/
export async function updateDock(isEnabled: boolean): Promise<void> {
if (registration) {
await registration.updateDockProviderConfig(buildDockConfiguration(isEnabled));
}
}
22 changes: 20 additions & 2 deletions how-to/register-with-dock-basic/client/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
type WorkspaceButton
} from "@openfin/workspace";
import { init } from "@openfin/workspace-platform";
import { dockGetCustomActions, register } from "./dock";
import { dockGetCustomActions, register, updateDock } from "./dock";

let registerButton: HTMLButtonElement | null;
let showButton: HTMLButtonElement | null;
let minimizeButton: HTMLButtonElement | null;
let deregisterButton: HTMLButtonElement | null;
let enableButton: HTMLButtonElement | null;
let disableButton: HTMLButtonElement | null;
let showHomeButton: HTMLInputElement | null;
let showNotificationButton: HTMLInputElement | null;
let showStorefrontButton: HTMLInputElement | null;
Expand Down Expand Up @@ -114,8 +116,10 @@ async function initializeDOM(): Promise<void> {
enableRearrangementButton = document.querySelector<HTMLInputElement>("#enableRearrangement");
customIconUrlInput = document.querySelector<HTMLInputElement>("#customIconUrl");
customOpenUrlInput = document.querySelector<HTMLInputElement>("#customOpenUrl");
enableButton = document.querySelector<HTMLButtonElement>("#enable");
disableButton = document.querySelector<HTMLButtonElement>("#disable");

if (registerButton && deregisterButton && showButton && minimizeButton) {
if (registerButton && deregisterButton && showButton && minimizeButton && enableButton && disableButton) {
setStates(false);

registerButton.addEventListener("click", async () => {
Expand Down Expand Up @@ -163,6 +167,16 @@ async function initializeDOM(): Promise<void> {
minimizeButton.addEventListener("click", async () => {
await Dock.minimize();
});

enableButton.addEventListener("click", async () => {
console.log("Enable Clicked!");
await updateDock(true);
});

disableButton.addEventListener("click", async () => {
console.log("Disable Clicked!");
await updateDock(false);
});
}
}

Expand All @@ -176,6 +190,8 @@ function setStates(isRegistered: boolean | null): void {
deregisterButton &&
showButton &&
minimizeButton &&
enableButton &&
disableButton &&
showHomeButton &&
showNotificationButton &&
showStorefrontButton &&
Expand All @@ -188,6 +204,8 @@ function setStates(isRegistered: boolean | null): void {
deregisterButton.disabled = isRegistered === null || !isRegistered;
showButton.disabled = isRegistered === null || !isRegistered;
minimizeButton.disabled = isRegistered === null || !isRegistered;
enableButton.disabled = isRegistered === null || !isRegistered;
disableButton.disabled = isRegistered === null || !isRegistered;
showHomeButton.disabled = isRegistered === null || isRegistered;
showNotificationButton.disabled = isRegistered === null || isRegistered;
showStorefrontButton.disabled = isRegistered === null || isRegistered;
Expand Down
4 changes: 3 additions & 1 deletion how-to/register-with-dock-basic/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"icon": "http://localhost:8080/favicon.ico",
"autoShow": true,
"providerUrl": "http://localhost:8080/platform/provider.html",
"preventQuitOnLastWindowClosed": true
"preventQuitOnLastWindowClosed": true,
"minWidth": 750,
"defaultWidth": 750
},
"shortcut": {
"company": "OpenFin",
Expand Down
2 changes: 2 additions & 0 deletions how-to/register-with-dock-basic/public/platform/provider.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ <h1 class="tag">Demonstrate basic dock interactions.</h1>
<button id="deregister">Deregister A Dock Provider</button>
<button id="show">Show Dock</button>
<button id="minimize">Minimize Dock</button>
<button id="enable">Enable Buttons</button>
<button id="disable">Disable Buttons</button>
</div>
<div class="col gap20">
<h2>Options</h2>
Expand Down
2 changes: 1 addition & 1 deletion how-to/workspace-platform-starter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- Docs - Added a document showing [How To Add A Service](./docs/how-to-add-a-service.md)
- Improved launchPreference so that now args for a native app (app asset or external) can be specified via launchPreference. Launch preference can also be configured to allow args to be specified dynamically when the launch request is made. Please see [how to define app launch preference](./docs/how-to-define-app-launch-preference.md).
- Improved launchPreference so additional options such as url, interop, customData can be specified. Modules can now pass a launchPreference when launching an app by appId. They can see if the app supports being updated by getting the app by id and checking for the updatable setting under launchPreference.options. Only inline-view/view and inline-window/window support updatable launch preferences. Please see [how to define app launch preference](./docs/how-to-define-app-launch-preference.md).
- Added support for Snap, enable by setting `customSettings.snapProvider.enabled` to true. Configure the `customSettings.snapProvider.serverAssetInfo` to point to the `SNAP_ASSET_URL`. Enable the Snap debugging window by setting `customSettings.snapProvider.showDebugWindow` to true.
- Added support for Snap, enable by setting `customSettings.snapProvider.enabled` to true. Enable the Snap debugging window by setting `customSettings.snapProvider.showDebugWindow` to true.
- Added new module type `content-creation`, these modules can be used to define content creation rules and handle the associated events. Modules are added in `customSettings.contentCreationProvider` section in manifest.
- Added example content creation module which interrogates the `features` property from `window.open` to determine where to place a view in relation to where it was launched from. An example app `Content Creation Example` demonstrates this in use.
- Added CustomActionCallerType enum to actions-shapes, use these in preference to the workspace-platform CustomActionCallerType type to avoid importing the whole npm package into your modules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The OpenFin Snap SDK provides the ability to snap windows together, include native applications.
For more detailed information see [OpenFin Snap SDK](https://developers.openfin.co/of-docs/docs/snap)

To enable snap support in your platform you can add the following in your manifest.fin.json. As the Snap SDK is currently in beta you must contact OpenFin to get the real url for the `SNAP_ASSET_URL`
To enable snap support in your platform you can add the following in your manifest.fin.json.

```json
{
Expand All @@ -17,7 +17,7 @@ To enable snap support in your platform you can add the following in your manife
"enabled": true,
"id": "workspace-platform-starter",
"serverAssetInfo": {
"src": "SNAP_ASSET_URL",
"src": "https://cdn.openfin.co/release/snap/0.2.0/snap.zip",
"alias": "openfin-snap",
"version": "0.2.0",
"target": "OpenFinSnap.exe"
Expand Down
2 changes: 1 addition & 1 deletion how-to/workspace-platform-starter/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@
"enabled": false,
"id": "workspace-platform-starter",
"serverAssetInfo": {
"src": "SNAP_ASSET_URL",
"src": "https://cdn.openfin.co/release/snap/0.2.0/snap.zip",
"alias": "openfin-snap",
"version": "0.2.0",
"target": "OpenFinSnap.exe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@
"enabled": false,
"id": "workspace-platform-starter",
"serverAssetInfo": {
"src": "SNAP_ASSET_URL",
"src": "https://cdn.openfin.co/release/snap/0.2.0/snap.zip",
"alias": "openfin-snap",
"version": "0.2.0",
"target": "OpenFinSnap.exe"
Expand Down

0 comments on commit 4eb52b7

Please sign in to comment.