@xiaoxionga/buzz 2.1.0 → 2.2.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.
- package/README.md +2 -2
- package/bin/buzz.js +49 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,11 +41,11 @@ Default unit is **minutes**. Add a suffix to override:
|
|
|
41
41
|
| Platform | Method | Install needed? | Admin needed? |
|
|
42
42
|
|----------|--------|:---------------:|:-------------:|
|
|
43
43
|
| **macOS** | `caffeinate -i` (built-in) | ❌ | ❌ |
|
|
44
|
-
| **Windows** |
|
|
44
|
+
| **Windows** | `SetThreadExecutionState` + mouse jiggle (built-in) | ❌ | ❌ |
|
|
45
45
|
| **Linux** | `xdotool` (pre-installed on most distros) | maybe | ❌ |
|
|
46
46
|
|
|
47
47
|
- **macOS**: Uses Apple's built-in `caffeinate` — not even a mouse jiggle, just cleanly blocks idle sleep.
|
|
48
|
-
- **Windows**:
|
|
48
|
+
- **Windows**: Triple strategy — `SetThreadExecutionState` (official Windows API, same as YouTube/PowerPoint use to prevent screen sleep) + mouse jiggle 1px every 30s + F15 keystroke as backup. Corporate lock screen policies that ignore synthetic keystrokes are handled by the real mouse movement.
|
|
49
49
|
- **Linux**: Moves mouse 1px via `xdotool`.
|
|
50
50
|
|
|
51
51
|
## Why buzz?
|
package/bin/buzz.js
CHANGED
|
@@ -37,7 +37,7 @@ USAGE:
|
|
|
37
37
|
|
|
38
38
|
PLATFORMS:
|
|
39
39
|
macOS Uses 'caffeinate' (built-in, zero install)
|
|
40
|
-
Windows Uses
|
|
40
|
+
Windows Uses SetThreadExecutionState + mouse jiggle (built-in, zero install)
|
|
41
41
|
Linux Uses xdotool (if available)
|
|
42
42
|
|
|
43
43
|
EXAMPLES:
|
|
@@ -130,19 +130,56 @@ function startCaffeinate(durationMs) {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
* Windows:
|
|
134
|
-
*
|
|
135
|
-
*
|
|
133
|
+
* Windows: triple strategy — SetThreadExecutionState + mouse jiggle + F15
|
|
134
|
+
*
|
|
135
|
+
* Many corporate Windows policies ignore synthetic keystrokes (F15).
|
|
136
|
+
* The robust approach is:
|
|
137
|
+
* 1. SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)
|
|
138
|
+
* — the official Windows API to prevent sleep (same as YouTube/PowerPoint do)
|
|
139
|
+
* 2. Move mouse 1px via .NET Cursor.Position — universally recognized as "activity"
|
|
140
|
+
* 3. F15 via SendKeys as backup
|
|
141
|
+
*
|
|
142
|
+
* All via PowerShell — zero install, zero admin.
|
|
136
143
|
*/
|
|
137
144
|
function jiggleWindows() {
|
|
138
|
-
// Single PowerShell invocation that loops every 30s
|
|
139
145
|
const psScript = `
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
# 1. Load Windows Forms for mouse control
|
|
147
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
148
|
+
|
|
149
|
+
# 2. Call SetThreadExecutionState to prevent display sleep
|
|
150
|
+
Add-Type -TypeDefinition @"
|
|
151
|
+
using System;
|
|
152
|
+
using System.Runtime.InteropServices;
|
|
153
|
+
public class PowerUtil {
|
|
154
|
+
[DllImport("kernel32.dll")]
|
|
155
|
+
public static extern uint SetThreadExecutionState(uint esFlags);
|
|
156
|
+
|
|
157
|
+
public const uint ES_CONTINUOUS = 0x80000000;
|
|
158
|
+
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
|
|
159
|
+
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
|
|
160
|
+
}
|
|
161
|
+
"@
|
|
162
|
+
|
|
163
|
+
# Prevent display from turning off and system from sleeping
|
|
164
|
+
[PowerUtil]::SetThreadExecutionState(
|
|
165
|
+
[PowerUtil]::ES_CONTINUOUS -bor [PowerUtil]::ES_SYSTEM_REQUIRED -bor [PowerUtil]::ES_DISPLAY_REQUIRED
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# 3. Loop: jiggle mouse + press F15
|
|
169
|
+
$wsh = New-Object -ComObject WScript.Shell
|
|
170
|
+
while ($true) {
|
|
171
|
+
Start-Sleep -Seconds 30
|
|
172
|
+
|
|
173
|
+
# Move mouse 1px then back — most reliable "activity" signal
|
|
174
|
+
$pos = [System.Windows.Forms.Cursor]::Position
|
|
175
|
+
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($pos.X + 1, $pos.Y)
|
|
176
|
+
Start-Sleep -Milliseconds 50
|
|
177
|
+
[System.Windows.Forms.Cursor]::Position = $pos
|
|
178
|
+
|
|
179
|
+
# Also press F15 as backup
|
|
180
|
+
try { $wsh.SendKeys('{F15}') } catch {}
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
146
183
|
// This runs as a detached child
|
|
147
184
|
const child = spawn('powershell.exe', [
|
|
148
185
|
'-NoProfile', '-NonInteractive', '-Command', psScript
|
|
@@ -234,7 +271,7 @@ function cmdRun(durationMs) {
|
|
|
234
271
|
console.log(BEE);
|
|
235
272
|
|
|
236
273
|
const platformLabel = PLATFORM === 'darwin' ? 'macOS caffeinate'
|
|
237
|
-
: PLATFORM === 'win32' ? 'Windows
|
|
274
|
+
: PLATFORM === 'win32' ? 'Windows SetThreadExecutionState + Mouse'
|
|
238
275
|
: 'Linux xdotool';
|
|
239
276
|
|
|
240
277
|
if (durationMs) {
|