Skip to content

Commit

Permalink
#36 #11 tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
iscander01 committed Oct 14, 2021
1 parent 054075c commit c63fd1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/app/core/NotificationManager.ts
Expand Up @@ -65,6 +65,10 @@ export default class NotificationManager {
}
}

closeTab(tabId) {
this.platform.closeTab(tabId);
}

private async getPopup() {
const windows = await this.platform.getAllWindows();
return this.getPopupIn(windows);
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/WasmWallet.ts
Expand Up @@ -44,7 +44,7 @@ export default class WasmWallet {
private contractInfoHandlerCallback;

// TODO:BRO map [url->app]
private app = undefined;
private apps = {};

static getInstance() {
if (this.instance != null) {
Expand Down Expand Up @@ -384,16 +384,16 @@ export default class WasmWallet {
// TODO:BRO handle error in Utils.js
}
try {
this.app = new DnodeApp();
await this.app.createAppAPI(
this.apps[params.appurl] = new DnodeApp();
await this.apps[params.appurl].createAppAPI(
WasmWallet.getInstance(),
params.apiver,
params.apivermin,
params.appname,
params.appurl,
);
const portStream = new PortStream(NotificationManager.getPort());
this.app.connectPage(portStream, params.appurl);
this.apps[params.appurl].connectPage(portStream, params.appurl);
notificationPort.postMessage({
result: true,
});
Expand Down
7 changes: 7 additions & 0 deletions src/background.ts
Expand Up @@ -19,6 +19,7 @@ const openBeamTabsIDs = {};
let port = null;
let contentPort = null;
let connected = false;
let activeTab = null;

let uiIsTriggering = false;
let notification = null;
Expand Down Expand Up @@ -89,6 +90,9 @@ function handleConnect(remote) {

port.onDisconnect.addListener(() => {
connected = false;
if (!isNil(activeTab)) {
notificationManager.closeTab(activeTab);
}
});

port.onMessage.addListener(({ id, method, params }: RemoteRequest) => {
Expand All @@ -103,6 +107,9 @@ function handleConnect(remote) {
break;
}
case Environment.NOTIFICATION: {
const tabId = remote.sender.tab.id;
openBeamTabsIDs[tabId] = true;
activeTab = remote.sender.tab.id;
wallet.init(postMessage, notification);
break;
}
Expand Down

0 comments on commit c63fd1c

Please sign in to comment.