auto restart process if needed

This commit is contained in:
April Ayres-Griffiths 2019-04-18 10:21:28 +10:00
parent 624484eefb
commit 68b30613f5
4 changed files with 75 additions and 7 deletions

View File

@ -1,7 +1,7 @@
object GUIForm: TGUIForm
Left = 371
Left = 275
Height = 683
Top = 112
Top = 109
Width = 1078
AlphaBlendValue = 128
Caption = 'microM8 GUI'
@ -10549,6 +10549,7 @@ object GUIForm: TGUIForm
WindowTop = 0
WindowWidth = 0
FillAttribute = 0
OnTerminate = MicroM8ProcessTerminate
left = 240
top = 160
end

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, ComCtrls,
ExtCtrls, StdCtrls, fphttpclient, LCLType, Buttons, AsyncProcess, DateUtils,
Clipbrd,
Clipbrd, lclintf,
{$IFDEF WINDOWS}
Windows,
{$ENDIF}
@ -369,6 +369,7 @@ type
procedure MenuItem14Click(Sender: TObject);
procedure MenuItem15Click(Sender: TObject);
procedure MenuItem16Click(Sender: TObject);
procedure MicroM8ProcessTerminate(Sender: TObject);
procedure miD1InsBlankClick(Sender: TObject);
procedure miD2InsBlankClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
@ -568,6 +569,7 @@ type
procedure WaitReposTimer(Sender: TObject);
procedure SendOSDMessage(msg: string);
procedure LaunchPAK(disk: string);
procedure CheckMicroM8RunState;
private
lx, ly, lw, lh: integer;
lastShowTime: TDateTime;
@ -582,6 +584,7 @@ type
VolPosition, WarpPosition: integer;
VolDrag, WarpDrag: boolean;
Caps: boolean;
NeedsRestart, Quitting: boolean;
public
procedure AppActivate(Sender: TObject);
procedure AppDeactivate(Sender: TObject);
@ -2373,7 +2376,9 @@ begin
result := self.httpc.Get(url)
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2386,6 +2391,9 @@ begin
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2409,6 +2417,9 @@ begin
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2623,6 +2634,7 @@ end;
procedure TGUIForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
Quitting := true;
SimpleGet( baseUrl+'/api/control/quit' );
CanClose := true;
end;
@ -3203,6 +3215,11 @@ begin
end;
end;
procedure TGUIForm.MicroM8ProcessTerminate(Sender: TObject);
begin
//lblTerm.Caption := 'core has terminated';
end;
procedure TGUIForm.miD1InsBlankClick(Sender: TObject);
begin
SimpleGet(baseUrl + '/api/control/hardware/disk/blank/0');
@ -3221,9 +3238,25 @@ end;
procedure TGUIForm.MenuItem2Click(Sender: TObject);
begin
Quitting := true;
SimpleGet( baseUrl+'/api/control/quit' );
Application.Terminate();
end;
procedure TGUIForm.CheckMicroM8RunState;
begin
if Quitting then
exit;
if not NeedsRestart then
exit;
if MicroM8Process.Active then
exit;
{ okay not running and we want to start it }
MicroM8Process.Active := true;
Sleep(50);
lx := -1;
ReposWindow;
end;
end.

View File

@ -1,7 +1,7 @@
object GUIForm: TGUIForm
Left = 371
Left = 275
Height = 683
Top = 112
Top = 109
Width = 1078
AlphaBlendValue = 128
Caption = 'microM8 GUI'
@ -10549,6 +10549,7 @@ object GUIForm: TGUIForm
WindowTop = 0
WindowWidth = 0
FillAttribute = 0
OnTerminate = MicroM8ProcessTerminate
left = 240
top = 160
end

View File

@ -369,6 +369,7 @@ type
procedure MenuItem14Click(Sender: TObject);
procedure MenuItem15Click(Sender: TObject);
procedure MenuItem16Click(Sender: TObject);
procedure MicroM8ProcessTerminate(Sender: TObject);
procedure miD1InsBlankClick(Sender: TObject);
procedure miD2InsBlankClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
@ -568,6 +569,7 @@ type
procedure WaitReposTimer(Sender: TObject);
procedure SendOSDMessage(msg: string);
procedure LaunchPAK(disk: string);
procedure CheckMicroM8RunState;
private
lx, ly, lw, lh: integer;
lastShowTime: TDateTime;
@ -582,6 +584,7 @@ type
VolPosition, WarpPosition: integer;
VolDrag, WarpDrag: boolean;
Caps: boolean;
NeedsRestart, Quitting: boolean;
public
procedure AppActivate(Sender: TObject);
procedure AppDeactivate(Sender: TObject);
@ -2373,7 +2376,9 @@ begin
result := self.httpc.Get(url)
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2386,6 +2391,9 @@ begin
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2409,6 +2417,9 @@ begin
except
on e: Exception do begin
// nothing much
// restart backend if not running
NeedsRestart:=true;
CheckMicroM8RunState;
end;
end;
end;
@ -2623,6 +2634,7 @@ end;
procedure TGUIForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
Quitting := true;
SimpleGet( baseUrl+'/api/control/quit' );
CanClose := true;
end;
@ -3203,6 +3215,11 @@ begin
end;
end;
procedure TGUIForm.MicroM8ProcessTerminate(Sender: TObject);
begin
//lblTerm.Caption := 'core has terminated';
end;
procedure TGUIForm.miD1InsBlankClick(Sender: TObject);
begin
SimpleGet(baseUrl + '/api/control/hardware/disk/blank/0');
@ -3221,9 +3238,25 @@ end;
procedure TGUIForm.MenuItem2Click(Sender: TObject);
begin
Quitting := true;
SimpleGet( baseUrl+'/api/control/quit' );
Application.Terminate();
end;
procedure TGUIForm.CheckMicroM8RunState;
begin
if Quitting then
exit;
if not NeedsRestart then
exit;
if MicroM8Process.Active then
exit;
{ okay not running and we want to start it }
MicroM8Process.Active := true;
Sleep(1000);
lx := -1;
ReposWindow;
end;
end.