fix: (again) Windows integration add-to-hfs not working when only https is available #1030
Massimo Melina committed
Jul 5, 2025 at 12:20 UTC
29e945b749462be4070bbfdadd8f56e8dbade4a4
1 file changed
+3
-2
src/api.vfs.ts
+3
-2
@@ -235,12 +235,13 @@ const apis: ApiHandlers = {
235
236
async windows_integration({ parent }) {
237
const status = await getServerStatus(true)
238
- const h = status.http.listening ? status.http : status.https
238
+ const h = status.http.listening ? status.http : status.https // prefer http on localhost
239
const url = h.srv!.name + '://localhost:' + h.port
240
for (const k of ['*', 'Directory']) {
241
await reg('add', WINDOWS_REG_KEY.replace('*', k), '/ve', '/f', '/d', 'Add to HFS (new)')
242
await reg('add', WINDOWS_REG_KEY.replace('*', k), '/v', 'icon', '/f', '/d', IS_BINARY ? process.execPath : APP_PATH + '\\hfs.ico')
243
await reg('add', WINDOWS_REG_KEY.replace('*', k) + '\\command', '/ve', '/f', '/d', `powershell -WindowStyle Hidden -Command "
244
+ [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12;
245
$wsh = New-Object -ComObject Wscript.Shell;
246
$j = @{parent=@'\n${parent}\n'@; source=@'\n%1\n'@} | ConvertTo-Json -Compress
247
$j = [System.Text.Encoding]::UTF8.GetBytes($j);
@@ -249,7 +250,7 @@ const apis: ApiHandlers = {
250
$res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 2 -Body $j;
251
$json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard;
252
$wsh.Popup('The link is ready to be pasted');
252
- } catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`)
253
+ } catch { $wsh.Popup($_.Exception.Message + ' – ' + '${url}', 0, 'Error', 16); }"`)
254
}
255
return {}
256
},