fix: Windows' "add to hfs" failed sometimes
Massimo Melina committed
Oct 5, 2024 at 19:05 UTC
8fc45852a87f8b7653c9e95f4304da3398025bf6
1 file changed
+2
-2
src/api.vfs.ts
+2
-2
@@ -231,12 +231,12 @@ const apis: ApiHandlers = {
231
const url = h.srv!.name + '://localhost:' + h.port
232
for (const k of ['*', 'Directory']) {
233
await reg('add', WINDOWS_REG_KEY.replace('*', k), '/ve', '/f', '/d', 'Add to HFS (new)')
234
- await reg('add', WINDOWS_REG_KEY.replace('*', k) + '\\command', '/ve', '/f', '/d', `powershell -Command "
234
+ await reg('add', WINDOWS_REG_KEY.replace('*', k) + '\\command', '/ve', '/f', '/d', `powershell -WindowStyle Hidden -Command "
235
$wsh = New-Object -ComObject Wscript.Shell;
236
$j = @{parent=@'\n${parent}\n'@; source=@'\n%1\n'@} | ConvertTo-Json -Compress
237
$j = [System.Text.Encoding]::UTF8.GetBytes($j);
238
try {
239
- $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 1 -Body $j;
239
+ $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 2 -Body $j;
240
$json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard;
241
$wsh.Popup('The link is ready to be pasted');
242
} catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`)