mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
Refactor screenshot function to use temporary script
Refactor screenshot capture to use a temporary PowerShell script file for execution. This improves the handling of the screenshot process and ensures cleanup of temporary files.
This commit is contained in:
@@ -31,6 +31,9 @@ async function takeScreenshot(filename) {
|
|||||||
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
|
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
|
||||||
const fullPath = path.join(workspace, filename);
|
const fullPath = path.join(workspace, filename);
|
||||||
|
|
||||||
|
// Create a temporary script file path
|
||||||
|
const scriptPath = path.join(workspace, `screenshot_${Date.now()}.ps1`);
|
||||||
|
|
||||||
const psScript = `
|
const psScript = `
|
||||||
Add-Type -AssemblyName System.Windows.Forms;
|
Add-Type -AssemblyName System.Windows.Forms;
|
||||||
Add-Type -AssemblyName System.Drawing;
|
Add-Type -AssemblyName System.Drawing;
|
||||||
@@ -44,19 +47,34 @@ async function takeScreenshot(filename) {
|
|||||||
$bitmap = New-Object System.Drawing.Bitmap $Screen.Width, $Screen.Height;
|
$bitmap = New-Object System.Drawing.Bitmap $Screen.Width, $Screen.Height;
|
||||||
$graphic = [System.Drawing.Graphics]::FromImage($bitmap);
|
$graphic = [System.Drawing.Graphics]::FromImage($bitmap);
|
||||||
$graphic.CopyFromScreen($Screen.Left, $Screen.Top, 0, 0, $bitmap.Size);
|
$graphic.CopyFromScreen($Screen.Left, $Screen.Top, 0, 0, $bitmap.Size);
|
||||||
|
|
||||||
|
# Save the file (using single quotes safely now)
|
||||||
$bitmap.Save('${fullPath}');
|
$bitmap.Save('${fullPath}');
|
||||||
Write-Output "Wrote ${fullPath}";
|
Write-Output "Wrote ${fullPath}";
|
||||||
New-Item "${fullPath}.written";
|
|
||||||
|
# Specify ItemType to prevent older PS versions from prompting interactively
|
||||||
|
New-Item -Path "${fullPath}.written" -ItemType File | Out-Null;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(`powershell -Command "${psScript}"`);
|
// 1. Write the script to disk
|
||||||
|
fs.writeFileSync(scriptPath, psScript);
|
||||||
|
|
||||||
|
// 2. Execute the file directly, piping stdout/stderr to the Node console
|
||||||
|
execSync(`powershell -NoProfile -ExecutionPolicy Bypass -File "${scriptPath}"`, {
|
||||||
|
stdio: 'inherit'
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`Saved screenshot: ${fullPath}`);
|
console.log(`Saved screenshot: ${fullPath}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to save screenshot ${fullPath}:`, err.message);
|
console.error(`Failed to save screenshot ${fullPath}:`, err.message);
|
||||||
|
} finally {
|
||||||
|
// 3. Clean up the temp file so it doesn't clutter your CI artifacts
|
||||||
|
if (fs.existsSync(scriptPath)) {
|
||||||
|
fs.unlinkSync(scriptPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire and forget application launcher
|
// Fire and forget application launcher
|
||||||
function launchSSD() {
|
function launchSSD() {
|
||||||
const child = spawn('C:\\Program Files\\Certum\\SimplySign Desktop\\SimplySignDesktop.exe', [], {
|
const child = spawn('C:\\Program Files\\Certum\\SimplySign Desktop\\SimplySignDesktop.exe', [], {
|
||||||
|
|||||||
Reference in New Issue
Block a user