首页 > 解决方案 > 不同的小部件/窗口如何在 openfin 中进行通信

问题描述

与openfin一样,我们可以单独打开单独的小部件/窗口,它们如何相互通信,搜索了很多都找不到任何东西,请帮助。

标签: desktop-applicationopenfin

解决方案


您可以使用从主窗口共享上下文到其所有父视图customContext

在窗口(框架)

const me = fin.Window.getCurrentSync();
me.on('options-changed', async (event) => {
    if (event.diff.customContext) {
        const myViews = await me.getCurrentViews();
        const customContext = event.diff.customContext.newVal;
        myViews.forEach(v => {
            v.updateOptions({ customContext });
        });
    }
})

在视图中(内容)

const me = fin.View.getCurrentSync();
const broadcastContext = async (customContext) => {
    const myWindow = await me.getCurrentWindow()
    await myWindow.updateOptions({ customContext })
};
const addContextListener = async (listener) => {
    await me.on('options-changed', (event) => {
        if (event.diff.customContext) {
            listener(event.diff.customContext.newVal);
        }
    });
}

参考资料 - https://cdn.openfin.co/docs/javascript/stable/tutorial-customContext.html


推荐阅读