@lvce-editor/output-view 2.21.0 → 2.22.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.
@@ -1179,6 +1179,9 @@ const {
1179
1179
  invoke: invoke$3,
1180
1180
  set: set$4
1181
1181
  } = create$2(FileSystemWorker);
1182
+ const readDirWithFileTypes = async uri => {
1183
+ return invoke$3('FileSystem.readDirWithFileTypes', uri);
1184
+ };
1182
1185
  const readFile = async uri => {
1183
1186
  return invoke$3('FileSystem.readFile', uri);
1184
1187
  };
@@ -1210,6 +1213,9 @@ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1210
1213
  const command = 'Extensions.handleMessagePort';
1211
1214
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1212
1215
  };
1216
+ const getWindowId = async () => {
1217
+ return invoke$1('GetWindowId.getWindowId');
1218
+ };
1213
1219
  const showSaveFilePicker = async () => {
1214
1220
  return invoke$1('FilePicker.showSaveFilePicker');
1215
1221
  };
@@ -2014,6 +2020,7 @@ const initialize = async () => {
2014
2020
  };
2015
2021
 
2016
2022
  const Web = 1;
2023
+ const Electron = 2;
2017
2024
 
2018
2025
  const getSelectedItem = (selectedOption, platform) => {
2019
2026
  if (selectedOption) {
@@ -2097,12 +2104,42 @@ const getLogsDir = async () => {
2097
2104
  }
2098
2105
  };
2099
2106
 
2107
+ const legacyWindowLogFileName = 'log-window.txt';
2108
+ const isWindowLogFileName = name => {
2109
+ return /^\d+\.txt$/.test(name) || /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z\.txt$/.test(name);
2110
+ };
2111
+ const getLatestLogFileName = dirents => {
2112
+ let latest = '';
2113
+ for (const dirent of dirents) {
2114
+ if (dirent.type === 1 && isWindowLogFileName(dirent.name) && dirent.name > latest) {
2115
+ latest = dirent.name;
2116
+ }
2117
+ }
2118
+ return latest;
2119
+ };
2120
+ const getWindowLogUri = async logsFolderUri => {
2121
+ const legacyWindowLogUri = `${logsFolderUri}/${legacyWindowLogFileName}`;
2122
+ try {
2123
+ const windowId = await getWindowId();
2124
+ const windowLogsFolderUri = `${logsFolderUri}/${windowId}`;
2125
+ const dirents = await readDirWithFileTypes(windowLogsFolderUri);
2126
+ const latestLogFileName = getLatestLogFileName(dirents);
2127
+ if (latestLogFileName) {
2128
+ return `${windowLogsFolderUri}/${latestLogFileName}`;
2129
+ }
2130
+ } catch {
2131
+ return legacyWindowLogUri;
2132
+ }
2133
+ return legacyWindowLogUri;
2134
+ };
2135
+
2100
2136
  const loadOptions = async platform => {
2101
2137
  const extensionOptions = await getExtensionOptions();
2102
2138
  if (platform === Web) {
2103
2139
  return extensionOptions;
2104
2140
  }
2105
2141
  const logsFolderUri = await getLogsDir();
2142
+ const windowLogUri = platform === Electron ? await getWindowLogUri(logsFolderUri) : `${logsFolderUri}/log-window.txt`;
2106
2143
  return [{
2107
2144
  id: MainProcess,
2108
2145
  label: 'Main Process',
@@ -2114,7 +2151,7 @@ const loadOptions = async platform => {
2114
2151
  }, {
2115
2152
  id: Window,
2116
2153
  label: 'Window',
2117
- uri: `${logsFolderUri}/log-window.txt`
2154
+ uri: windowLogUri
2118
2155
  }, ...extensionOptions];
2119
2156
  };
2120
2157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",