* Send console output through TCommandDispatcher

This commit is contained in:
Michael Van Canneyt 2025-04-24 11:57:40 +02:00
parent 31b0027881
commit 5f0afb2ad0

View File

@ -5,7 +5,7 @@ unit workerapp;
interface interface
uses uses
Classes, SysUtils, CustApp, WebOrWorker, WebWorker, Rtl.WorkerCommands; Classes, SysUtils, CustApp, WebWorker, Rtl.WorkerCommands;
Type Type
@ -13,8 +13,6 @@ Type
TWorkerApplication = class(TCustomApplication) TWorkerApplication = class(TCustomApplication)
Private Private
FSendOutputToBrowser: Boolean;
FConsoleChannel: TJSBroadcastChannel;
FSendOutputToConsole: Boolean; FSendOutputToConsole: Boolean;
protected protected
procedure DoLog(EventType: TEventType; const Msg: String); override; procedure DoLog(EventType: TEventType; const Msg: String); override;
@ -23,17 +21,12 @@ Type
procedure ShowException(aError: Exception); override; procedure ShowException(aError: Exception); override;
function GetConsoleApplication: boolean; override; function GetConsoleApplication: boolean; override;
function GetLocation: String; override; function GetLocation: String; override;
// Send output to browser window process? // Send output to console channel ?
Property SendOutputToBrowser : Boolean Read FSendOutputToBrowser Write FSendOutputToBrowser;
// Send output to console ?
Property SendOutputToConsole : Boolean Read FSendOutputToConsole Write FSendOutputToConsole; Property SendOutputToConsole : Boolean Read FSendOutputToConsole Write FSendOutputToConsole;
// Default console input
// Send a command to the process that started the worker. // Send a command to the process that started the worker.
procedure SendCommand(aCommand: TCustomWorkerCommand); procedure SendCommand(aCommand: TCustomWorkerCommand);
// Get the list of environment variables. // Get the list of environment variables.
procedure GetEnvironmentList(List: TStrings; NamesOnly: Boolean); override; procedure GetEnvironmentList(List: TStrings; NamesOnly: Boolean); override;
// Console channel
property ConsoleChannel : TJSBroadCastChannel Read FConsoleChannel;
end; end;
implementation implementation
@ -95,7 +88,6 @@ end;
constructor TWorkerApplication.Create(AOwner: TComponent); constructor TWorkerApplication.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FConsoleChannel:=TJSBroadcastChannel.new(channelConsole);
FSendOutputToConsole:=true; FSendOutputToConsole:=true;
end; end;
@ -142,8 +134,10 @@ procedure TWorkerApplication.DoLog(EventType: TEventType; const Msg: String);
var var
S : String; S : String;
begin begin
if not SendOutputToConsole then
Exit;
S:=GetEnumName(TypeInfo(TEventType),Ord(EventType)); S:=GetEnumName(TypeInfo(TEventType),Ord(EventType));
ConsoleChannel.PostMessage(TConsoleOutputCommand.Create(Format('[%s] %s',[S,Msg]))); TCommandDispatcher.Instance.SendConsoleCommand(TConsoleOutputCommand.Create(Format('[%s] %s',[S,Msg])));
end; end;
initialization initialization