mirror of
https://github.com/winapps-org/winapps.git
synced 2025-09-23 17:59:34 +02:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci Signed-off-by: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com>
This commit is contained in:
![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
Oskar Manhart

parent
a04f5db39a
commit
fbb382e1e8
16
bin/winapps
16
bin/winapps
@@ -648,7 +648,7 @@ function waCheckIdle() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Name: 'waTimeSync'
|
# Name: 'waTimeSync'
|
||||||
# Role: Detect if system went to sleep by comparing uptime progression, then sync time in Windows VM
|
# Role: Detect if system went to sleep by comparing uptime progression, then sync time in Windows VM
|
||||||
function waTimeSync() {
|
function waTimeSync() {
|
||||||
local CURRENT_TIME=$(date +%s)
|
local CURRENT_TIME=$(date +%s)
|
||||||
@@ -657,31 +657,31 @@ function waTimeSync() {
|
|||||||
local STORED_UPTIME=0
|
local STORED_UPTIME=0
|
||||||
local EXPECTED_UPTIME=0
|
local EXPECTED_UPTIME=0
|
||||||
local UPTIME_DIFF=0
|
local UPTIME_DIFF=0
|
||||||
|
|
||||||
# Read stored values if file exists
|
# Read stored values if file exists
|
||||||
if [ -f "$SLEEP_DETECT_PATH" ]; then
|
if [ -f "$SLEEP_DETECT_PATH" ]; then
|
||||||
STORED_TIME=$(head -n1 "$SLEEP_DETECT_PATH" 2>/dev/null || echo 0)
|
STORED_TIME=$(head -n1 "$SLEEP_DETECT_PATH" 2>/dev/null || echo 0)
|
||||||
STORED_UPTIME=$(tail -n1 "$SLEEP_DETECT_PATH" 2>/dev/null || echo 0)
|
STORED_UPTIME=$(tail -n1 "$SLEEP_DETECT_PATH" 2>/dev/null || echo 0)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$STORED_TIME" -gt 0 ] && [ "$STORED_UPTIME" -gt 0 ]; then
|
if [ "$STORED_TIME" -gt 0 ] && [ "$STORED_UPTIME" -gt 0 ]; then
|
||||||
# Calculate what uptime should be now
|
# Calculate what uptime should be now
|
||||||
EXPECTED_UPTIME=$((STORED_UPTIME + CURRENT_TIME - STORED_TIME))
|
EXPECTED_UPTIME=$((STORED_UPTIME + CURRENT_TIME - STORED_TIME))
|
||||||
UPTIME_DIFF=$((EXPECTED_UPTIME - CURRENT_UPTIME))
|
UPTIME_DIFF=$((EXPECTED_UPTIME - CURRENT_UPTIME))
|
||||||
|
|
||||||
dprint "UPTIME_DIFF: ${UPTIME_DIFF} seconds"
|
dprint "UPTIME_DIFF: ${UPTIME_DIFF} seconds"
|
||||||
|
|
||||||
# If uptime is significantly less than expected, system likely slept
|
# If uptime is significantly less than expected, system likely slept
|
||||||
if [[ "$UPTIME_DIFF" -gt 30 && ! -f "$SLEEP_MARKER" ]]; then
|
if [[ "$UPTIME_DIFF" -gt 30 && ! -f "$SLEEP_MARKER" ]]; then
|
||||||
dprint "DETECTED SLEEP/WAKE CYCLE (uptime gap: ${UPTIME_DIFF}s). CREATING SLEEP MARKER TO SYNC WINDOWS TIME."
|
dprint "DETECTED SLEEP/WAKE CYCLE (uptime gap: ${UPTIME_DIFF}s). CREATING SLEEP MARKER TO SYNC WINDOWS TIME."
|
||||||
|
|
||||||
# Create sleep marker which will be monitored by Windows VM to trigger time sync
|
# Create sleep marker which will be monitored by Windows VM to trigger time sync
|
||||||
touch "$SLEEP_MARKER"
|
touch "$SLEEP_MARKER"
|
||||||
|
|
||||||
dprint "CREATED SLEEP MARKER"
|
dprint "CREATED SLEEP MARKER"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Store current values
|
# Store current values
|
||||||
{
|
{
|
||||||
echo "$CURRENT_TIME"
|
echo "$CURRENT_TIME"
|
||||||
|
@@ -14,7 +14,7 @@ function Monitor-File {
|
|||||||
if (Test-Path -Path $filePath) {
|
if (Test-Path -Path $filePath) {
|
||||||
# Run time resync silently
|
# Run time resync silently
|
||||||
w32tm /resync /quiet
|
w32tm /resync /quiet
|
||||||
|
|
||||||
# Remove the file
|
# Remove the file
|
||||||
Remove-Item -Path $filePath -Force
|
Remove-Item -Path $filePath -Force
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ function Monitor-File {
|
|||||||
catch {
|
catch {
|
||||||
# Network location not available, continue monitoring silently
|
# Network location not available, continue monitoring silently
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wait 5 minutes before next check
|
# Wait 5 minutes before next check
|
||||||
Start-Sleep -Seconds 3000
|
Start-Sleep -Seconds 3000
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,9 @@ set "command2=powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File \
|
|||||||
|
|
||||||
schtasks /query /tn "%taskname2%" >nul
|
schtasks /query /tn "%taskname2%" >nul
|
||||||
if %ERRORLEVEL% equ 0 (
|
if %ERRORLEVEL% equ 0 (
|
||||||
echo %DATE% %TIME% Task "%taskname2%" already exists, skipping creation.
|
echo %DATE% %TIME% Task "%taskname2%" already exists, skipping creation.
|
||||||
) else (
|
) else (
|
||||||
schtasks /create /tn "%taskname2%" /tr "%command2%" /sc onlogon /rl HIGHEST /f
|
schtasks /create /tn "%taskname2%" /tr "%command2%" /sc onlogon /rl HIGHEST /f
|
||||||
if %ERRORLEVEL% equ 0 (
|
if %ERRORLEVEL% equ 0 (
|
||||||
echo %DATE% %TIME% Scheduled task "%taskname2%" created successfully.
|
echo %DATE% %TIME% Scheduled task "%taskname2%" created successfully.
|
||||||
) else (
|
) else (
|
||||||
|
Reference in New Issue
Block a user