feat: replace scroll-touch* with generic input-event (#35531)

This commit is contained in:
Jeremy Rose 2022-09-27 14:47:46 -05:00 committed by GitHub
parent dfb8a2d804
commit f82a863f65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 253 additions and 138 deletions

View file

@ -1,5 +1,6 @@
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron/main';
import type { BrowserWindow as BWT } from 'electron/main';
import * as deprecate from '@electron/internal/common/deprecate';
const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT };
Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype);
@ -44,6 +45,28 @@ BrowserWindow.prototype._init = function (this: BWT) {
this.on(event as any, visibilityChanged);
}
const warn = deprecate.warnOnceMessage('\'scroll-touch-{begin,end,edge}\' are deprecated and will be removed. Please use the WebContents \'input-event\' event instead.');
this.webContents.on('input-event', (_, e) => {
if (e.type === 'gestureScrollBegin') {
if (this.listenerCount('scroll-touch-begin') !== 0) {
warn();
this.emit('scroll-touch-edge');
this.emit('scroll-touch-begin');
}
} else if (e.type === 'gestureScrollUpdate') {
if (this.listenerCount('scroll-touch-edge') !== 0) {
warn();
this.emit('scroll-touch-edge');
}
} else if (e.type === 'gestureScrollEnd') {
if (this.listenerCount('scroll-touch-end') !== 0) {
warn();
this.emit('scroll-touch-edge');
this.emit('scroll-touch-end');
}
}
});
// Notify the creation of the window.
const event = process._linkedBinding('electron_browser_event').createEmpty();
app.emit('browser-window-created', event, this);