@lvce-editor/main-process 4.1.0 → 4.3.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.
@@ -5,10 +5,10 @@ import { fileURLToPath } from 'node:url';
5
5
  import { inspect } from 'node:util';
6
6
  import { spawn } from 'node:child_process';
7
7
  import { Console } from 'node:console';
8
- import { createWriteStream, readFileSync } from 'node:fs';
8
+ import { createWriteStream, readFileSync, existsSync } from 'node:fs';
9
9
  import { tmpdir, homedir } from 'node:os';
10
10
  import * as NodePath from 'node:path';
11
- import { dirname } from 'node:path';
11
+ import { dirname, join as join$1 } from 'node:path';
12
12
  import { MessageChannel } from 'node:worker_threads';
13
13
 
14
14
  const scheme = 'lvce-oss';
@@ -3388,6 +3388,7 @@ const xdgData = env.XDG_DATA_HOME || (homeDirectory ? join(homeDirectory, '.loca
3388
3388
  join(xdgData || tmpdir(), applicationName);
3389
3389
  const chromeUserDataPath = xdgCache ? join(xdgCache, applicationName, 'userdata') : '';
3390
3390
 
3391
+ const useIpcForResponse = true;
3391
3392
  const getSessionId = () => {
3392
3393
  return process.env.SESSION_ID || `persist:${scheme}`;
3393
3394
  };
@@ -4177,6 +4178,49 @@ const handlePermissionCheck$1 = (webContents, permission, origin, details) => {
4177
4178
  return isAllowed;
4178
4179
  };
4179
4180
 
4181
+ let config;
4182
+ const createConfig = () => {
4183
+ const configPath = join$1(root, 'config.json');
4184
+ const config = readFileSync(configPath, 'utf8');
4185
+ const parsedConfig = JSON.parse(config);
4186
+ return parsedConfig;
4187
+ };
4188
+ const getOrCreateConfig = () => {
4189
+ if (!config) {
4190
+ config = createConfig();
4191
+ }
4192
+ return config;
4193
+ };
4194
+
4195
+ const getElectronFileResponseConfig = async (url, request) => {
4196
+ const parsedConfig = getOrCreateConfig();
4197
+ const {
4198
+ files,
4199
+ headers
4200
+ } = parsedConfig;
4201
+ const relative = url.slice(scheme.length + 4);
4202
+ const actual = relative === '/' ? '/index.html' : relative;
4203
+ const match = files[actual];
4204
+ if (!match) {
4205
+ return new Response('Not Found', {
4206
+ status: 404
4207
+ });
4208
+ }
4209
+ const responseHeaders = headers[match];
4210
+ const absolutePath = join$1(root, 'static', actual);
4211
+ if (!existsSync(absolutePath)) {
4212
+ return new Response('Not Found', {
4213
+ status: 404
4214
+ });
4215
+ }
4216
+ const content = readFileSync(absolutePath, 'utf8');
4217
+ const response = new Response(content, {
4218
+ headers: responseHeaders,
4219
+ status: 200
4220
+ });
4221
+ return response;
4222
+ };
4223
+
4180
4224
  const getElectronFileResponseIpc = async (url, request) => {
4181
4225
  const {
4182
4226
  body,
@@ -4187,9 +4231,10 @@ const getElectronFileResponseIpc = async (url, request) => {
4187
4231
  };
4188
4232
 
4189
4233
  const getElectronFileResponse = async (url, request) => {
4190
- {
4234
+ if (useIpcForResponse()) {
4191
4235
  return getElectronFileResponseIpc(url, request);
4192
4236
  }
4237
+ return getElectronFileResponseConfig(url);
4193
4238
  };
4194
4239
 
4195
4240
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"