Skip to content

Commit b9fbdb0

Browse files
committed
Fix "maximize" not using drag rules
1 parent 6a96e55 commit b9fbdb0

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,19 @@ export class Draggable {
279279
const isDraggable = Draggable.isDraggable(wc, input, options);
280280
if (isDraggable === false) { return; }
281281
this.setInitialPosition(dragState); // Not using input.x/y because of inconsistent values
282+
283+
if (isDraggable === true) { dragState.interval = null; return; }
282284
(async () => await isDraggable && (dragState.interval = null))();
283285
return;
284286
}
285287

286288
// Handle double-click to maximize/unmaximize
287289
if (input.clickCount === 2 && options.maximize) {
290+
const isDraggable = Draggable.isDraggable(wc, input, options);
291+
if (isDraggable === false) { return; }
288292
e.preventDefault();
289-
this.toggleMaximize();
293+
if (isDraggable === true) { this.toggleMaximize(); return; }
294+
(async () => await isDraggable && this.toggleMaximize())();
290295
}
291296
}
292297
};
@@ -311,7 +316,7 @@ export class Draggable {
311316
}
312317

313318
// eslint-disable-next-line @stylistic/max-len
314-
private static isDraggable(webContents: WebContents, point: Point, options: InternalDragOptions): false | Promise<boolean> {
319+
private static isDraggable(webContents: WebContents, point: Point, options: InternalDragOptions): boolean | Promise<boolean> {
315320
if (options.region && !Draggable.isDraggingRegion(options.region, point)) { return false; }
316321

317322
if (options.selector) {
@@ -322,7 +327,7 @@ export class Draggable {
322327
return Draggable.closest(webContents, point, options.exclude, true);
323328
}
324329

325-
return Draggable.TRUE_PROMISE;
330+
return true;
326331
}
327332

328333
private static isDraggingRegion(region: Partial<Rectangle>, point: Point): boolean {

test/sample.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { Draggable } = require('electron-draggable')
33

44
app.whenReady().then(() => {
55
const window = setupWindow();
6-
setupFindbar(window);
76
Menu.setApplicationMenu(null);
87
setupApplicationMenu(window);
98
})
@@ -21,7 +20,7 @@ function setupWindow() {
2120
view.setBounds({ x: 0, y: 0, width: 800, height: 600 });
2221
view.webContents.loadFile(`${__dirname}/sample.html`);
2322
const dragHandler = Draggable.from(window, { dragZone: { height: 100 } }).attach(view.webContents, { exclude: '.not-drag-1, button'});
24-
Draggable.create(window, { selector: '.drag-2', fps: 10 }).attach(view.webContents);
23+
Draggable.create(window, { selector: '.drag-2', fps: 10, maximize: true }).attach(view.webContents);
2524
if (dragHandler !== Draggable.from(window)) {
2625
window.destroy();
2726
throw new Error('attach did not return the Draggable instance');

0 commit comments

Comments
 (0)