mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Fix popup reassigning and popupClose shim message
This commit is contained in:
@@ -327,6 +327,7 @@ browser.menus.onClicked.addListener(async (info, tab) => {
|
|||||||
|
|
||||||
let popupWinId;
|
let popupWinId;
|
||||||
let popupShimId;
|
let popupShimId;
|
||||||
|
let popupPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates popup window for cast destination selection.
|
* Creates popup window for cast destination selection.
|
||||||
@@ -381,31 +382,19 @@ async function openPopup (shimId) {
|
|||||||
// Track popup close
|
// Track popup close
|
||||||
browser.windows.onRemoved.addListener(id => {
|
browser.windows.onRemoved.addListener(id => {
|
||||||
if (id === popupWinId) {
|
if (id === popupWinId) {
|
||||||
messageRouter.handleMessage({
|
shimMap.get(popupShimId).port.postMessage({
|
||||||
subject: "popupClosed"
|
subject: "popupClosed"
|
||||||
});
|
});
|
||||||
|
|
||||||
popupWinId = null;
|
popupWinId = null;
|
||||||
popupShimId = null;
|
popupShimId = null;
|
||||||
|
popupPort = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const shimMap = new Map();
|
const shimMap = new Map();
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(message => {
|
|
||||||
if (message.subject === "getPopupShimInfo") {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const { tabId, frameId } = shimMap.get(popupShimId);
|
|
||||||
|
|
||||||
resolve({
|
|
||||||
tabId
|
|
||||||
, frameId
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onConnectShim (port) {
|
async function onConnectShim (port) {
|
||||||
const bridgeInfo = await getBridgeInfo();
|
const bridgeInfo = await getBridgeInfo();
|
||||||
if (bridgeInfo && !bridgeInfo.isVersionCompatible) {
|
if (bridgeInfo && !bridgeInfo.isVersionCompatible) {
|
||||||
@@ -470,6 +459,16 @@ async function onConnectShim (port) {
|
|||||||
* otherwise create a new popup.
|
* otherwise create a new popup.
|
||||||
*/
|
*/
|
||||||
if (popupWinId) {
|
if (popupWinId) {
|
||||||
|
|
||||||
|
// Reassign popup to new shim
|
||||||
|
popupPort.postMessage({
|
||||||
|
subject: "assignPopup"
|
||||||
|
, data: {
|
||||||
|
tabId
|
||||||
|
, frameId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify shim that existing popup has closed and
|
* Notify shim that existing popup has closed and
|
||||||
* to re-populate receiver list for new popup.
|
* to re-populate receiver list for new popup.
|
||||||
@@ -505,12 +504,27 @@ async function onConnectShim (port) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onConnectPopup (port) {
|
||||||
|
if (popupPort) {
|
||||||
|
popupPort.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
popupPort = port;
|
||||||
|
|
||||||
|
const { tabId, frameId } = shimMap.get(popupShimId);
|
||||||
|
port.postMessage({
|
||||||
|
subject: "assignPopup"
|
||||||
|
, data: {
|
||||||
|
tabId
|
||||||
|
, frameId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
browser.runtime.onConnect.addListener(port => {
|
browser.runtime.onConnect.addListener(port => {
|
||||||
switch (port.name) {
|
switch (port.name) {
|
||||||
case "shim": {
|
case "shim": onConnectShim(port); break;
|
||||||
onConnectShim(port);
|
case "popup": onConnectPopup(port); break;
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount () {
|
async setPort (shimTabId, shimFrameId) {
|
||||||
const { tabId, frameId } = await browser.runtime.sendMessage({
|
if (this.port) {
|
||||||
subject: "getPopupShimInfo"
|
this.port.disconnect();
|
||||||
});
|
}
|
||||||
|
|
||||||
this.port = browser.tabs.connect(tabId, {
|
this.port = browser.tabs.connect(shimTabId, {
|
||||||
name: "popup"
|
name: "popup"
|
||||||
, frameId
|
, frameId: shimFrameId
|
||||||
});
|
});
|
||||||
|
|
||||||
this.port.postMessage({
|
this.port.postMessage({
|
||||||
@@ -84,6 +84,19 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
const backgroundPort = browser.runtime.connect({
|
||||||
|
name: "popup"
|
||||||
|
});
|
||||||
|
|
||||||
|
backgroundPort.onMessage.addListener(message => {
|
||||||
|
if (message.subject === "assignPopup") {
|
||||||
|
this.setPort(message.data.tabId
|
||||||
|
, message.data.frameId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onCast (receiver) {
|
onCast (receiver) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoading: true
|
isLoading: true
|
||||||
|
|||||||
Reference in New Issue
Block a user