@lvce-editor/main-process 6.42.0 → 6.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5307,6 +5307,72 @@ const beep$1 = () => {
5307
5307
  shell.beep();
5308
5308
  };
5309
5309
 
5310
+ const pending = new WeakMap();
5311
+ const stop$1 = view => {
5312
+ pending.get(view)?.();
5313
+ if (!view.webContents.isDestroyed()) view.webContents.stopFindInPage('clearSelection');
5314
+ };
5315
+ const find = (view, text, forward = true, matchCase = false, newSession = true) => {
5316
+ pending.get(view)?.();
5317
+ const {
5318
+ webContents
5319
+ } = view;
5320
+ if (webContents.isDestroyed()) return Promise.resolve(undefined);
5321
+ if (!text) {
5322
+ stop$1(view);
5323
+ return Promise.resolve({
5324
+ activeMatchOrdinal: 0,
5325
+ matches: 0
5326
+ });
5327
+ }
5328
+ return new Promise((resolve, reject) => {
5329
+ let requestId = 0;
5330
+ const finish = result => {
5331
+ clearTimeout(timeout);
5332
+ webContents.off('found-in-page', onResult);
5333
+ webContents.off('did-start-navigation', onNavigation);
5334
+ webContents.off('destroyed', cancel);
5335
+ webContents.off('render-process-gone', cancel);
5336
+ pending.delete(view);
5337
+ resolve(result);
5338
+ };
5339
+ const cancel = () => finish();
5340
+ const onNavigation = (_event, _url, inPlace, mainFrame) => {
5341
+ if (mainFrame && !inPlace) cancel();
5342
+ };
5343
+ const onResult = (_event, result) => {
5344
+ if (result.requestId === requestId && result.finalUpdate) {
5345
+ finish({
5346
+ activeMatchOrdinal: result.activeMatchOrdinal,
5347
+ matches: result.matches
5348
+ });
5349
+ }
5350
+ };
5351
+ const timeout = setTimeout(cancel, 10_000);
5352
+ pending.set(view, cancel);
5353
+ webContents.on('found-in-page', onResult);
5354
+ webContents.on('did-start-navigation', onNavigation);
5355
+ webContents.once('destroyed', cancel);
5356
+ webContents.once('render-process-gone', cancel);
5357
+ try {
5358
+ // Electron maps findNext to Chromium's new_session option.
5359
+ requestId = webContents.findInPage(text, {
5360
+ findNext: newSession,
5361
+ forward,
5362
+ matchCase
5363
+ });
5364
+ } catch (error) {
5365
+ clearTimeout(timeout);
5366
+ webContents.off('found-in-page', onResult);
5367
+ webContents.off('did-start-navigation', onNavigation);
5368
+ webContents.off('destroyed', cancel);
5369
+ webContents.off('render-process-gone', cancel);
5370
+ pending.delete(view);
5371
+ reject(error instanceof Error ? error : new Error(String(error)));
5372
+ }
5373
+ });
5374
+ };
5375
+
5310
5376
  const handleTimeout = () => {
5311
5377
  throw new Error('oops');
5312
5378
  };
@@ -8030,6 +8096,8 @@ const trash = async path => {
8030
8096
  const commandMap = {
8031
8097
  'AppWindow.createAppWindow': createAppWindow,
8032
8098
  'Beep.beep': beep$1,
8099
+ 'BrowserFind.find': wrapBrowserViewCommand(find),
8100
+ 'BrowserFind.stop': wrapBrowserViewCommand(stop$1),
8033
8101
  'Crash.crashMainProcess': crashMainProcess$1,
8034
8102
  'CreateMessagePort.createMessagePort': createMessagePort,
8035
8103
  'CreatePidMap.createPidMap': createPidMap,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.42.0",
3
+ "version": "6.43.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"