fix(android): re-enable the fetch button on every exit path, prefill the test parameters
The Exit in each error branch jumped past the re-enable at the end of the anonymous method, so one failure disabled the button for good. Wrapped in try/finally. URL and token are now constants, with the port chosen per platform: 80 on Windows against Apache, 8080 on Android through adb reverse. The sync password is never prefilled - it opens the whole vault and this file is versioned.
This commit is contained in:
+30
-3
@@ -23,6 +23,22 @@ uses
|
||||
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Memo, FMX.Memo.Types,
|
||||
FMX.ScrollBox, FMX.Layouts, FMX.Edit;
|
||||
|
||||
const
|
||||
// Parametres du banc d'essai, pre-remplis pour ne pas les retaper.
|
||||
//
|
||||
// Le port differe selon la plateforme : sur Windows on attaque Apache
|
||||
// directement (80), sur Android on passe par "adb reverse tcp:8080 tcp:80",
|
||||
// qui fait voir le PC comme 127.0.0.1 — ce qui satisfait au passage
|
||||
// l'exemption HTTPS de l'endpoint, reservee a la boucle locale.
|
||||
{$IF DEFINED(ANDROID)}
|
||||
TEST_URL = 'http://127.0.0.1:8080/server-php/sync.php';
|
||||
{$ELSE}
|
||||
TEST_URL = 'http://127.0.0.1/server-php/sync.php';
|
||||
{$ENDIF}
|
||||
// Jeton d'un serveur de test local. Il n'authentifie qu'un appareil et ne
|
||||
// donne acces qu'a du chiffre — mais a remplacer avant toute mise en ligne.
|
||||
TEST_TOKEN = '8765e5bf426039e9888f44bfbab27d489d12b7dbaaa54c8c695ae6af8b2a820e';
|
||||
|
||||
type
|
||||
TForm8 = class(TForm)
|
||||
private
|
||||
@@ -81,16 +97,21 @@ begin
|
||||
FPwd.Margins.Rect := RectF(8, 4, 8, 0);
|
||||
FPwd.TextPrompt := 'mot de passe de sync';
|
||||
FPwd.Password := True;
|
||||
// Jamais pre-rempli, meme pour un essai : il ouvre le coffre entier, et ce
|
||||
// fichier est versionne.
|
||||
FPwd.Text := '';
|
||||
|
||||
FToken := TEdit.Create(Self);
|
||||
FToken.Parent := Self; FToken.Align := TAlignLayout.Top;
|
||||
FToken.Margins.Rect := RectF(8, 4, 8, 0);
|
||||
FToken.TextPrompt := 'jeton Bearer';
|
||||
FToken.Text := TEST_TOKEN;
|
||||
|
||||
FUrl := TEdit.Create(Self);
|
||||
FUrl.Parent := Self; FUrl.Align := TAlignLayout.Top;
|
||||
FUrl.Margins.Rect := RectF(8, 8, 8, 0);
|
||||
FUrl.TextPrompt := 'http://127.0.0.1:8080/server-php/sync.php';
|
||||
FUrl.TextPrompt := 'URL de l''endpoint';
|
||||
FUrl.Text := TEST_URL;
|
||||
|
||||
FLog := TMemo.Create(Self);
|
||||
FLog.Parent := Self;
|
||||
@@ -136,6 +157,10 @@ begin
|
||||
LLive, LTrash, I: Integer;
|
||||
begin
|
||||
LClient := TSyncClient.Create(LUrl, LTok);
|
||||
// try/finally et NON un simple enchainement : les Exit des branches
|
||||
// d'erreur ci-dessous sautent la fin de la procedure, ce qui laissait le
|
||||
// bouton desactive pour de bon apres le premier echec.
|
||||
try
|
||||
try
|
||||
Log('GET ' + LUrl);
|
||||
if FETag <> '' then Log(' If-None-Match: ' + FETag);
|
||||
@@ -200,8 +225,10 @@ begin
|
||||
on E: Exception do
|
||||
Log('ERREUR ' + E.ClassName + ' : ' + E.Message);
|
||||
end;
|
||||
LClient.Free;
|
||||
TThread.Queue(nil, procedure begin FBtnFetch.Enabled := True; end);
|
||||
finally
|
||||
LClient.Free;
|
||||
TThread.Queue(nil, procedure begin FBtnFetch.Enabled := True; end);
|
||||
end;
|
||||
end).Start;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user