@lvce-editor/main-process 6.36.1 → 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';
@@ -6855,6 +6854,47 @@ const disposeWebContentsView = browserViewId => {
6855
6854
  disposeWebContents(view.webContents);
6856
6855
  };
6857
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
+
6858
6898
  const webContentsViewErrorPath = join(root, 'packages', 'main-process', 'pages', 'error', 'error.html');
6859
6899
 
6860
6900
  // TODO create output channel for browser view debug logs
@@ -6941,7 +6981,7 @@ const getDomTree = async view => {
6941
6981
  };
6942
6982
  const capturePage = async view => {
6943
6983
  const image = await view.webContents.capturePage();
6944
- return image.toDataURL();
6984
+ return image.toPNG();
6945
6985
  };
6946
6986
  const insertCss = async (view, code) => {
6947
6987
  const {
@@ -7256,228 +7296,6 @@ const open2 = async (options, url) => {
7256
7296
  }
7257
7297
  };
7258
7298
 
7259
- const getSameSite = sameSite => {
7260
- switch (sameSite) {
7261
- case 0:
7262
- return 'no_restriction';
7263
- case 1:
7264
- return 'lax';
7265
- case 2:
7266
- return 'strict';
7267
- default:
7268
- return 'unspecified';
7269
- }
7270
- };
7271
- const getUrlHost = host => {
7272
- return host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
7273
- };
7274
- const convert = (row, now = Date.now() / 1000) => {
7275
- if (!row.host || row.originAttributes) {
7276
- return undefined;
7277
- }
7278
- const host = row.host.startsWith('.') ? row.host.slice(1) : row.host;
7279
- if (!host) {
7280
- return undefined;
7281
- }
7282
- const expirationDate = row.expiry;
7283
- if (!Number.isFinite(expirationDate) || expirationDate <= now) {
7284
- return undefined;
7285
- }
7286
- const secure = Boolean(row.isSecure);
7287
- const details = {
7288
- expirationDate,
7289
- httpOnly: Boolean(row.isHttpOnly),
7290
- name: row.name,
7291
- path: row.path || '/',
7292
- sameSite: getSameSite(row.sameSite),
7293
- secure,
7294
- url: `${secure ? 'https' : 'http'}://${getUrlHost(host)}/`,
7295
- value: row.value
7296
- };
7297
- if (row.host.startsWith('.')) {
7298
- details.domain = row.host;
7299
- }
7300
- return details;
7301
- };
7302
-
7303
- /* eslint-disable n/no-unsupported-features/node-builtins -- Electron 43 provides the node:sqlite API used by the main process */
7304
- const getDatabaseError = error => {
7305
- const message = error instanceof Error ? error.message : String(error);
7306
- if (message.toLowerCase().includes('locked') || message.toLowerCase().includes('busy')) {
7307
- return new Error('Firefox cookie database is busy. Close Firefox and try again.');
7308
- }
7309
- return new Error('Failed to read the Firefox cookie database');
7310
- };
7311
- const withDatabase = (path, fn) => {
7312
- let database;
7313
- try {
7314
- database = new DatabaseSync(path, {
7315
- readOnly: true
7316
- });
7317
- database.exec('PRAGMA busy_timeout = 1000');
7318
- return fn(database);
7319
- } catch (error) {
7320
- if (error instanceof Error && error.message.startsWith('Unsupported Firefox cookie database version')) {
7321
- throw error;
7322
- }
7323
- throw getDatabaseError(error);
7324
- } finally {
7325
- database?.close();
7326
- }
7327
- };
7328
- const getVersion = database => {
7329
- const row = database.prepare('PRAGMA user_version').get();
7330
- if (row.user_version < 9) {
7331
- throw new Error(`Unsupported Firefox cookie database version ${row.user_version}`);
7332
- }
7333
- return row.user_version;
7334
- };
7335
- const getCookieCount = path => {
7336
- return withDatabase(path, database => {
7337
- getVersion(database);
7338
- const row = database.prepare('SELECT COUNT(*) AS count FROM moz_cookies').get();
7339
- return row.count;
7340
- });
7341
- };
7342
- const readCookies = path => {
7343
- return withDatabase(path, database => {
7344
- const version = getVersion(database);
7345
- const rows = database.prepare(`
7346
- SELECT
7347
- expiry,
7348
- host,
7349
- isHttpOnly,
7350
- isSecure,
7351
- name,
7352
- originAttributes,
7353
- path,
7354
- sameSite,
7355
- value
7356
- FROM moz_cookies
7357
- `).all();
7358
- return {
7359
- rows,
7360
- version
7361
- };
7362
- });
7363
- };
7364
-
7365
- const parseIni = content => {
7366
- const sections = {};
7367
- let section;
7368
- for (const line of content.split(/\r?\n/)) {
7369
- const trimmed = line.trim();
7370
- const sectionMatch = /^\[([^\]]+)\]$/.exec(trimmed);
7371
- if (sectionMatch) {
7372
- section = {};
7373
- sections[sectionMatch[1]] = section;
7374
- } else if (section && trimmed && !trimmed.startsWith(';') && !trimmed.startsWith('#')) {
7375
- const separatorIndex = trimmed.indexOf('=');
7376
- if (separatorIndex !== -1) {
7377
- section[trimmed.slice(0, separatorIndex)] = trimmed.slice(separatorIndex + 1);
7378
- }
7379
- }
7380
- }
7381
- return sections;
7382
- };
7383
- const getProfilePath = (firefoxDataDirectory, profile) => {
7384
- if (profile.IsRelative === '0' || isAbsolute(profile.Path)) {
7385
- return profile.Path;
7386
- }
7387
- return join$1(firefoxDataDirectory, profile.Path);
7388
- };
7389
- const getFirefoxDataDirectory = () => {
7390
- const homeDirectory = homedir();
7391
- if (process.platform === 'win32') {
7392
- const applicationDataDirectory = process.env.APPDATA || join$1(homeDirectory, 'AppData', 'Roaming');
7393
- return join$1(applicationDataDirectory, 'Mozilla', 'Firefox');
7394
- }
7395
- if (process.platform === 'darwin') {
7396
- return join$1(homeDirectory, 'Library', 'Application Support', 'Firefox');
7397
- }
7398
- 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')];
7399
- const directory = candidates.find(candidate => existsSync(join$1(candidate, 'profiles.ini')));
7400
- return directory || candidates[0];
7401
- };
7402
- const getActiveProfile = firefoxDataDirectory => {
7403
- const profilesPath = join$1(firefoxDataDirectory, 'profiles.ini');
7404
- if (!existsSync(profilesPath)) {
7405
- throw new Error(`Firefox profile data was not found at ${firefoxDataDirectory}`);
7406
- }
7407
- let sections;
7408
- try {
7409
- sections = parseIni(readFileSync(profilesPath, 'utf8'));
7410
- } catch {
7411
- throw new Error('Firefox profile metadata is invalid');
7412
- }
7413
- const profiles = Object.entries(sections).filter(([sectionName, profile]) => sectionName.startsWith('Profile') && profile.Path);
7414
- const installs = Object.entries(sections).filter(([sectionName, install]) => sectionName.startsWith('Install') && install.Default);
7415
- const installDefault = (installs.find(([, install]) => install.Locked === '1') || installs[0])?.[1].Default;
7416
- const selected = profiles.find(([, profile]) => profile.Path === installDefault) || profiles.find(([, profile]) => profile.Default === '1') || profiles[0];
7417
- if (!selected) {
7418
- throw new Error('Firefox profile metadata does not contain a profile');
7419
- }
7420
- const [, profile] = selected;
7421
- const profilePath = getProfilePath(firefoxDataDirectory, profile);
7422
- const cookieDatabasePath = join$1(profilePath, 'cookies.sqlite');
7423
- if (!existsSync(cookieDatabasePath)) {
7424
- throw new Error(`Firefox cookie database was not found for profile ${profile.Path}`);
7425
- }
7426
- return {
7427
- cookieDatabasePath,
7428
- directory: profile.Path,
7429
- name: profile.Name || profile.Path
7430
- };
7431
- };
7432
-
7433
- const getInfoFromDirectory = firefoxDataDirectory => {
7434
- const profile = getActiveProfile(firefoxDataDirectory);
7435
- const cookieCount = getCookieCount(profile.cookieDatabasePath);
7436
- return {
7437
- cookieCount,
7438
- profileDirectory: profile.directory,
7439
- profileName: profile.name
7440
- };
7441
- };
7442
- const getInfo = () => {
7443
- return getInfoFromDirectory(getFirefoxDataDirectory());
7444
- };
7445
- const importFromDirectory = async (firefoxDataDirectory, session) => {
7446
- const profile = getActiveProfile(firefoxDataDirectory);
7447
- const {
7448
- rows
7449
- } = readCookies(profile.cookieDatabasePath);
7450
- const cookies = [];
7451
- let skipped = 0;
7452
- for (const row of rows) {
7453
- const cookie = convert(row);
7454
- if (cookie) {
7455
- cookies.push(cookie);
7456
- } else {
7457
- skipped++;
7458
- }
7459
- }
7460
- let imported = 0;
7461
- let failed = 0;
7462
- for (const cookie of cookies) {
7463
- try {
7464
- await session.cookies.set(cookie);
7465
- imported++;
7466
- } catch {
7467
- failed++;
7468
- }
7469
- }
7470
- await session.cookies.flushStore();
7471
- return {
7472
- failed,
7473
- imported,
7474
- skipped
7475
- };
7476
- };
7477
- const importCookies = async () => {
7478
- return importFromDirectory(getFirefoxDataDirectory(), getSession());
7479
- };
7480
-
7481
7299
  const getWindowId = webContentsId => {
7482
7300
  number(webContentsId);
7483
7301
  const webContents = Electron.webContents.fromId(webContentsId);
@@ -7801,10 +7619,12 @@ const commandMap = {
7801
7619
  'ElectronWebContents.dispose': dispose$1,
7802
7620
  'ElectronWebContents.getStats': getStats$1,
7803
7621
  'ElectronWebContentsView.acceptLogin': accept,
7622
+ 'ElectronWebContentsView.addCookies': addCookies,
7804
7623
  'ElectronWebContentsView.attachEventListeners': attachEventListeners,
7805
7624
  'ElectronWebContentsView.cancelLogin': cancel,
7806
7625
  'ElectronWebContentsView.createWebContentsView': createWebContentsView,
7807
7626
  'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
7627
+ 'ElectronWebContentsView.removeCookies': removeCookies,
7808
7628
  'ElectronWebContentsViewFunctions.addToWindow': addToWindow,
7809
7629
  'ElectronWebContentsViewFunctions.backward': wrapBrowserViewCommand(backward),
7810
7630
  'ElectronWebContentsViewFunctions.cancelNavigation': wrapBrowserViewCommand(cancelNavigation),
@@ -7836,8 +7656,6 @@ const commandMap = {
7836
7656
  'ElectronWindowGpuInfo.open': open,
7837
7657
  'ElectronWindowProcessExplorer.open2': open2,
7838
7658
  'Exit.exit': exit,
7839
- 'FirefoxCookieImport.getInfo': getInfo,
7840
- 'FirefoxCookieImport.importCookies': importCookies,
7841
7659
  'GetWindowId.getWindowId': getWindowId,
7842
7660
  'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
7843
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.1",
3
+ "version": "6.37.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"