@lvce-editor/main-process 6.36.0 → 6.37.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.
@@ -7,11 +7,10 @@ import { spawn } from 'node:child_process';
7
7
  import { Console } from 'node:console';
8
8
  import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, writeFileSync, rmSync, openSync, writeSync, closeSync } from 'node:fs';
9
9
  import * as NodePath from 'node:path';
10
- import { dirname as dirname$1, join as join$1, isAbsolute } from 'node:path';
10
+ import { dirname as dirname$1, join as join$1 } from 'node:path';
11
11
  import { homedir, tmpdir } from 'node:os';
12
12
  import { readFile, mkdir, writeFile } from 'node:fs/promises';
13
13
  import { MessageChannel } from 'node:worker_threads';
14
- import { DatabaseSync } from 'node:sqlite';
15
14
 
16
15
  const scheme = 'lvce-oss';
17
16
  const applicationName = 'lvce-oss';
@@ -1647,6 +1646,12 @@ const string = value => {
1647
1646
  throw new AssertionError('expected value to be of type string');
1648
1647
  }
1649
1648
  };
1649
+ const boolean = value => {
1650
+ const type = getType(value);
1651
+ if (type !== Boolean$1) {
1652
+ throw new AssertionError('expected value to be of type boolean');
1653
+ }
1654
+ };
1650
1655
 
1651
1656
  const setExitCode = code => {
1652
1657
  number(code);
@@ -6849,6 +6854,47 @@ const disposeWebContentsView = browserViewId => {
6849
6854
  disposeWebContents(view.webContents);
6850
6855
  };
6851
6856
 
6857
+ const addCookiesToSession = async (session, cookies) => {
6858
+ let added = 0;
6859
+ let failed = 0;
6860
+ for (const cookie of cookies) {
6861
+ try {
6862
+ await session.cookies.set(cookie);
6863
+ added++;
6864
+ } catch {
6865
+ failed++;
6866
+ }
6867
+ }
6868
+ await session.cookies.flushStore();
6869
+ return {
6870
+ added,
6871
+ failed
6872
+ };
6873
+ };
6874
+ const removeCookiesFromSession = async (session, cookies) => {
6875
+ let failed = 0;
6876
+ let removed = 0;
6877
+ for (const cookie of cookies) {
6878
+ try {
6879
+ await session.cookies.remove(cookie.url, cookie.name);
6880
+ removed++;
6881
+ } catch {
6882
+ failed++;
6883
+ }
6884
+ }
6885
+ await session.cookies.flushStore();
6886
+ return {
6887
+ failed,
6888
+ removed
6889
+ };
6890
+ };
6891
+ const addCookies = cookies => {
6892
+ return addCookiesToSession(getSession(), cookies);
6893
+ };
6894
+ const removeCookies = cookies => {
6895
+ return removeCookiesFromSession(getSession(), cookies);
6896
+ };
6897
+
6852
6898
  const webContentsViewErrorPath = join(root, 'packages', 'main-process', 'pages', 'error', 'error.html');
6853
6899
 
6854
6900
  // TODO create output channel for browser view debug logs
@@ -6935,7 +6981,7 @@ const getDomTree = async view => {
6935
6981
  };
6936
6982
  const capturePage = async view => {
6937
6983
  const image = await view.webContents.capturePage();
6938
- return image.toDataURL();
6984
+ return image.toPNG();
6939
6985
  };
6940
6986
  const insertCss = async (view, code) => {
6941
6987
  const {
@@ -7067,6 +7113,10 @@ const inspectElement = (view, x, y) => {
7067
7113
  const setBackgroundColor = (view, backgroundColor) => {
7068
7114
  view.setBackgroundColor(backgroundColor);
7069
7115
  };
7116
+ const setAudioMuted = (view, muted) => {
7117
+ boolean(muted);
7118
+ view.webContents.setAudioMuted(muted);
7119
+ };
7070
7120
 
7071
7121
  /**
7072
7122
  *
@@ -7097,11 +7147,13 @@ const getStats = view => {
7097
7147
  } = view;
7098
7148
  const canGoBack = webContents.navigationHistory.canGoBack();
7099
7149
  const canGoForward = webContents.navigationHistory.canGoForward();
7150
+ const isAudioMuted = webContents.isAudioMuted();
7100
7151
  const url = webContents.getURL();
7101
7152
  const title = webContents.getTitle();
7102
7153
  return {
7103
7154
  canGoBack,
7104
7155
  canGoForward,
7156
+ isAudioMuted,
7105
7157
  title,
7106
7158
  url
7107
7159
  };
@@ -7244,228 +7296,6 @@ const open2 = async (options, url) => {
7244
7296
  }
7245
7297
  };
7246
7298
 
7247
- const getSameSite = sameSite => {
7248
- switch (sameSite) {
7249
- case 0:
7250
- return 'no_restriction';
7251
- case 1:
7252
- return 'lax';
7253
- case 2:
7254
- return 'strict';
7255
- default:
7256
- return 'unspecified';
7257
- }
7258
- };
7259
- const getUrlHost = host => {
7260
- return host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
7261
- };
7262
- const convert = (row, now = Date.now() / 1000) => {
7263
- if (!row.host || row.originAttributes) {
7264
- return undefined;
7265
- }
7266
- const host = row.host.startsWith('.') ? row.host.slice(1) : row.host;
7267
- if (!host) {
7268
- return undefined;
7269
- }
7270
- const expirationDate = row.expiry;
7271
- if (!Number.isFinite(expirationDate) || expirationDate <= now) {
7272
- return undefined;
7273
- }
7274
- const secure = Boolean(row.isSecure);
7275
- const details = {
7276
- expirationDate,
7277
- httpOnly: Boolean(row.isHttpOnly),
7278
- name: row.name,
7279
- path: row.path || '/',
7280
- sameSite: getSameSite(row.sameSite),
7281
- secure,
7282
- url: `${secure ? 'https' : 'http'}://${getUrlHost(host)}/`,
7283
- value: row.value
7284
- };
7285
- if (row.host.startsWith('.')) {
7286
- details.domain = row.host;
7287
- }
7288
- return details;
7289
- };
7290
-
7291
- /* eslint-disable n/no-unsupported-features/node-builtins -- Electron 43 provides the node:sqlite API used by the main process */
7292
- const getDatabaseError = error => {
7293
- const message = error instanceof Error ? error.message : String(error);
7294
- if (message.toLowerCase().includes('locked') || message.toLowerCase().includes('busy')) {
7295
- return new Error('Firefox cookie database is busy. Close Firefox and try again.');
7296
- }
7297
- return new Error('Failed to read the Firefox cookie database');
7298
- };
7299
- const withDatabase = (path, fn) => {
7300
- let database;
7301
- try {
7302
- database = new DatabaseSync(path, {
7303
- readOnly: true
7304
- });
7305
- database.exec('PRAGMA busy_timeout = 1000');
7306
- return fn(database);
7307
- } catch (error) {
7308
- if (error instanceof Error && error.message.startsWith('Unsupported Firefox cookie database version')) {
7309
- throw error;
7310
- }
7311
- throw getDatabaseError(error);
7312
- } finally {
7313
- database?.close();
7314
- }
7315
- };
7316
- const getVersion = database => {
7317
- const row = database.prepare('PRAGMA user_version').get();
7318
- if (row.user_version < 9) {
7319
- throw new Error(`Unsupported Firefox cookie database version ${row.user_version}`);
7320
- }
7321
- return row.user_version;
7322
- };
7323
- const getCookieCount = path => {
7324
- return withDatabase(path, database => {
7325
- getVersion(database);
7326
- const row = database.prepare('SELECT COUNT(*) AS count FROM moz_cookies').get();
7327
- return row.count;
7328
- });
7329
- };
7330
- const readCookies = path => {
7331
- return withDatabase(path, database => {
7332
- const version = getVersion(database);
7333
- const rows = database.prepare(`
7334
- SELECT
7335
- expiry,
7336
- host,
7337
- isHttpOnly,
7338
- isSecure,
7339
- name,
7340
- originAttributes,
7341
- path,
7342
- sameSite,
7343
- value
7344
- FROM moz_cookies
7345
- `).all();
7346
- return {
7347
- rows,
7348
- version
7349
- };
7350
- });
7351
- };
7352
-
7353
- const parseIni = content => {
7354
- const sections = {};
7355
- let section;
7356
- for (const line of content.split(/\r?\n/)) {
7357
- const trimmed = line.trim();
7358
- const sectionMatch = /^\[([^\]]+)\]$/.exec(trimmed);
7359
- if (sectionMatch) {
7360
- section = {};
7361
- sections[sectionMatch[1]] = section;
7362
- } else if (section && trimmed && !trimmed.startsWith(';') && !trimmed.startsWith('#')) {
7363
- const separatorIndex = trimmed.indexOf('=');
7364
- if (separatorIndex !== -1) {
7365
- section[trimmed.slice(0, separatorIndex)] = trimmed.slice(separatorIndex + 1);
7366
- }
7367
- }
7368
- }
7369
- return sections;
7370
- };
7371
- const getProfilePath = (firefoxDataDirectory, profile) => {
7372
- if (profile.IsRelative === '0' || isAbsolute(profile.Path)) {
7373
- return profile.Path;
7374
- }
7375
- return join$1(firefoxDataDirectory, profile.Path);
7376
- };
7377
- const getFirefoxDataDirectory = () => {
7378
- const homeDirectory = homedir();
7379
- if (process.platform === 'win32') {
7380
- const applicationDataDirectory = process.env.APPDATA || join$1(homeDirectory, 'AppData', 'Roaming');
7381
- return join$1(applicationDataDirectory, 'Mozilla', 'Firefox');
7382
- }
7383
- if (process.platform === 'darwin') {
7384
- return join$1(homeDirectory, 'Library', 'Application Support', 'Firefox');
7385
- }
7386
- const candidates = [join$1(homeDirectory, '.mozilla', 'firefox'), join$1(homeDirectory, 'snap', 'firefox', 'common', '.mozilla', 'firefox'), join$1(homeDirectory, '.var', 'app', 'org.mozilla.firefox', '.mozilla', 'firefox')];
7387
- const directory = candidates.find(candidate => existsSync(join$1(candidate, 'profiles.ini')));
7388
- return directory || candidates[0];
7389
- };
7390
- const getActiveProfile = firefoxDataDirectory => {
7391
- const profilesPath = join$1(firefoxDataDirectory, 'profiles.ini');
7392
- if (!existsSync(profilesPath)) {
7393
- throw new Error(`Firefox profile data was not found at ${firefoxDataDirectory}`);
7394
- }
7395
- let sections;
7396
- try {
7397
- sections = parseIni(readFileSync(profilesPath, 'utf8'));
7398
- } catch {
7399
- throw new Error('Firefox profile metadata is invalid');
7400
- }
7401
- const profiles = Object.entries(sections).filter(([sectionName, profile]) => sectionName.startsWith('Profile') && profile.Path);
7402
- const installs = Object.entries(sections).filter(([sectionName, install]) => sectionName.startsWith('Install') && install.Default);
7403
- const installDefault = (installs.find(([, install]) => install.Locked === '1') || installs[0])?.[1].Default;
7404
- const selected = profiles.find(([, profile]) => profile.Path === installDefault) || profiles.find(([, profile]) => profile.Default === '1') || profiles[0];
7405
- if (!selected) {
7406
- throw new Error('Firefox profile metadata does not contain a profile');
7407
- }
7408
- const [, profile] = selected;
7409
- const profilePath = getProfilePath(firefoxDataDirectory, profile);
7410
- const cookieDatabasePath = join$1(profilePath, 'cookies.sqlite');
7411
- if (!existsSync(cookieDatabasePath)) {
7412
- throw new Error(`Firefox cookie database was not found for profile ${profile.Path}`);
7413
- }
7414
- return {
7415
- cookieDatabasePath,
7416
- directory: profile.Path,
7417
- name: profile.Name || profile.Path
7418
- };
7419
- };
7420
-
7421
- const getInfoFromDirectory = firefoxDataDirectory => {
7422
- const profile = getActiveProfile(firefoxDataDirectory);
7423
- const cookieCount = getCookieCount(profile.cookieDatabasePath);
7424
- return {
7425
- cookieCount,
7426
- profileDirectory: profile.directory,
7427
- profileName: profile.name
7428
- };
7429
- };
7430
- const getInfo = () => {
7431
- return getInfoFromDirectory(getFirefoxDataDirectory());
7432
- };
7433
- const importFromDirectory = async (firefoxDataDirectory, session) => {
7434
- const profile = getActiveProfile(firefoxDataDirectory);
7435
- const {
7436
- rows
7437
- } = readCookies(profile.cookieDatabasePath);
7438
- const cookies = [];
7439
- let skipped = 0;
7440
- for (const row of rows) {
7441
- const cookie = convert(row);
7442
- if (cookie) {
7443
- cookies.push(cookie);
7444
- } else {
7445
- skipped++;
7446
- }
7447
- }
7448
- let imported = 0;
7449
- let failed = 0;
7450
- for (const cookie of cookies) {
7451
- try {
7452
- await session.cookies.set(cookie);
7453
- imported++;
7454
- } catch {
7455
- failed++;
7456
- }
7457
- }
7458
- await session.cookies.flushStore();
7459
- return {
7460
- failed,
7461
- imported,
7462
- skipped
7463
- };
7464
- };
7465
- const importCookies = async () => {
7466
- return importFromDirectory(getFirefoxDataDirectory(), getSession());
7467
- };
7468
-
7469
7299
  const getWindowId = webContentsId => {
7470
7300
  number(webContentsId);
7471
7301
  const webContents = Electron.webContents.fromId(webContentsId);
@@ -7789,10 +7619,12 @@ const commandMap = {
7789
7619
  'ElectronWebContents.dispose': dispose$1,
7790
7620
  'ElectronWebContents.getStats': getStats$1,
7791
7621
  'ElectronWebContentsView.acceptLogin': accept,
7622
+ 'ElectronWebContentsView.addCookies': addCookies,
7792
7623
  'ElectronWebContentsView.attachEventListeners': attachEventListeners,
7793
7624
  'ElectronWebContentsView.cancelLogin': cancel,
7794
7625
  'ElectronWebContentsView.createWebContentsView': createWebContentsView,
7795
7626
  'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
7627
+ 'ElectronWebContentsView.removeCookies': removeCookies,
7796
7628
  'ElectronWebContentsViewFunctions.addToWindow': addToWindow,
7797
7629
  'ElectronWebContentsViewFunctions.backward': wrapBrowserViewCommand(backward),
7798
7630
  'ElectronWebContentsViewFunctions.cancelNavigation': wrapBrowserViewCommand(cancelNavigation),
@@ -7811,6 +7643,7 @@ const commandMap = {
7811
7643
  'ElectronWebContentsViewFunctions.openDevtools': wrapBrowserViewCommand(openDevtools),
7812
7644
  'ElectronWebContentsViewFunctions.reload': wrapBrowserViewCommand(reload),
7813
7645
  'ElectronWebContentsViewFunctions.resizeBrowserView': wrapBrowserViewCommand(resizeBrowserView),
7646
+ 'ElectronWebContentsViewFunctions.setAudioMuted': wrapBrowserViewCommand(setAudioMuted),
7814
7647
  'ElectronWebContentsViewFunctions.setBackgroundColor': wrapBrowserViewCommand(setBackgroundColor),
7815
7648
  'ElectronWebContentsViewFunctions.setFallthroughKeyBindings': wrapBrowserViewCommand(setFallThroughKeyBindings),
7816
7649
  'ElectronWebContentsViewFunctions.setIframeSrc': wrapBrowserViewCommand(setIframeSrc),
@@ -7823,8 +7656,6 @@ const commandMap = {
7823
7656
  'ElectronWindowGpuInfo.open': open,
7824
7657
  'ElectronWindowProcessExplorer.open2': open2,
7825
7658
  'Exit.exit': exit,
7826
- 'FirefoxCookieImport.getInfo': getInfo,
7827
- 'FirefoxCookieImport.importCookies': importCookies,
7828
7659
  'GetWindowId.getWindowId': getWindowId,
7829
7660
  'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
7830
7661
  'IpcParent.create': create$1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.36.0",
3
+ "version": "6.37.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"