Skip to content

Commit 97b154f

Browse files
committed
refactor: tighten legacy patch guards and centralize dmg defaults
1 parent a0edd32 commit 97b154f

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

.github/workflows/build-desktop-tauri.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,6 @@ jobs:
283283
# Only retry on known transient DMG detach failures.
284284
retry_pattern='hdiutil: detach:.*(timeout|not detached)|DiskArbitration expired'
285285
cleanup_script="scripts/ci/cleanup-dmg.sh"
286-
export ASTRBOT_DESKTOP_MACOS_DETACH_ATTEMPTS="${ASTRBOT_DESKTOP_MACOS_DETACH_ATTEMPTS:-3}"
287-
export ASTRBOT_DESKTOP_MACOS_DETACH_SLEEP_SECONDS="${ASTRBOT_DESKTOP_MACOS_DETACH_SLEEP_SECONDS:-2}"
288-
export ASTRBOT_DESKTOP_MACOS_RW_DMG_IMAGE_PREFIX="${ASTRBOT_DESKTOP_MACOS_RW_DMG_IMAGE_PREFIX:-/src-tauri/target/}"
289-
export ASTRBOT_DESKTOP_MACOS_RW_DMG_IMAGE_SUFFIX_REGEX="${ASTRBOT_DESKTOP_MACOS_RW_DMG_IMAGE_SUFFIX_REGEX:-/bundle/macos/rw\\..*\\.dmg$}"
290-
export ASTRBOT_DESKTOP_MACOS_RW_DMG_MOUNT_REGEX="${ASTRBOT_DESKTOP_MACOS_RW_DMG_MOUNT_REGEX:-^/Volumes/(dmg\\.|rw\\.|dmg-|rw-).*}"
291-
export ASTRBOT_DESKTOP_MACOS_ALLOW_GLOBAL_HELPER_KILL="${ASTRBOT_DESKTOP_MACOS_ALLOW_GLOBAL_HELPER_KILL:-0}"
292286
log_file=""
293287
if [ ! -f "${cleanup_script}" ]; then
294288
echo "Missing DMG cleanup script: ${cleanup_script}" >&2
@@ -304,7 +298,7 @@ jobs:
304298
trap cleanup_log_file EXIT
305299
306300
cleanup_stale_dmg_state() {
307-
bash "${cleanup_script}" || true
301+
bash "${cleanup_script}"
308302
}
309303
310304
while [ "${attempt}" -le "${max_attempts}" ]; do

scripts/ci/cleanup-dmg.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ if [ -n "${ASTRBOT_DESKTOP_MACOS_WORKSPACE_ROOT:-}" ]; then
6161
elif [ -n "${GITHUB_WORKSPACE:-}" ]; then
6262
workspace_root="${GITHUB_WORKSPACE}"
6363
else
64-
fail_or_skip_workspace_root \
65-
"ASTRBOT_DESKTOP_MACOS_WORKSPACE_ROOT is required outside GitHub Actions" || exit 1
64+
if ! fail_or_skip_workspace_root \
65+
"ASTRBOT_DESKTOP_MACOS_WORKSPACE_ROOT is required outside GitHub Actions"; then
66+
exit 1
67+
fi
6668
exit 0
6769
fi
6870
workspace_root="${workspace_root%/}"
6971
if [ -z "${workspace_root}" ] || [ ! -d "${workspace_root}" ]; then
70-
fail_or_skip_workspace_root "workspace root is invalid (${workspace_root})" || exit 1
72+
if ! fail_or_skip_workspace_root "workspace root is invalid (${workspace_root})"; then
73+
exit 1
74+
fi
7175
exit 0
7276
fi
7377

@@ -278,5 +282,9 @@ cleanup_stale_dmg_state() {
278282
fi
279283
}
280284

281-
cleanup_stale_dmg_state || true
285+
if ! cleanup_stale_dmg_state; then
286+
if [ "${strict_workspace_root}" = "1" ]; then
287+
exit 1
288+
fi
289+
fi
282290
exit 0

scripts/prepare-resources.mjs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ const patchMonacoCssNestingWarnings = async (dashboardDir) => {
210210
};
211211

212212
const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
213-
const patchFile = async (filePath, transform, patchLabel) => {
213+
const patchFile = async (filePath, transform, patchLabel, options = {}) => {
214+
const { warnOnNoChange = false } = options;
214215
if (!existsSync(filePath)) {
215216
return;
216217
}
@@ -221,48 +222,55 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
221222
console.log(
222223
`[prepare-resources] Patched ${patchLabel} in ${path.relative(projectRoot, filePath)}`,
223224
);
225+
} else if (warnOnNoChange) {
226+
console.warn(
227+
`[prepare-resources] WARN: No changes applied for ${patchLabel} in ${path.relative(projectRoot, filePath)}`,
228+
);
224229
}
225230
};
226231

227232
await patchFile(
228233
path.join(dashboardDir, 'src', 'App.vue'),
229234
(source) =>
230235
source.replace(
231-
/if\s*\(!desktopBridge\?\.\w+\s*\|\|\s*!desktopBridge\.onTrayRestartBackend\)\s*\{/,
236+
/if\s*\(\s*!desktopBridge\?\.isElectron\s*\|\|\s*!desktopBridge\.onTrayRestartBackend\s*\)\s*\{/,
232237
'if (!desktopBridge?.onTrayRestartBackend) {',
233238
),
234239
'tray restart desktop guard',
240+
{ warnOnNoChange: true },
235241
);
236242

237243
await patchFile(
238244
path.join(dashboardDir, 'src', 'types', 'electron-bridge.d.ts'),
239245
(source) => {
240246
let patched = source;
241-
patched = patched.replace(/^\s+is\w+:\s*boolean;\n/m, ' isDesktop: boolean;\n');
247+
patched = patched.replace(/^\s+isElectron:\s*boolean;\n/m, ' isDesktop: boolean;\n');
242248
patched = patched.replace(
243-
/^\s+is\w+Runtime:\s*\(\)\s*=>\s*Promise<boolean>;\n/m,
249+
/^\s+isElectronRuntime:\s*\(\)\s*=>\s*Promise<boolean>;\n/m,
244250
' isDesktopRuntime: () => Promise<boolean>;\n',
245251
);
246252
return patched;
247253
},
248254
'desktop bridge type definitions',
255+
{ warnOnNoChange: true },
249256
);
250257

251258
await patchFile(
252259
path.join(dashboardDir, 'src', 'layouts', 'full', 'vertical-header', 'VerticalHeader.vue'),
253260
(source) => {
254-
let patched = source.replaceAll(/\bis\w+App\b/g, 'isDesktopReleaseMode');
261+
let patched = source.replaceAll(/\bisElectronApp\b/g, 'isDesktopReleaseMode');
255262
patched = patched.replace(
256-
/typeof window !== 'undefined'\s*&&\s*!!window\.astrbotDesktop\?\.\w+/,
263+
/typeof window !== 'undefined'\s*&&\s*!!window\.astrbotDesktop\?\.isElectron/,
257264
'false',
258265
);
259266
patched = patched.replace(
260-
/isDesktopReleaseMode\.value\s*=\s*!!window\.astrbotDesktop\?\.\w+\s*\|\|\s*\n\s*!!\(await window\.astrbotDesktop\?\.\w+\?\.\(\)\);/,
267+
/isDesktopReleaseMode\.value\s*=\s*!!window\.astrbotDesktop\?\.isElectron\s*\|\|\s*\n\s*!!\(await window\.astrbotDesktop\?\.isElectronRuntime\?\.\(\)\);/,
261268
'isDesktopReleaseMode.value = false;',
262269
);
263270
return patched;
264271
},
265272
'desktop update mode guards',
273+
{ warnOnNoChange: true },
266274
);
267275

268276
await patchFile(
@@ -272,7 +280,7 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
272280
return source;
273281
}
274282
return source.replace(
275-
/if\s*\(desktopBridge\?\.\w+\)\s*\{/,
283+
/if\s*\(\s*desktopBridge\?\.isElectron\s*\)\s*\{/,
276284
`const hasDesktopRestartCapability =
277285
!!desktopBridge &&
278286
typeof desktopBridge.restartBackend === 'function' &&
@@ -291,6 +299,7 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
291299
);
292300
},
293301
'desktop restart capability guard',
302+
{ warnOnNoChange: true },
294303
);
295304
};
296305

0 commit comments

Comments
 (0)