2017-12-05 10:02:07 +01:00
|
|
|
unit uCEFWorkScheduler;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2019-11-08 23:15:53 +01:00
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows, WinApi.Messages,{$ENDIF} System.Classes,
|
2017-12-05 10:02:07 +01:00
|
|
|
{$ELSE}
|
2019-11-08 23:15:53 +01:00
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes,
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
2020-12-18 16:51:02 +01:00
|
|
|
LCLProc, LCLType, LCLIntf, LResources, LMessages, InterfaceBase, {$IFNDEF MSWINDOWS}forms,{$ENDIF}
|
2018-05-12 14:50:54 +02:00
|
|
|
{$ELSE}
|
|
|
|
Messages,
|
|
|
|
{$ENDIF}
|
2017-12-05 10:02:07 +01:00
|
|
|
{$ENDIF}
|
2021-05-26 19:32:10 +02:00
|
|
|
uCEFConstants, uCEFWorkSchedulerQueueThread, uCEFWorkSchedulerThread;
|
2021-02-11 19:52:23 +01:00
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
|
|
|
|
type
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows)]{$ENDIF}{$ENDIF}
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// <para>Implementation of an external message pump for VCL and LCL.</para>
|
|
|
|
/// <para>Read the GlobalCEFApp.OnScheduleMessagePumpWork documentation for all the details.</para>
|
|
|
|
/// </summary>
|
2017-12-05 10:02:07 +01:00
|
|
|
TCEFWorkScheduler = class(TComponent)
|
|
|
|
protected
|
2018-01-25 21:34:04 +01:00
|
|
|
FThread : TCEFWorkSchedulerThread;
|
2021-02-11 19:52:23 +01:00
|
|
|
FQueueThread : TCEFWorkSchedulerQueueThread;
|
2017-12-05 10:02:07 +01:00
|
|
|
FDepleteWorkCycles : cardinal;
|
|
|
|
FDepleteWorkDelay : cardinal;
|
2018-01-25 21:34:04 +01:00
|
|
|
FDefaultInterval : integer;
|
2017-12-05 10:02:07 +01:00
|
|
|
FStopped : boolean;
|
2021-05-26 19:32:10 +02:00
|
|
|
FUseQueueThread : boolean;
|
2018-01-25 21:34:04 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$WARN SYMBOL_PLATFORM OFF}
|
2020-12-18 16:51:02 +01:00
|
|
|
FCompHandle : HWND;
|
2018-01-25 21:34:04 +01:00
|
|
|
FPriority : TThreadPriority;
|
|
|
|
{$WARN SYMBOL_PLATFORM ON}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2021-02-11 19:52:23 +01:00
|
|
|
procedure CreateQueueThread;
|
|
|
|
procedure DestroyQueueThread;
|
|
|
|
procedure QueueThread_OnPulse(Sender : TObject; aDelay : integer);
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure DestroyThread;
|
|
|
|
procedure DepleteWork;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure WndProc(var aMessage: TMessage);
|
2020-12-18 16:51:02 +01:00
|
|
|
procedure DeallocateWindowHandle;
|
|
|
|
{$ELSE}
|
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure ScheduleWorkAsync(Data: PtrInt);
|
|
|
|
{$ENDIF}
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure NextPulse(aInterval : integer);
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure ScheduleWork(const delay_ms : int64);
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure DoWork;
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure DoMessageLoopWork;
|
2021-01-20 18:57:20 +01:00
|
|
|
procedure Initialize;
|
2018-01-25 21:34:04 +01:00
|
|
|
|
|
|
|
procedure SetDefaultInterval(aValue : integer);
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$WARN SYMBOL_PLATFORM OFF}
|
|
|
|
procedure SetPriority(aValue : TThreadPriority);
|
|
|
|
{$WARN SYMBOL_PLATFORM ON}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
procedure Thread_OnPulse(Sender : TObject);
|
2017-12-05 10:02:07 +01:00
|
|
|
|
|
|
|
public
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Full constructor of TCEFWorkScheduler. This constructor also creates the internal threads.
|
|
|
|
/// </summary>
|
2017-12-05 10:02:07 +01:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Partial constructor of TCEFWorkScheduler. This constructor doesn't create any threads.
|
|
|
|
/// Call TCEFWorkScheduler.CreateThread when necessary.
|
|
|
|
/// </summary>
|
2021-01-20 18:57:20 +01:00
|
|
|
constructor CreateDelayed;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// TCEFWorkScheduler destructor.
|
|
|
|
/// </summary>
|
2017-12-05 10:02:07 +01:00
|
|
|
destructor Destroy; override;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Called from GlobalCEFApp.OnScheduleMessagePumpWork to schedule
|
|
|
|
/// a GlobalCEFApp.DoMessageLoopWork call asynchronously to perform a single
|
|
|
|
/// iteration of CEF message loop processing.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="delay_ms">Requested delay in milliseconds.</param>
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure ScheduleMessagePumpWork(const delay_ms : int64);
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Stop the scheduler. This function must be called after the destruction of all the forms in the application.
|
|
|
|
/// </summary>
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure StopScheduler;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Creates all the internal threads used by TCEFWorkScheduler.
|
|
|
|
/// </summary>
|
2021-01-20 18:57:20 +01:00
|
|
|
procedure CreateThread;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
|
|
|
published
|
2018-01-25 21:34:04 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$WARN SYMBOL_PLATFORM OFF}
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Priority of TCEFWorkSchedulerThread in Windows.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property Priority : TThreadPriority read FPriority write SetPriority default tpNormal;
|
|
|
|
{$WARN SYMBOL_PLATFORM ON}
|
|
|
|
{$ENDIF}
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Default interval in milliseconds to do the next GlobalCEFApp.DoMessageLoopWork call.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property DefaultInterval : integer read FDefaultInterval write SetDefaultInterval default CEF_TIMER_MAXDELAY;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Number of cycles used to deplete the remaining messages in the work loop.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property DepleteWorkCycles : cardinal read FDepleteWorkCycles write FDepleteWorkCycles default CEF_TIMER_DEPLETEWORK_CYCLES;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Delay in milliseconds between the cycles used to deplete the remaining messages in the work loop.
|
|
|
|
/// </summary>
|
2018-01-25 21:34:04 +01:00
|
|
|
property DepleteWorkDelay : cardinal read FDepleteWorkDelay write FDepleteWorkDelay default CEF_TIMER_DEPLETEWORK_DELAY;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Use a custom queue thread instead of Windows messages or any other way to schedule the next pump work.
|
|
|
|
/// </summary>
|
2021-05-26 19:32:10 +02:00
|
|
|
property UseQueueThread : boolean read FUseQueueThread write FUseQueueThread default False;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2018-04-07 20:24:55 +02:00
|
|
|
var
|
|
|
|
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
procedure DestroyGlobalCEFWorkScheduler;
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils, System.Math,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils, Math,
|
|
|
|
{$ENDIF}
|
2019-11-08 23:15:53 +01:00
|
|
|
uCEFMiscFunctions, uCEFApplicationCore, uCEFTypes;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
procedure DestroyGlobalCEFWorkScheduler;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFWorkScheduler <> nil) then FreeAndNil(GlobalCEFWorkScheduler);
|
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
|
|
|
constructor TCEFWorkScheduler.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
2021-01-20 18:57:20 +01:00
|
|
|
Initialize;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
2021-01-20 18:57:20 +01:00
|
|
|
if not(csDesigning in ComponentState) then
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (GlobalCEFApp <> nil) and
|
|
|
|
((GlobalCEFApp.ProcessType = ptBrowser) or GlobalCEFApp.SingleProcess) then
|
|
|
|
FCompHandle := AllocateHWnd({$IFDEF FPC}@{$ENDIF}WndProc);
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
CreateThread;
|
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2021-01-20 18:57:20 +01:00
|
|
|
constructor TCEFWorkScheduler.CreateDelayed;
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2021-01-20 18:57:20 +01:00
|
|
|
inherited Create(nil);
|
|
|
|
|
|
|
|
Initialize;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
|
|
|
if not(csDesigning in ComponentState) then
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-11-22 15:02:21 +01:00
|
|
|
if (GlobalCEFApp <> nil) and
|
|
|
|
((GlobalCEFApp.ProcessType = ptBrowser) or GlobalCEFApp.SingleProcess) then
|
2021-01-20 18:57:20 +01:00
|
|
|
FCompHandle := AllocateHWnd({$IFDEF FPC}@{$ENDIF}WndProc);
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2021-01-20 18:57:20 +01:00
|
|
|
destructor TCEFWorkScheduler.Destroy;
|
|
|
|
begin
|
|
|
|
DestroyThread;
|
2021-02-11 19:52:23 +01:00
|
|
|
DestroyQueueThread;
|
2021-01-20 18:57:20 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
DeallocateWindowHandle;
|
|
|
|
{$ENDIF}
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.Initialize;
|
|
|
|
begin
|
2021-05-26 19:32:10 +02:00
|
|
|
FUseQueueThread := False;
|
2021-01-20 18:57:20 +01:00
|
|
|
FThread := nil;
|
2021-02-11 19:52:23 +01:00
|
|
|
FQueueThread := nil;
|
2021-01-20 18:57:20 +01:00
|
|
|
FStopped := False;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$WARN SYMBOL_PLATFORM OFF}
|
|
|
|
FCompHandle := 0;
|
|
|
|
FPriority := tpNormal;
|
|
|
|
{$WARN SYMBOL_PLATFORM ON}
|
|
|
|
{$ENDIF}
|
|
|
|
FDefaultInterval := CEF_TIMER_MAXDELAY;
|
|
|
|
FDepleteWorkCycles := CEF_TIMER_DEPLETEWORK_CYCLES;
|
|
|
|
FDepleteWorkDelay := CEF_TIMER_DEPLETEWORK_DELAY;
|
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.CreateThread;
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2021-01-20 18:57:20 +01:00
|
|
|
if (FThread <> nil) then exit;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
FThread := TCEFWorkSchedulerThread.Create;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FThread.Priority := FPriority;
|
|
|
|
{$ENDIF}
|
|
|
|
FThread.DefaultInterval := FDefaultInterval;
|
2018-05-12 14:50:54 +02:00
|
|
|
FThread.OnPulse := {$IFDEF FPC}@{$ENDIF}Thread_OnPulse;
|
2018-02-07 14:30:44 +01:00
|
|
|
{$IFDEF DELPHI14_UP}
|
2018-01-25 21:34:04 +01:00
|
|
|
FThread.Start;
|
|
|
|
{$ELSE}
|
2019-11-10 18:23:39 +01:00
|
|
|
{$IFNDEF FPC}
|
2018-01-25 21:34:04 +01:00
|
|
|
FThread.Resume;
|
2019-11-10 18:23:39 +01:00
|
|
|
{$ELSE}
|
|
|
|
FThread.Start;
|
|
|
|
{$ENDIF}
|
2018-01-25 21:34:04 +01:00
|
|
|
{$ENDIF}
|
2021-02-11 19:52:23 +01:00
|
|
|
|
2021-05-26 19:32:10 +02:00
|
|
|
if FUseQueueThread then
|
|
|
|
CreateQueueThread;
|
|
|
|
end;
|
2021-02-11 19:52:23 +01:00
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.CreateQueueThread;
|
|
|
|
begin
|
|
|
|
FQueueThread := TCEFWorkSchedulerQueueThread.Create;
|
|
|
|
FQueueThread.OnPulse := {$IFDEF FPC}@{$ENDIF}QueueThread_OnPulse;
|
|
|
|
{$IFDEF DELPHI14_UP}
|
|
|
|
FQueueThread.Start;
|
|
|
|
{$ELSE}
|
|
|
|
{$IFNDEF FPC}
|
|
|
|
FQueueThread.Resume;
|
|
|
|
{$ELSE}
|
|
|
|
FQueueThread.Start;
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2021-02-11 19:52:23 +01:00
|
|
|
procedure TCEFWorkScheduler.DestroyQueueThread;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FQueueThread <> nil) then
|
|
|
|
begin
|
|
|
|
FQueueThread.Terminate;
|
|
|
|
FQueueThread.StopThread;
|
|
|
|
FQueueThread.WaitFor;
|
|
|
|
FreeAndNil(FQueueThread);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCEFWorkScheduler.DestroyQueueThread', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.QueueThread_OnPulse(Sender : TObject; aDelay : integer);
|
|
|
|
begin
|
|
|
|
ScheduleWork(aDelay);
|
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.DestroyThread;
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
try
|
|
|
|
if (FThread <> nil) then
|
|
|
|
begin
|
|
|
|
FThread.Terminate;
|
|
|
|
FThread.NextPulse(0);
|
|
|
|
FThread.WaitFor;
|
|
|
|
FreeAndNil(FThread);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCEFWorkScheduler.DestroyThread', e) then raise;
|
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.WndProc(var aMessage: TMessage);
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
if (aMessage.Msg = CEF_PUMPHAVEWORK) then
|
|
|
|
ScheduleWork(aMessage.lParam)
|
|
|
|
else
|
|
|
|
aMessage.Result := DefWindowProc(FCompHandle, aMessage.Msg, aMessage.WParam, aMessage.LParam);
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.DeallocateWindowHandle;
|
|
|
|
begin
|
|
|
|
if (FCompHandle <> 0) then
|
|
|
|
begin
|
|
|
|
DeallocateHWnd(FCompHandle);
|
|
|
|
FCompHandle := 0;
|
|
|
|
end;
|
|
|
|
end;
|
2021-05-26 19:32:10 +02:00
|
|
|
|
|
|
|
{$WARN SYMBOL_PLATFORM OFF}
|
|
|
|
procedure TCEFWorkScheduler.SetPriority(aValue : TThreadPriority);
|
|
|
|
begin
|
|
|
|
FPriority := aValue;
|
|
|
|
if (FThread <> nil) then FThread.Priority := aValue;
|
|
|
|
end;
|
|
|
|
{$WARN SYMBOL_PLATFORM ON}
|
2020-12-18 16:51:02 +01:00
|
|
|
{$ENDIF}
|
2017-12-05 10:02:07 +01:00
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.DoMessageLoopWork;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFApp <> nil) then GlobalCEFApp.DoMessageLoopWork;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.SetDefaultInterval(aValue : integer);
|
|
|
|
begin
|
|
|
|
FDefaultInterval := aValue;
|
|
|
|
if (FThread <> nil) then FThread.DefaultInterval := aValue;
|
|
|
|
end;
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure TCEFWorkScheduler.DepleteWork;
|
|
|
|
var
|
|
|
|
i : cardinal;
|
|
|
|
begin
|
|
|
|
i := FDepleteWorkCycles;
|
|
|
|
|
|
|
|
while (i > 0) do
|
|
|
|
begin
|
|
|
|
DoMessageLoopWork;
|
|
|
|
Sleep(FDepleteWorkDelay);
|
|
|
|
dec(i);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.ScheduleMessagePumpWork(const delay_ms : int64);
|
|
|
|
begin
|
2021-02-11 19:52:23 +01:00
|
|
|
if FStopped then exit;
|
|
|
|
|
2021-05-26 19:32:10 +02:00
|
|
|
if FUseQueueThread and (FQueueThread <> nil) and FQueueThread.Ready then
|
|
|
|
FQueueThread.EnqueueValue(integer(delay_ms))
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FCompHandle <> 0) then
|
|
|
|
PostMessage(FCompHandle, CEF_PUMPHAVEWORK, 0, LPARAM(delay_ms));
|
|
|
|
{$ELSE}
|
|
|
|
{$IFDEF FPC}
|
|
|
|
Application.QueueAsyncCall(@ScheduleWorkAsync, integer(delay_ms));
|
|
|
|
{$ELSE}
|
|
|
|
TThread.ForceQueue(nil, procedure
|
|
|
|
begin
|
|
|
|
ScheduleWork(delay_ms);
|
|
|
|
end);
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2020-12-18 16:51:02 +01:00
|
|
|
{$IFNDEF MSWINDOWS}{$IFDEF FPC}
|
|
|
|
procedure TCEFWorkScheduler.ScheduleWorkAsync(Data: PtrInt);
|
|
|
|
begin
|
|
|
|
ScheduleWork(integer(Data));
|
|
|
|
end;
|
|
|
|
{$ENDIF}{$ENDIF}
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
procedure TCEFWorkScheduler.StopScheduler;
|
|
|
|
begin
|
|
|
|
FStopped := True;
|
2018-01-25 21:34:04 +01:00
|
|
|
NextPulse(0);
|
2017-12-05 10:02:07 +01:00
|
|
|
DepleteWork;
|
2020-12-18 16:51:02 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-12-05 10:02:07 +01:00
|
|
|
DeallocateWindowHandle;
|
2020-12-18 16:51:02 +01:00
|
|
|
{$ENDIF}
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.Thread_OnPulse(Sender: TObject);
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
if not(FStopped) then DoMessageLoopWork;
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.DoWork;
|
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
DoMessageLoopWork;
|
|
|
|
NextPulse(FDefaultInterval);
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFWorkScheduler.ScheduleWork(const delay_ms : int64);
|
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
if not(FStopped) then
|
2017-12-05 10:02:07 +01:00
|
|
|
begin
|
2018-01-25 21:34:04 +01:00
|
|
|
if (delay_ms <= 0) then
|
|
|
|
DoWork
|
|
|
|
else
|
|
|
|
NextPulse(delay_ms);
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
2017-12-05 10:02:07 +01:00
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TCEFWorkScheduler.NextPulse(aInterval : integer);
|
|
|
|
begin
|
|
|
|
if (FThread <> nil) then FThread.NextPulse(aInterval);
|
2017-12-05 10:02:07 +01:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
begin
|
2018-06-03 17:18:54 +02:00
|
|
|
{$I res/tcefworkscheduler.lrs}
|
2018-05-12 14:50:54 +02:00
|
|
|
RegisterComponents('Chromium', [TCEFWorkScheduler]);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-12-05 10:02:07 +01:00
|
|
|
end.
|