@openfin/workspace-platform 4.3.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/client-api/src/shapes.d.ts +596 -0
  2. package/{index.ts → client-api-platform/index.d.ts} +0 -0
  3. package/client-api-platform/src/api/app-directory.d.ts +7 -0
  4. package/client-api-platform/src/api/browser/browser-module.d.ts +13 -0
  5. package/client-api-platform/src/api/browser/index.d.ts +22 -0
  6. package/client-api-platform/src/api/pages/helper.d.ts +22 -0
  7. package/client-api-platform/src/api/pages/index.d.ts +30 -0
  8. package/client-api-platform/src/api/protocol.d.ts +48 -0
  9. package/client-api-platform/src/api/storage.d.ts +10 -0
  10. package/client-api-platform/src/api/theming.d.ts +5 -0
  11. package/client-api-platform/src/api/workspace-module.d.ts +3 -0
  12. package/client-api-platform/src/index.d.ts +6 -0
  13. package/client-api-platform/src/init/browser-window-focus.d.ts +19 -0
  14. package/client-api-platform/src/init/cleanup.d.ts +1 -0
  15. package/client-api-platform/src/init/index.d.ts +5 -0
  16. package/client-api-platform/src/init/override-callback.d.ts +3 -0
  17. package/client-api-platform/src/init/theming.d.ts +9 -0
  18. package/client-api-platform/src/init/utils.d.ts +39 -0
  19. package/client-api-platform/src/shapes.d.ts +278 -0
  20. package/client-api-platform/src/umd.d.ts +1 -0
  21. package/common/src/api/pages/attached.d.ts +101 -0
  22. package/common/src/api/pages/idb.d.ts +12 -0
  23. package/common/src/api/pages/index.d.ts +16 -0
  24. package/common/src/api/pages/legacy.d.ts +16 -0
  25. package/common/src/api/pages/shapes.d.ts +77 -0
  26. package/common/src/api/protocol.d.ts +63 -0
  27. package/common/src/api/theming.d.ts +60 -0
  28. package/common/src/api/workspaces/index.d.ts +7 -0
  29. package/common/src/utils/application.d.ts +38 -0
  30. package/common/src/utils/channels.d.ts +8 -0
  31. package/common/src/utils/debounce.d.ts +16 -0
  32. package/common/src/utils/env.d.ts +30 -0
  33. package/common/src/utils/layout.d.ts +52 -0
  34. package/common/src/utils/local-storage-key.d.ts +8 -0
  35. package/common/src/utils/logger/index.d.ts +26 -0
  36. package/common/src/utils/logger/manager.d.ts +35 -0
  37. package/common/src/utils/logger/shapes.d.ts +27 -0
  38. package/common/src/utils/route.d.ts +55 -0
  39. package/common/src/utils/shared-emitter.d.ts +10 -0
  40. package/common/src/utils/snapshot.d.ts +33 -0
  41. package/common/src/utils/strings.d.ts +5 -0
  42. package/common/src/utils/theming.d.ts +57 -0
  43. package/common/src/utils/umd.d.ts +2 -0
  44. package/common/src/utils/window.d.ts +146 -0
  45. package/index.d.ts +1 -0
  46. package/index.js +2 -0
  47. package/index.js.map +1 -0
  48. package/package.json +1 -34
  49. package/search-api/src/client/index.d.ts +6 -0
  50. package/search-api/src/client/internal.d.ts +38 -0
  51. package/search-api/src/client/remote/channel-client-factory.d.ts +2 -0
  52. package/search-api/src/client/remote/channel-client.d.ts +9 -0
  53. package/search-api/src/client/remote/data.d.ts +16 -0
  54. package/search-api/src/client/remote/disconnect.d.ts +7 -0
  55. package/search-api/src/client/remote/dispatch.d.ts +9 -0
  56. package/search-api/src/client/remote/requests.d.ts +5 -0
  57. package/search-api/src/client/remote/search-close.d.ts +14 -0
  58. package/search-api/src/common.d.ts +104 -0
  59. package/search-api/src/errors.d.ts +5 -0
  60. package/search-api/src/fin/index.d.ts +6 -0
  61. package/search-api/src/fin/shapes.d.ts +23 -0
  62. package/search-api/src/index.d.ts +7 -0
  63. package/search-api/src/internal-shapes.d.ts +134 -0
  64. package/search-api/src/logger.d.ts +1 -0
  65. package/search-api/src/provider/index.d.ts +8 -0
  66. package/search-api/src/provider/internal.d.ts +33 -0
  67. package/search-api/src/provider/remote/channel-factory.d.ts +6 -0
  68. package/search-api/src/provider/remote/channel.d.ts +23 -0
  69. package/search-api/src/provider/remote/connection.d.ts +20 -0
  70. package/search-api/src/provider/remote/data.d.ts +23 -0
  71. package/search-api/src/provider/remote/deregistration.d.ts +5 -0
  72. package/search-api/src/provider/remote/disconnect.d.ts +1 -0
  73. package/search-api/src/provider/remote/disconnection.d.ts +9 -0
  74. package/search-api/src/provider/remote/dispatch.d.ts +7 -0
  75. package/search-api/src/provider/remote/info.d.ts +5 -0
  76. package/search-api/src/provider/remote/registration.d.ts +23 -0
  77. package/search-api/src/provider/remote/search-close.d.ts +14 -0
  78. package/search-api/src/provider/remote/search.d.ts +8 -0
  79. package/search-api/src/shapes.d.ts +541 -0
  80. package/.eslintignore +0 -1
  81. package/.eslintrc.js +0 -2
  82. package/.prettierrc.js +0 -2
  83. package/babel.config.js +0 -2
  84. package/jest.config.js +0 -2
  85. package/src/api/app-directory.ts +0 -45
  86. package/src/api/browser/browser-module.ts +0 -65
  87. package/src/api/browser/index.ts +0 -46
  88. package/src/api/pages/helper.ts +0 -113
  89. package/src/api/pages/index.ts +0 -164
  90. package/src/api/protocol.ts +0 -60
  91. package/src/api/storage.ts +0 -32
  92. package/src/api/workspace-module.ts +0 -36
  93. package/src/index.ts +0 -35
  94. package/src/init/browser-window-focus.ts +0 -59
  95. package/src/init/cleanup.ts +0 -87
  96. package/src/init/index.ts +0 -42
  97. package/src/init/override-callback.ts +0 -159
  98. package/src/init/utils.ts +0 -164
  99. package/src/shapes.ts +0 -160
  100. package/src/umd.ts +0 -5
  101. package/tsconfig.json +0 -13
  102. package/webpack.common.config.js +0 -1
@@ -1,46 +0,0 @@
1
- import type { AttachedPage, Page } from '@common/api/pages/shapes';
2
-
3
- import type { BrowserCreateWindowRequest, BrowserWindowModule } from '../../shapes';
4
- import { ChannelAction, getChannelClient } from '../protocol';
5
-
6
- import { getBrowserModule } from './browser-module';
7
-
8
- export const getBrowserApi = (identity: OpenFin.Identity) => {
9
- const platform = fin.Platform.wrapSync(identity);
10
-
11
- const getOpenPages = async (): Promise<AttachedPage[]> => {
12
- const client = await platform.getClient();
13
- return client.dispatch(ChannelAction.GetOpenPages, undefined);
14
- };
15
-
16
- return {
17
- wrapSync: (windowIdentity: OpenFin.Identity) => getBrowserModule(windowIdentity),
18
- createWindow: async (options: BrowserCreateWindowRequest): Promise<BrowserWindowModule> => {
19
- const win = await platform.createWindow(options as any); // TODO: remove typecast after container removes Page type
20
- return getBrowserModule(win.identity);
21
- },
22
- getOpenPages,
23
- getAllWindows: async (): Promise<BrowserWindowModule[]> => {
24
- const CHILD_WINDOW_NAME_PREFIX = 'internal-generated-window-';
25
- const childWindows = await fin.Application.wrapSync(identity).getChildWindows();
26
- const browserWindows = childWindows.filter((win) => win.identity.name.includes(CHILD_WINDOW_NAME_PREFIX));
27
- return browserWindows.map((bw) => getBrowserModule(bw.identity));
28
- },
29
-
30
- launchPage: async (page: Page): Promise<BrowserWindowModule> => {
31
- const client = await platform.getClient();
32
- await client.dispatch(ChannelAction.LaunchPage, { page, attachToExistingWindow: true });
33
- const pages = await getOpenPages();
34
- const launchedPage = pages.find((p) => p.pageId === page.pageId);
35
- return getBrowserModule(launchedPage.parentIdentity);
36
- },
37
- getUniquePageTitle: async (title?: string) => {
38
- const channel = await getChannelClient(identity);
39
- return channel.dispatch(ChannelAction.GetUniquePageTitle, title);
40
- },
41
- getLastFocusedWindow: async () => {
42
- const channel = await getChannelClient(identity);
43
- return channel.dispatch(ChannelAction.GetLastFocusedBrowserWindow, undefined);
44
- }
45
- };
46
- };
@@ -1,113 +0,0 @@
1
- import type { Fin } from 'openfin-adapter';
2
-
3
- import { getSnapshotExtended, SnapshotExtended } from '@common/utils/snapshot';
4
- import { getBrowserWindows } from '@common/utils/window';
5
-
6
- import { makePage } from '@common/api/pages';
7
- import * as attachedPageAPI from '@common/api/pages/attached';
8
- import { fixAttachedPages } from '@common/api/pages/legacy';
9
- import { AttachedPage, Page } from '@common/api/pages/shapes';
10
-
11
- import { initWorkspacePlatformOptions } from '@client-platform/init/utils';
12
-
13
- import { getOpenPages, getUniquePageTitle, setActivePageForWindow } from '.';
14
-
15
- declare const fin: Fin<'window'>;
16
-
17
- /**
18
- * Brings the page's parent window into focus.
19
- * The window will be brought to front, focused and restored.
20
- * @param page the page to focus.
21
- */
22
- const focusAndRestoreWindow = (identity: OpenFin.Identity) => {
23
- const targetWin = fin.Window.wrapSync(identity);
24
- return Promise.all([targetWin.bringToFront(), targetWin.restore(), targetWin.focus()]);
25
- };
26
-
27
- /**
28
- * Get a snapshot with pages.
29
- *
30
- * Makes sure that the layout of the page is up to date with the window's layout.
31
- *
32
- * @returns a snapshot with windows that contain pages.
33
- */
34
- export async function getSnapshotWithPages(superGetSnapshot?: () => Promise<SnapshotExtended>) {
35
- const browserWins = await getBrowserWindows();
36
- await Promise.all(browserWins.map(({ identity }) => attachedPageAPI.updatePagesWindowOptions(identity)));
37
- return superGetSnapshot ? superGetSnapshot() : getSnapshotExtended();
38
- }
39
-
40
- /**
41
- * Launch a snapshot that contains windows with pages.
42
- *
43
- * If a page with the same ID is already launched in the platform,
44
- * focus and set it as the active page.
45
- *
46
- * If there is no page on the desktop with the same ID, launch
47
- * the new window with the page.
48
- *
49
- * @param snapshot the snapshot to launch.
50
- */
51
- export async function applySnapshotWithPages(
52
- snapshot: OpenFin.Snapshot,
53
- superApplySnapshot?: (superSnapshot: OpenFin.Snapshot) => Promise<void>
54
- ): Promise<void> {
55
- const allAttachedPages = await getOpenPages();
56
-
57
- const monitorInfo = snapshot.snapshotDetails?.monitorInfo || (await fin.System.getMonitorInfo());
58
- const allLaunchingWindows = (snapshot.windows || []).filter(({ layout }) => !!layout);
59
-
60
- const attachedPageMap: Map<string, Page> = new Map();
61
- allAttachedPages.forEach((w) => attachedPageMap.set(w.pageId, w));
62
-
63
- const newWindowOptions: OpenFin.WindowOptions[] = [];
64
- const launchingWindowsPromises = allLaunchingWindows.map(async (launchingWindow: OpenFin.WindowOptions) => {
65
- const options = initWorkspacePlatformOptions(launchingWindow);
66
- const pagesToLaunch: Page[] = [];
67
- const launchingPages = fixAttachedPages(options?.workspacePlatform?.pages);
68
- if (!launchingPages?.length) {
69
- const title = await getUniquePageTitle();
70
- pagesToLaunch.push(await makePage(title, options.layout));
71
- }
72
-
73
- let pageToActivate: AttachedPage;
74
- launchingPages.forEach((launchingPage) => {
75
- const attachedPage = attachedPageMap.get(launchingPage.pageId);
76
- if (attachedPage) {
77
- pageToActivate = attachedPage;
78
- return;
79
- }
80
- pagesToLaunch.push(launchingPage);
81
- });
82
-
83
- if (pageToActivate) {
84
- await Promise.all([
85
- setActivePageForWindow({
86
- identity: pageToActivate.parentIdentity,
87
- pageId: pageToActivate.pageId
88
- }),
89
- focusAndRestoreWindow(pageToActivate.parentIdentity)
90
- ]);
91
- }
92
-
93
- if (pagesToLaunch.length) {
94
- newWindowOptions.push({
95
- ...(options as OpenFin.WindowOptions),
96
- workspacePlatform: { ...options.workspacePlatform, pages: pagesToLaunch as OpenFin.Page[] }
97
- });
98
- }
99
- });
100
- await Promise.all(launchingWindowsPromises);
101
-
102
- if (!newWindowOptions.length) return;
103
- const platform = fin.Platform.getCurrentSync();
104
- const applySnapshot = superApplySnapshot || platform.applySnapshot.bind(platform);
105
- return applySnapshot({
106
- ...snapshot,
107
- snapshotDetails: {
108
- ...snapshot.snapshotDetails,
109
- monitorInfo
110
- },
111
- windows: newWindowOptions
112
- });
113
- }
@@ -1,164 +0,0 @@
1
- import { currentOFIdentity, getBrowserWindows } from '@common/utils/window';
2
-
3
- import * as attachedPageAPI from '@common/api/pages/attached';
4
- import type { AttachPagesToWindowPayload } from '@common/api/pages/shapes';
5
-
6
- import type { CreateSavedPageRequest, Page, UpdateSavedPageRequest } from '@client-platform/shapes';
7
-
8
- import { ChannelAction, getChannelClient } from '../protocol';
9
-
10
- /**
11
- * Get all open pages in which are attached to a window.
12
- * @returns the list of attached pages.
13
- */
14
- export const getOpenPages = async () => {
15
- const browserWins = await getBrowserWindows();
16
- const attachedPages = await Promise.all(
17
- browserWins.map(async ({ identity }) => attachedPageAPI.getPages(identity))
18
- );
19
- return attachedPages.reduce((x, y) => x.concat(y), []);
20
- };
21
-
22
- const findAttachedPage = async (id: string) => {
23
- const allRunningPages = await getOpenPages();
24
- return allRunningPages.find((page) => page.pageId === id);
25
- };
26
-
27
- const createPageInStorage = async (req: CreateSavedPageRequest) => {
28
- const client = await getChannelClient(currentOFIdentity);
29
- return client.dispatch(ChannelAction.CreateSavedPage, req);
30
- };
31
-
32
- const getPagesInStorage = async (): Promise<Page[]> => {
33
- const client = await getChannelClient(currentOFIdentity);
34
- return client.dispatch(ChannelAction.GetSavedPages, undefined);
35
- };
36
-
37
- const getPageInStorage = async (id: string): Promise<Page> => {
38
- const client = await getChannelClient(currentOFIdentity);
39
- return client.dispatch(ChannelAction.GetSavedPage, id);
40
- };
41
-
42
- const deletePageInStorage = async (id: string) => {
43
- const client = await getChannelClient(currentOFIdentity);
44
- return client.dispatch(ChannelAction.DeleteSavedPage, id);
45
- };
46
-
47
- const updatePageInStorage = async (req) => {
48
- const client = await getChannelClient(currentOFIdentity);
49
- return client.dispatch(ChannelAction.UpdateSavedPage, req);
50
- };
51
-
52
- /**
53
- * Update attached page attributes to match a saved page.
54
- * Specifically, `pageId` and `title` must always match.
55
- */
56
- const updateAttachedPage = async (pageId: string, page: Page) => {
57
- const attachedPage = await findAttachedPage(pageId);
58
- if (attachedPage && (attachedPage.title !== page.title || pageId !== page.pageId)) {
59
- await attachedPageAPI.updatePageForWindow({
60
- identity: attachedPage.parentIdentity,
61
- pageId: pageId,
62
- page: {
63
- pageId: page.pageId,
64
- title: page.title
65
- }
66
- });
67
- }
68
- return attachedPage;
69
- };
70
-
71
- export const createSavedPageInternal = async ({ page }: CreateSavedPageRequest) => {
72
- await updateAttachedPage(page.pageId, page);
73
- await createPageInStorage({ page });
74
- };
75
-
76
- export const deleteSavedPageInternal = async (id: string) => {
77
- const pageToDelete = await getPageInStorage(id);
78
- if (!pageToDelete) return;
79
- await deletePageInStorage(id);
80
- };
81
-
82
- export const updateSavedPageInternal = async ({ pageId, page }: UpdateSavedPageRequest) => {
83
- await updateAttachedPage(pageId, page);
84
- const isDatabaseUpdated = await updatePageInStorage({ pageId, page });
85
- return isDatabaseUpdated;
86
- };
87
-
88
- export const savePage = async (page: Page) => {
89
- const savedPage = await getPageInStorage(page.pageId);
90
- if (savedPage) {
91
- return updateSavedPageInternal({ pageId: page.pageId, page });
92
- }
93
- return createSavedPageInternal({ page });
94
- };
95
-
96
- export const attachPagesToWindow = async (payload: AttachPagesToWindowPayload) => {
97
- await attachedPageAPI.attachPagesToWindow(payload);
98
- };
99
-
100
- export const updatePageForWindow = async (payload) => {
101
- await attachedPageAPI.updatePageForWindow(payload);
102
- };
103
-
104
- export const detachPagesFromWindow = async (payload) => {
105
- await attachedPageAPI.detachPagesFromWindow(payload);
106
- };
107
-
108
- export const setActivePageForWindow = async (payload) => {
109
- await attachedPageAPI.setActivePageForWindow(payload);
110
- };
111
-
112
- export const getPagesForWindow = (identity: OpenFin.Identity) => attachedPageAPI.getPages(identity);
113
-
114
- export const getPageForWindow = async ({ identity, pageId }) => {
115
- const pages = await getPagesForWindow(identity);
116
- return pages.find((p) => p.pageId === pageId);
117
- };
118
-
119
- export const reorderPagesForWindow = async (payload) => {
120
- await attachedPageAPI.reorderPagesForWindow(payload);
121
- };
122
-
123
- export const getActivePageIdForWindow = async (identity) => {
124
- const { pageId } = await attachedPageAPI.getActivePageForWindow(identity);
125
- return pageId;
126
- };
127
-
128
- const checkIsUnique = (val: string, arr: string[]): boolean => !arr.find((n) => n === val);
129
-
130
- /**
131
- * Helper function to maintain duplicate name format in fewer places
132
- * @param baseName Name to which we want to append
133
- * @param counter Number to append
134
- * @returns string: The name with the counter appended
135
- */
136
- const formatNameWithCounter = (baseName: string, counter: number): string => `${baseName} (${counter})`;
137
-
138
- /**
139
- * Checks if a given page name is unique
140
- * If not, add a progressive number to it
141
- * @param initialName The initial name to test
142
- * @returns string: a unique page name
143
- */
144
- export async function getUniquePageTitle(initialName = 'Untitled Page'): Promise<string> {
145
- const [savedPages, openPages] = await Promise.all([getPagesInStorage(), getOpenPages()]);
146
-
147
- // Names need to be unique across all running and saved pages
148
- const allPageNames = [...savedPages, ...openPages].map(({ title }) => title);
149
-
150
- if (!allPageNames.find((n) => n === initialName)) {
151
- return initialName;
152
- }
153
-
154
- // Format is any number of digits, wrapped in parentheses and preceded by a space.
155
- const stripNumberRegEx = / \(.+\)$/;
156
-
157
- let counter = 1;
158
- const baseName = initialName.replace(stripNumberRegEx, '');
159
-
160
- while (!checkIsUnique(formatNameWithCounter(baseName, counter), allPageNames)) {
161
- counter += 1;
162
- }
163
- return formatNameWithCounter(baseName, counter);
164
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * All of the remote procedures that can be called in the
3
- * a Workspace Platform's address space.
4
- *
5
- * When adding a new channel action make sure to add a function that's name matches
6
- * the value of the enum for the remote procedure in the Workspace Platform overrides.
7
- * All of the registered channel action handlers can be found here in the platform's overrides:
8
- * @see link: [Provider Protocol Handlers](https://github.com/openfin/workspace/client-api-platform/src/init/override-callback.ts)
9
- */
10
- export enum ChannelAction {
11
- LaunchApp = 'launchApp',
12
- SavePage = 'savePage',
13
- GetSavedPage = 'getSavedPage',
14
- CreateSavedPage = 'createSavedPage',
15
- UpdateSavedPage = 'updateSavedPage',
16
- DeleteSavedPage = 'deleteSavedPage',
17
- GetSavedPages = 'getSavedPages',
18
- CreateSavedPageInternal = 'createSavedPageInternal',
19
- UpdateSavedPageInternal = 'updateSavedPageInternal',
20
- DeleteSavedPageInternal = 'deleteSavedPageInternal',
21
- SharePage = 'sharePage',
22
- LaunchPage = 'launchPage',
23
- UpdatePageForWindow = 'updatePageForWindow',
24
- AttachPagesToWindow = 'attachPagesToWindow',
25
- DetachPagesFromWindow = 'detachPagesFromWindow',
26
- ReorderPagesForWindow = 'reorderPagesForWindow',
27
- SetActivePageForWindow = 'setActivePageForWindow',
28
- GetOpenPages = 'getOpenPages',
29
- GetActivePageIdForWindow = 'getActivePageIdForWindow',
30
- GetPagesForWindow = 'getPagesForWindow',
31
- GetPageForWindow = 'getPageForWindow',
32
- GetSavedPageMetadata = 'getSavedPageMetadata',
33
- GetUniquePageTitle = 'getUniquePageTitle',
34
- GetLastFocusedBrowserWindow = 'getLastFocusedBrowserWindow'
35
- }
36
-
37
- /**
38
- * Get a channel client for a specific Workspace platform.
39
- *
40
- * The channel client can execute remote procedures on the platform via its `dispatch` function.
41
- * A call to the `dispatch` function will block until the channel action has concluded execution
42
- * in the Workspace platform's address space.
43
- * For a list of supported procedures, see the `ChannelAction` enum.
44
- *
45
- * @returns the channel client for the Workspace platform.
46
- */
47
- export const getChannelClient = async (identity: OpenFin.Identity) => {
48
- const platform = fin.Platform.wrapSync(identity);
49
- const client = await platform.getClient();
50
- const errMsg = 'Target is not a Workspace Platform. Target must call WorkspacePlatform.init';
51
- try {
52
- const res = await client.dispatch('isWorkspacePlatform');
53
- if (res === true) {
54
- return client;
55
- }
56
- throw new Error(errMsg);
57
- } catch (e) {
58
- throw new Error(errMsg);
59
- }
60
- };
@@ -1,32 +0,0 @@
1
- import { Page } from '@common/api/pages/shapes';
2
-
3
- import type { CreateSavedPageRequest, UpdateSavedPageRequest } from '../shapes';
4
-
5
- import { ChannelAction, getChannelClient } from './protocol';
6
-
7
- export const getStorageApi = (identity) => ({
8
- createPage: async (req: CreateSavedPageRequest) => {
9
- const client = await getChannelClient(identity);
10
- return client.dispatch(ChannelAction.CreateSavedPageInternal, req);
11
- },
12
- deletePage: async (id: string) => {
13
- const client = await getChannelClient(identity);
14
- return client.dispatch(ChannelAction.DeleteSavedPageInternal, id);
15
- },
16
- updatePage: async (req: UpdateSavedPageRequest) => {
17
- const client = await getChannelClient(identity);
18
- return client.dispatch(ChannelAction.UpdateSavedPageInternal, req);
19
- },
20
- getPage: async (id: string) => {
21
- const client = await getChannelClient(identity);
22
- return client.dispatch(ChannelAction.GetSavedPage, id);
23
- },
24
- getPages: async (query?: string): Promise<Page[]> => {
25
- const client = await getChannelClient(identity);
26
- return client.dispatch(ChannelAction.GetSavedPages, query);
27
- },
28
- savePage: async (page: Page) => {
29
- const client = await getChannelClient(identity);
30
- return client.dispatch(ChannelAction.SavePage, page);
31
- }
32
- });
@@ -1,36 +0,0 @@
1
- import { finEntityType, finName, finUUID } from '@common/utils/env';
2
-
3
- import type { BrowserSnapshot, WorkspacePlatformModule } from '../shapes';
4
- import { LaunchAppPayload } from '..';
5
-
6
- import { getBrowserApi } from './browser';
7
- import { ChannelAction, getChannelClient } from './protocol';
8
- import { getStorageApi } from './storage';
9
-
10
- export const getWorkspacePlatformModule = (identity: OpenFin.Identity): WorkspacePlatformModule => {
11
- const platform = fin.Platform.wrapSync(identity);
12
-
13
- const platformModule = Object.assign(platform, {
14
- applySnapshot: async (snapshot: BrowserSnapshot | string): Promise<OpenFin.Platform> => {
15
- if (typeof snapshot !== 'string' && !snapshot?.windows) {
16
- throw new Error('Not a valid browser snapshot');
17
- }
18
- return fin.Platform.wrapSync(identity).applySnapshot(snapshot);
19
- },
20
- getSnapshot: () =>
21
- fin.Platform.wrapSync(identity)
22
- .getSnapshot()
23
- .then((snapshot) => snapshot as BrowserSnapshot),
24
- launchApp: async (req: LaunchAppPayload): Promise<void> => {
25
- if (!req.target) {
26
- req.target = { uuid: finUUID, name: finName, entityType: finEntityType || 'unknown' };
27
- }
28
- const client = await getChannelClient(identity);
29
- return client.dispatch(ChannelAction.LaunchApp, req);
30
- },
31
- Browser: getBrowserApi(identity),
32
- Storage: getStorageApi(identity)
33
- });
34
-
35
- return platformModule;
36
- };
package/src/index.ts DELETED
@@ -1,35 +0,0 @@
1
- import { workspaceRuntimeVersion } from '@common/utils/env';
2
-
3
- import { getWorkspacePlatformModule } from './api/workspace-module';
4
- import initBrowser from './init';
5
- import type { WorkspacePlatformInitConfig, WorkspacePlatformModule } from './shapes';
6
-
7
- export * from './shapes';
8
-
9
- const validateRuntime = async (requiredVersions: number[]): Promise<boolean> => {
10
- return new Promise<boolean>(async (resolve) => {
11
- const runtimeVersion = await fin.System.getVersion();
12
- const vbits = runtimeVersion.split('.').map((n) => parseInt(n));
13
- const valid = requiredVersions.every((n, i) => {
14
- return i < 3 ? vbits[i] === requiredVersions[i] : true;
15
- });
16
- resolve(valid);
17
- });
18
- };
19
-
20
- // TODO - pass through options and do the thing
21
- export const init = async (options: WorkspacePlatformInitConfig) => {
22
- const requiredVersions = workspaceRuntimeVersion.split('.').map((n) => parseInt(n));
23
- const validRuntime = await validateRuntime(requiredVersions);
24
- if (validRuntime) {
25
- const browserOptions = options?.browser;
26
- return initBrowser(browserOptions);
27
- } else {
28
- throw new Error(
29
- `Runtime version is not supported. ${requiredVersions[0]}.${requiredVersions[1]}.${requiredVersions[2]}.* is required`
30
- );
31
- }
32
- };
33
-
34
- export const wrapSync = (identity: OpenFin.Identity): WorkspacePlatformModule => getWorkspacePlatformModule(identity);
35
- export const getCurrentSync = (): WorkspacePlatformModule => wrapSync(fin.me.identity);
@@ -1,59 +0,0 @@
1
- import LocalStorageKey from '@common/utils/local-storage-key';
2
- import logger from '@common/utils/logger';
3
- import { isBrowserWindow, isWindowRunning } from '@common/utils/window';
4
-
5
- const log = logger('api.platform-window-focus');
6
-
7
- function saveLastFocusedBrowserWindow(identity: OpenFin.Identity) {
8
- if (typeof localStorage === 'undefined') return;
9
- try {
10
- const strLastFocused = JSON.stringify(identity);
11
- localStorage.setItem(LocalStorageKey.LastFocusedBrowserWindow, strLastFocused);
12
- } catch (err) {
13
- log.error('failed to save last focused browser window: ', err);
14
- }
15
- }
16
-
17
- /**
18
- * Get the last focused browser window.
19
- * @returns the last focused browser window.
20
- */
21
- export async function getLastFocusedBrowserWindow(): Promise<OpenFin.Identity> {
22
- if (typeof localStorage === 'undefined') return;
23
- try {
24
- const strLastFocused = localStorage.getItem(LocalStorageKey.LastFocusedBrowserWindow);
25
- const identity = JSON.parse(strLastFocused);
26
- if (await isWindowRunning(identity)) {
27
- return identity;
28
- }
29
- } catch (err) {
30
- log.error('failed to get last focused browser window: ', err);
31
- }
32
- return undefined;
33
- }
34
-
35
- /**
36
- * Set the OpenFin identity of the last focused browser window.
37
- */
38
- export function setLastFocusedBrowserWindow(identity = fin.me.identity): void {
39
- const isFocusedBrowserWindow = isBrowserWindow(identity.name);
40
- if (!isFocusedBrowserWindow) return;
41
- saveLastFocusedBrowserWindow(identity);
42
- }
43
-
44
- /**
45
- * Listen for a browser window to be focused.
46
- * When a browser window is focused, store it in local storage as the last focused browser window.
47
- */
48
- export async function listenForBrowserWindowFocus(): Promise<void> {
49
- const app = fin.Application.getCurrentSync();
50
- await app.addListener('window-focused', setLastFocusedBrowserWindow);
51
- }
52
-
53
- /**
54
- * Stop listening for a browser window to be focused.
55
- */
56
- export async function removeBrowserWindowFocusListener(): Promise<void> {
57
- const app = fin.Application.getCurrentSync();
58
- await app.removeListener('window-focused', setLastFocusedBrowserWindow);
59
- }
@@ -1,87 +0,0 @@
1
- import { ApplicationEventType, getCurrentOFApplication } from '@common/utils/application';
2
- import makeDebouncedFunc from '@common/utils/debounce';
3
- import { mapContentComponentState } from '@common/utils/layout';
4
- import logger from '@common/utils/logger';
5
- import { getCurrentOFWindow, isBrowserWindow } from '@common/utils/window';
6
-
7
- import { getOpenPages } from '../api/pages';
8
-
9
- const log = logger('api.cleanup');
10
-
11
- /** Time to debounce scheduling of views cleanup. */
12
- const viewCleanupDebounce = 2500;
13
-
14
- /** Delay before views are destroyed. */
15
- const viewCleanupDelay = 5000;
16
-
17
- /** The map of views that are scheduled for cleanup. */
18
- const viewCleanupMap: Map<string, any> = new Map();
19
-
20
- /** Get a string that represents the view's identity. */
21
- const getViewId = (identity: OpenFin.Identity) => `${identity.uuid}-${identity.name}`;
22
-
23
- async function scheduleViewCleanup() {
24
- log.debug('scheduling views to cleanup');
25
-
26
- const attachedPages = await getOpenPages();
27
-
28
- // A set of view ids that should not be cleaned up.
29
- const viewsToPreserve: Set<string> = new Set();
30
- attachedPages.forEach((page) => {
31
- // Get all the views in the page layout content.
32
- const viewStates = mapContentComponentState(page.layout.content);
33
- viewStates.forEach((viewState) => {
34
- if (viewState.name) {
35
- const viewId = getViewId(viewState);
36
-
37
- // This view is still attached to a page, and therefore must be preserved.
38
- viewsToPreserve.add(viewId);
39
- log.debug(`preserving view with id ${viewId}`);
40
- }
41
- });
42
- });
43
-
44
- const currentWin = getCurrentOFWindow();
45
-
46
- // Views that are not attached to a browser window.
47
- const inactiveViews = await currentWin.getCurrentViews();
48
-
49
- inactiveViews.forEach(({ identity }) => {
50
- const viewId = getViewId(identity);
51
- if (viewsToPreserve.has(viewId) || viewCleanupMap.has(viewId)) return;
52
-
53
- // Do not destroy view immediately. Destroying view immediately
54
- // can cause issues when dragging and dropping pages between windows.
55
- const timeoutId = setTimeout(() => {
56
- log.debug(`destroying view with id ${viewId}`);
57
- fin.View.wrapSync(identity).destroy();
58
- viewCleanupMap.delete(viewId);
59
- }, viewCleanupDelay);
60
- log.debug(`scheduled cleanup of view with id ${viewId}`);
61
- viewCleanupMap.set(viewId, timeoutId);
62
- });
63
-
64
- viewCleanupMap.forEach((v, k) => {
65
- // If a view is no longer scheduled for cleanup, clear timeout.
66
- if (viewsToPreserve.has(k)) {
67
- clearTimeout(v);
68
- viewCleanupMap.delete(k);
69
- log.debug(`cancelled scheduled cleanup of view with id ${k}`);
70
- }
71
- });
72
- }
73
-
74
- const debouncedScheduleViewCleanup = makeDebouncedFunc(scheduleViewCleanup, viewCleanupDebounce);
75
-
76
- const handleWindowEvent = ({ name }) => {
77
- if (isBrowserWindow(name)) {
78
- debouncedScheduleViewCleanup();
79
- }
80
- };
81
-
82
- export default function registerViewCleanUp() {
83
- const app = getCurrentOFApplication();
84
- app.addListener(ApplicationEventType.WindowOptionsChanged, debouncedScheduleViewCleanup);
85
- app.addListener(ApplicationEventType.WindowClosed, handleWindowEvent);
86
- app.addListener(ApplicationEventType.WindowCreated, handleWindowEvent);
87
- }
package/src/init/index.ts DELETED
@@ -1,42 +0,0 @@
1
- import { Env, env, isFin } from '@common/utils/env';
2
- import { currentOFIdentity, getCurrentOFWindow, hideAndBlur, WindowEvent } from '@common/utils/window';
3
-
4
- import { BrowserInitConfig } from '../shapes';
5
-
6
- import { listenForBrowserWindowFocus } from './browser-window-focus';
7
- import registerViewCleanUp from './cleanup';
8
- import { getOverrideCallback } from './override-callback';
9
-
10
- /**
11
- * Handle platform ready event.
12
- */
13
- async function handlePlatformReady() {
14
- registerViewCleanUp();
15
- listenForBrowserWindowFocus();
16
-
17
- if (env !== Env.Local) {
18
- const win = getCurrentOFWindow();
19
- // Ensure that the provider window is always hidden in all envs except for local dev.
20
- win.addListener(WindowEvent.ShowRequested, () => hideAndBlur(currentOFIdentity));
21
- }
22
- }
23
-
24
- let initPromise: Promise<void>;
25
-
26
- /**
27
- * Initializing the Workspace Platform.
28
- */
29
- export default function init(options: BrowserInitConfig) {
30
- if (!isFin) {
31
- throw new Error('Cannot be used outside an OpenFin env.');
32
- }
33
- if (!initPromise) {
34
- const platform = fin.Platform.getCurrentSync();
35
- platform.once('platform-api-ready', () => handlePlatformReady());
36
- initPromise = fin.Platform.init({
37
- overrideCallback: getOverrideCallback(options),
38
- interopOverride: options?.interopOverride
39
- });
40
- }
41
- return initPromise;
42
- }