ERR_HTTP2_PROTOCOL_ERROR while using electron-updater - electron

I'm trying to test electron-updater, using a repo from github. It starts off detecting that an update is available, and then it starts downloading. But as the download starts picking up speed, this error gets triggered multiple times before the download stops altogether. Has anybody ever experienced this error before?
'Error: net::ERR_HTTP2_PROTOCOL_ERROR\n' +
' at SimpleURLLoaderWrapper. (electron/js2c/browser_init.js:105:6497)\n' +
' at SimpleURLLoaderWrapper.emit (events.js:315:20)'

Adding this alongside the autoUpdater boilerplate code seemed to do it for me (tried it twice on Windows and macOS):
app.commandLine.appendSwitch('disable-http2');
autoUpdater.requestHeaders = {'Cache-Control' : 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'};
source: https://github.com/electron-userland/electron-builder/issues/4987
Hope it works out for you too.

Related

Electron: how to close a portable app on pulling out the pendrive

I made a portable app with electron. It works fine. I have it saved in a pendrive, so I don't need to install it and copy into my hard disk to run it. Just executing the app from the pendrive I have it running in my desktop. But what I need, is implement a system that makes that if you pull out the pendrive the app automatically closes. I've been googling something similar and found many ways for using a pendrive as a master key. But that isn't exactly what I need. I don't want to shutdown the PC, I only need to close the app and remove it from memory. There is any way or nodejs library that can help me with that?
You can use node_usbspy module to watch the usb insertion/removal. This module supports only Windows.
If you receive an event with device_status as 0 then you could quit the app with app.quit()
Hope it helps you!
Note: I'm the author of node-usbspy.
I found a practical solution that could work on all platforms:
const basePath = app.getAppPath()
setInterval(() => {
const path = basePath.split('/')
const baseDir = path.slice(0, -1).join('/')
fs.writeFile(baseDir + '/portable.txt', '1', err => {
if(err) {
app.quit()
}
})
}, 1000)
The script above try to save a TXT file every second. If fs.writeFile returns an error, app.quit() is called closing the application.

WinHttpWriteData seems to be "flooding" server

I'm using WinHttpSendRequest/WinHttpWriteData to upload a large (54Mb) file to our server, sending it in 4Kb lumps to give user feedback. This has been working well, as far as I know, until recently. Now, when I try it, the upload goes very quickly and then the WinHttpReceiveResponse() call times-out and incomplete data is received by the server.
I'm using Win 8.1 64bit, IE11 11.0.15 (I think that WinHttp is updated with IE) but on my colleague's PC - same version of Windows, IE, the upload is much slower and the response doesn't time-out. When I try testing on various virtual machines, the problem isn't apparent. Other colleagues, however ... oh Windows!!
Just to be clear
As far as I am aware, this code used to work!
WinHttpOpen is called without the ASYNC flag set.
The HTTP verb is POST
The code in Delphi XE2
Result:= WinHttpSendRequest(RequestHandle,PWideChar(Headers),Length(Headers),WINHTTP_NO_REQUEST_DATA,0,FormBuffer.Size,Cardinal(Self));
If Result
then begin
BytesToWrite:= FormBuffer.Size;
while BytesToWrite > 0
do begin
If BytesToWrite > SizeOf(WriteBuffer)
then BufFill:= SizeOf(WriteBuffer)
else BufFill:= BytesToWrite;
FormBuffer.ReadBytes(WriteBuffer,BufFill); // FormBuffer is my object to supply data and headers
If WinHttpWriteData(RequestHandle,#WriteBuffer[0],BufFill,Written)
then Dec(BytesToWrite,Written)
else Error('WinHttpWriteData'); // Error() method calls GetLastError, assembles error message and logs it
If Assigned(OnDataWrite)
then OnDataWrite(Self,Written); // Event that notifies user
end;
FetchResponse(RequestHandle); // Calls WinHttpReceiveResponse() and then fetches data
Result:= True;
end
else GLE:= Error('WinHttpSendRequest');
This code was largely an adaptation of this code:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx
The "WinHttp Sample code to do a PUT." at the bottom.
It's AVG ...!
Disabling AVG gives normal performance for the upload ... now it's just a matter of finding out which part(s) are getting in the way.

Indy method HEAD takes forever if responce code is not good (200)

I am using INDY 10 with Delphi 2010 and I noticed some drawback when using method HEAD in IdHTTP component.
I want to check whether a particular file is ready for download. So I am using HEAD instead of GET to check if it's 404 or 200. The problem is that if the file is inexistent the method head takes at least couple of seconds until timeout occurs.
var
LHTTP:TIdHTTP;
begin
LHTTP:=TIdHTTP.Create(nil);
try
LHTTP.Head('http://www.google.com/inexistent');
this takes at least 15 seconds, while when I use GET method, it takes miliseconds to result in a exception 404.
EDIT: I found something in the source code:
It stucks at the line 1052 of IdHTTP.pas file:
IOHandler.ReadStream(LS, AResponse.ContentLength);
a couple of lines above there is a notice:
// RLebeau 6/30/2006: DO NOT READ IF THE REQUEST IS HEAD!!!
// The server is supposed to send a 'Content-Length' header
// without sending the actual data...
I think something is wrong here ;-)

XE5 RestClient Library issues

I have created a FMX Windows app that connects to a web server to obtain REST data. I have been using the REST Client, Response, Request and ResponseDataAdapter and have connected that to a Client Data Set. I have then connected the Datasets to a string grid through live bindings. I have done this for 2 different string grids with no problems at all, And then I come to the very last request I want to make and I am getting some very strange behaviour. I set everything up in a data module and did an execute of the RestRequest in the IDE and got the content I expected in the RESTResponse. I then activated the RESTResponseAdapter and ClientDataset. The clientdata set was populated and I was able to add the fielddefs through the ide by just going to add fields.
I have a timer setup on the app to update the string grids etc,,, Works fine for two string grids. However on the last one all I ever get on the StringGrid is the data that I originally fetched while in the IDE. I assumed this could be due to some caching on the clientdataset so I put a memo on the form and after each request execute I posted the response content to the memo.... The bizarre thing is that I occasionally get the response the server is currently sending back (Verified by going to the webserver through Chrome) but sometimes the Response Content is the data that I originally requested when I set it up in the IDE. So I went back to the IDE and cleared the response data from the Rest Response. Tried again and get the same... I get the expected result sometimes and other times I get the response that I originally got in the IDE yesterday. So then I thought perhaps the webserver was sending it back. So have run the same REST request through the webserver and never get back the data that the restresponse is showing...
The code below fires on my timer. The top two sets of code are working fine the last one is the buggy one.
restDataModule.adapterOperators.ClearDataSet;
restDataModule.cdsOperators.Close;
restDataModule.responseOperators.Content.Empty;
restDataModule.reqOnlineOperators.ClearBody;
restDataModule.reqOnlineOperators.Execute;
restDataModule.cdsOperators.Open;
restDataModule.adapterStats.ClearDataSet;
restDataModule.cdsStats.Close;
restDataModule.responseOperatorStats.Content.Empty;
restDataModule.reqOperatorStats.ClearBody;
restDataModule.reqOperatorStats.Execute;
restDataModule.cdsStats.Open;
try
restDataModule.adapterChats.ClearDataSet;
restDataModule.cdsChats.Close;
restDataModule.responseChats.Content.Empty;
restDataModule.reqChats.ClearBody;
restDataModule.reqChats.Execute;
restDataModule.cdsChats.Open;
except on E: Exception do
// ignore
memo1.Lines.Add('Failed!')
end;
memo1.Lines.Add(restDataModule.responseChats.Content);
Any suggestions welcome.
Ok the solution was to add a Parameter to the RestClient with the following settings:-
Kind = pkHTTPHEADER
Name = Cache-Control
Value = no-cache
Simple but elusive

SaveDialog.Execute not doing anything in Windows 7

Delphi 2007 on windows 7 just does nothing on the saveDialog.Execute call. I have seen another person mention this a few weeks back but it was with Borland c++.
See the thread "TOpenDialog.Execute not working " on embarcadero newsgroups.
Problem there was resolved by deleting the executable name from
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
I got the same problem (savedialog not working) in windows XP.
After lots of unsuccessful attempts according to the voluminous exchanges in the embarcadero group you mention (https://forums.embarcadero.com/thread.jspa?messageID=196950&tstart=0#196950).
I found what the reason was : the initial file dir and filename of the Savedialog12 were bad, contradicting each other, the filename containing the fullpath of the last file I had opened (I had thought it was smart to prepare the saving of the file I had opened last; unfortunately what I had put in the initialdir was equal to what I had put in the filename !)
The problem was already solved by clearing both fields of the save dialog.
Further, my initial goal to prepare the saving was reached by putting valid values in the involved fields :
SaveDialog1.FileName:=ExtractFileName(Opendialog1.Filename);
SaveDialog1.InitialFileDir:=ExtractFilePath(Opendialog1.Filename);

Resources