mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Initial implementation (#1363)
This commit is contained in:
parent
41f0ca4e7e
commit
08198aa86b
@ -58,6 +58,7 @@ jest.mock('../src/app/window-handler', () => {
|
|||||||
jest.mock('../src/app/window-utils', () => {
|
jest.mock('../src/app/window-utils', () => {
|
||||||
return {
|
return {
|
||||||
downloadManagerAction: jest.fn(),
|
downloadManagerAction: jest.fn(),
|
||||||
|
getWindowByName: jest.fn(),
|
||||||
isValidWindow: jest.fn(() => true),
|
isValidWindow: jest.fn(() => true),
|
||||||
sanitize: jest.fn(),
|
sanitize: jest.fn(),
|
||||||
setDataUrl: jest.fn(),
|
setDataUrl: jest.fn(),
|
||||||
@ -471,17 +472,35 @@ describe('main api handler', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call `getNativeWindowHandle` correctly', () => {
|
it('should call `getNativeWindowHandle` correctly', () => {
|
||||||
const fromWebContentsMocked = {
|
const windows = {
|
||||||
getNativeWindowHandle: jest.fn(),
|
main: {
|
||||||
|
getNativeWindowHandle: jest.fn(),
|
||||||
|
},
|
||||||
|
popout1: {
|
||||||
|
getNativeWindowHandle: jest.fn(),
|
||||||
|
},
|
||||||
|
popout2: {
|
||||||
|
getNativeWindowHandle: jest.fn(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
jest.spyOn(BrowserWindow, 'fromWebContents').mockImplementation(() => {
|
jest
|
||||||
return fromWebContentsMocked;
|
.spyOn(utils, 'getWindowByName')
|
||||||
});
|
.mockImplementation((windowName: string) => {
|
||||||
const value = {
|
return windows[windowName];
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.send(apiName.symphonyApi, {
|
||||||
cmd: apiCmds.getNativeWindowHandle,
|
cmd: apiCmds.getNativeWindowHandle,
|
||||||
};
|
windowName: 'main',
|
||||||
ipcMain.send(apiName.symphonyApi, value);
|
});
|
||||||
expect(fromWebContentsMocked.getNativeWindowHandle).toBeCalledTimes(1);
|
expect(windows['main'].getNativeWindowHandle).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
ipcMain.send(apiName.symphonyApi, {
|
||||||
|
cmd: apiCmds.getNativeWindowHandle,
|
||||||
|
windowName: 'popout1',
|
||||||
|
});
|
||||||
|
expect(windows['popout1'].getNativeWindowHandle).toBeCalledTimes(1);
|
||||||
|
expect(windows['popout2'].getNativeWindowHandle).toBeCalledTimes(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,6 +31,7 @@ import { activate, handleKeyPress } from './window-actions';
|
|||||||
import { ICustomBrowserWindow, windowHandler } from './window-handler';
|
import { ICustomBrowserWindow, windowHandler } from './window-handler';
|
||||||
import {
|
import {
|
||||||
downloadManagerAction,
|
downloadManagerAction,
|
||||||
|
getWindowByName,
|
||||||
isValidView,
|
isValidView,
|
||||||
isValidWindow,
|
isValidWindow,
|
||||||
sanitize,
|
sanitize,
|
||||||
@ -419,9 +420,7 @@ ipcMain.handle(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case apiCmds.getNativeWindowHandle:
|
case apiCmds.getNativeWindowHandle:
|
||||||
const browserWin = BrowserWindow.fromWebContents(
|
const browserWin = getWindowByName(arg.windowName);
|
||||||
event.sender,
|
|
||||||
) as ICustomBrowserWindow;
|
|
||||||
if (browserWin && windowExists(browserWin)) {
|
if (browserWin && windowExists(browserWin)) {
|
||||||
const windowHandle = browserWin.getNativeWindowHandle();
|
const windowHandle = browserWin.getNativeWindowHandle();
|
||||||
return getContentWindowHandle(windowHandle);
|
return getContentWindowHandle(windowHandle);
|
||||||
|
@ -279,7 +279,10 @@
|
|||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
<p>Native Window Handle:</p>
|
<p>Native Window Handle:</p>
|
||||||
<button id="get-window-handle">Get window handle</button>
|
<button id="get-window-handle">
|
||||||
|
Get window handle (optionally enter a window name)
|
||||||
|
</button>
|
||||||
|
<input type="text" id="text-window-handle-name" />
|
||||||
<input type="text" id="text-window-handle" />
|
<input type="text" id="text-window-handle" />
|
||||||
<hr />
|
<hr />
|
||||||
<br />
|
<br />
|
||||||
@ -1200,12 +1203,15 @@
|
|||||||
.join('');
|
.join('');
|
||||||
document.getElementById('text-window-handle').value = handleStr;
|
document.getElementById('text-window-handle').value = handleStr;
|
||||||
};
|
};
|
||||||
|
const windowName = document.getElementById('text-window-handle-name')
|
||||||
|
.value;
|
||||||
if (window.ssf) {
|
if (window.ssf) {
|
||||||
window.ssf.getNativeWindowHandle().then(resultCallback);
|
window.ssf.getNativeWindowHandle(windowName).then(resultCallback);
|
||||||
} else if (window.manaSSF) {
|
} else if (window.manaSSF) {
|
||||||
window.manaSSF.getNativeWindowHandle().then(resultCallback);
|
window.manaSSF.getNativeWindowHandle(windowName).then(resultCallback);
|
||||||
} else {
|
} else {
|
||||||
postRequest(apiCmds.getNativeWindowHandle, null, {
|
postRequest(apiCmds.getNativeWindowHandle, null, {
|
||||||
|
windowName,
|
||||||
successCallback: resultCallback,
|
successCallback: resultCallback,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -737,12 +737,18 @@ export class SSFApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get native window handle of the window where the renderer is displayed
|
* Get native window handle of the window, by default where the renderer is displayed,
|
||||||
|
* or optionally another window identified by its name.
|
||||||
|
* @param windowName optional window name, defaults to current renderer window
|
||||||
* @returns the platform-specific handle of the window.
|
* @returns the platform-specific handle of the window.
|
||||||
*/
|
*/
|
||||||
public getNativeWindowHandle(): Promise<Buffer> {
|
public getNativeWindowHandle(windowName?: string): Promise<Buffer> {
|
||||||
|
if (!windowName) {
|
||||||
|
windowName = window.name || 'main';
|
||||||
|
}
|
||||||
return ipcRenderer.invoke(apiName.symphonyApi, {
|
return ipcRenderer.invoke(apiName.symphonyApi, {
|
||||||
cmd: apiCmds.getNativeWindowHandle,
|
cmd: apiCmds.getNativeWindowHandle,
|
||||||
|
windowName,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user