Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
RUN-4065 disable frame unhook (#444)
Browse files Browse the repository at this point in the history
* RUN-4065 Make sure we unhook disable frame on a clean event

* some cleanup items.

* no one saw that.

* Handle the case of enabling the frame via the API.

* code review items
  • Loading branch information
rdepena authored and datamadic committed Jun 29, 2018
1 parent b502f20 commit f150996
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/browser/api/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const WindowsMessages = {
};

let Window = {};
const disabledFrameRef = new Map();

let browserWindowEventMap = {
'api-injection-failed': {
Expand Down Expand Up @@ -144,6 +145,10 @@ let webContentsEventMap = {
}
};

function genWindowKey(identity) {
return `${identity.uuid}-${identity.name}`;
}

/*
For the bounds stuff, looks like 5.0 does not take actions until the
window moves or has a resizing event. that is the same here. in the
Expand Down Expand Up @@ -1076,14 +1081,29 @@ Window.close = function(identity, force, callback = () => {}) {
handleForceActions(identity, force, 'close-requested', payload, defaultAction);
};

function disabledFrameUnsubDecorator(identity) {
const windowKey = genWindowKey(identity);
return function() {
let refCount = disabledFrameRef.get(windowKey) || 0;
if (refCount > 1) {
disabledFrameRef.set(windowKey, --refCount);
} else {
Window.enableFrame(identity);
}
};
}

Window.disableFrame = function(identity) {
let browserWindow = getElectronBrowserWindow(identity);
Window.disableFrame = function(requestorIdentity, windowIdentity) {
const browserWindow = getElectronBrowserWindow(windowIdentity);
const windowKey = genWindowKey(windowIdentity);

if (!browserWindow) {
return;
}

let dframeRefCount = disabledFrameRef.get(windowKey) || 0;
disabledFrameRef.set(windowKey, ++dframeRefCount);
subscriptionManager.registerSubscription(disabledFrameUnsubDecorator(windowIdentity), requestorIdentity, `disable-frame-${windowKey}`);
browserWindow.setUserMovementEnabled(false);
};

Expand All @@ -1110,12 +1130,14 @@ Window.embed = function(identity, parentHwnd) {
};

Window.enableFrame = function(identity) {
const windowKey = genWindowKey(identity);
let browserWindow = getElectronBrowserWindow(identity);

if (!browserWindow) {
return;
}

let dframeRefCount = disabledFrameRef.get(windowKey) || 0;
disabledFrameRef.set(windowKey, --dframeRefCount);
browserWindow.setUserMovementEnabled(true);
};

Expand Down
2 changes: 1 addition & 1 deletion src/browser/api_protocol/api_handlers/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function disableWindowFrame(identity, message, ack) {
var payload = message.payload,
windowIdentity = apiProtocolBase.getTargetWindowIdentity(payload);

Window.disableFrame(windowIdentity);
Window.disableFrame(identity, windowIdentity);
ack(successAck);
}

Expand Down

0 comments on commit f150996

Please sign in to comment.