Skip to content

Commit

Permalink
feat: Added code to save position of windows
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Aug 17, 2021
1 parent 3d60dab commit af07a53
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,27 @@ if (firstLaunch) {

function openOverlay() {
if (overlayWindowId == null) {
overwolf.windows.obtainDeclaredWindow("overlayWindow", (result) => {
overwolf.windows.obtainDeclaredWindow("overlayWindow", async (result) => {
if (!result.success) {
return;
}

let windowPosition = JSON.parse(
await db.getItem(`${result.window.id}-position`)
) || {
left: 30,
top: parseInt(window.screen.availHeight / 4 - 50),
};

console.log(windowPosition);

overlayWindowId = result.window.id;
overwolf.windows.restore(overlayWindowId);
overwolf.windows.changePosition(
overlayWindowId,
30,
parseInt(window.screen.availHeight / 4 - 50),
console.log
windowPosition.left,
windowPosition.top,
() => {}
);

overwolf.windows.changeSize(
Expand All @@ -203,7 +212,7 @@ if (firstLaunch) {
height: parseInt(window.screen.availHeight * 0.75),
auto_dpi_resize: false,
},
console.log
() => {}
);
});
}
Expand Down
17 changes: 15 additions & 2 deletions src/scripts/draggable-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const SIGNIFICANT_MOUSE_MOVE_THRESHOLD = 1;
*
* @param {String} window WindowId from Overwolf
* @param {HTMLElement} dragElement The element that should be draggable
* @param {String} windowName The name of the window, for saving position
*/
function DraggableWindow(window, dragElement) {
function DraggableWindow(window, dragElement, windowName) {
this.currentWindow = window;
this.initialMousePosition = 0;
this.isMouseDown = false;
Expand All @@ -30,7 +31,19 @@ function DraggableWindow(window, dragElement) {
this.isMouseDown = false;

if (this.currentWindow) {
overwolf.windows.dragMove(this.currentWindow.id);
overwolf.windows.dragMove(this.currentWindow.id, (result) => {
overwolf.windows.getCurrentWindow(async (_currentWindow) => {
if (_currentWindow.window) {
await db.setItem(
`${_currentWindow.window.id}-position`,
JSON.stringify({
left: _currentWindow.window.left,
top: _currentWindow.window.top,
})
);
}
});
});
}
};

Expand Down

0 comments on commit af07a53

Please sign in to comment.