Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ export function addRefreshableEventListener<K extends keyof HTMLElementEventMap>
* Async function constructor
*/
export const AsyncFunction = async function () {}.constructor;

export function isWebkitAppRegionCompatible() {
return ('webkitAppRegion' in document.documentElement.style)
}
37 changes: 27 additions & 10 deletions bridge/webui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/

//@ts-ignore use *.ts import real extension
import { AsyncFunction, addRefreshableEventListener } from './utils.ts';
import { AsyncFunction, addRefreshableEventListener, isWebkitAppRegionCompatible } from './utils.ts';

type DataTypes = string | number | boolean | Uint8Array;

const isWebKitAppRegionCompatible: boolean = isWebkitAppRegionCompatible();

class WebuiBridge {
// WebUI Settings
#secure: boolean;
Expand Down Expand Up @@ -171,16 +173,31 @@ class WebuiBridge {
}
if (!this.#isDragging) {
let target = e.target;
while (target) {
if (window.getComputedStyle(target).getPropertyValue("-webkit-app-region") === "drag") {
this.#initialMouseX = e.screenX;
this.#initialMouseY = e.screenY;
this.#initialWindowX = this.#currentWindowX;
this.#initialWindowY = this.#currentWindowY;
this.#isDragging = true;
break;
if (isWebKitAppRegionCompatible) {
while (target) {
if (window.getComputedStyle(target).getPropertyValue("-webkit-app-region") === "drag") {
this.#initialMouseX = e.screenX;
this.#initialMouseY = e.screenY;
this.#initialWindowX = this.#currentWindowX;
this.#initialWindowY = this.#currentWindowY;
this.#isDragging = true;
break;
}
target = target.parentElement;
}
} else {
/* To provide compatibility for browsers without `-webkit-app-region: drag;` */
while (target) {
if (target.id === "webui-draggable") {
this.#initialMouseX = e.screenX;
this.#initialMouseY = e.screenY;
this.#initialWindowX = this.#currentWindowX;
this.#initialWindowY = this.#currentWindowY;
this.#isDragging = true;
break;
}
target = target.parentElement;
}
target = target.parentElement;
}
return;
}
Expand Down
Loading