You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-08-04 21:32:54 +02:00
Added a GlobalCEFApp.OnAlreadyRunningAppRelaunch example to the TabbedBrowser2 demo
This commit is contained in:
@ -75,6 +75,8 @@ type
|
|||||||
property BrowserTabCount : integer read GetBrowserTabCount;
|
property BrowserTabCount : integer read GetBrowserTabCount;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
procedure AddTab(const aURL : ustring = '');
|
||||||
|
|
||||||
function DoOnBeforePopup(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures; targetDisposition : TCefWindowOpenDisposition) : boolean;
|
function DoOnBeforePopup(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures; targetDisposition : TCefWindowOpenDisposition) : boolean;
|
||||||
function DoOpenUrlFromTab(const targetUrl : string; targetDisposition : TCefWindowOpenDisposition) : boolean;
|
function DoOpenUrlFromTab(const targetUrl : string; targetDisposition : TCefWindowOpenDisposition) : boolean;
|
||||||
end;
|
end;
|
||||||
@ -153,12 +155,41 @@ begin
|
|||||||
PostMessage(MainForm.Handle, CEF_INITIALIZED, 0, 0);
|
PostMessage(MainForm.Handle, CEF_INITIALIZED, 0, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure GlobalCEFApp_OnAlreadyRunningAppRelaunch(const commandLine: ICefCommandLine; const current_directory: ustring; var aResult: boolean);
|
||||||
|
var
|
||||||
|
TempURL : ustring;
|
||||||
|
begin
|
||||||
|
if assigned(commandLine) and commandLine.IsValid then
|
||||||
|
begin
|
||||||
|
// Lets pretend the second application instance was executed with the
|
||||||
|
// following command line :
|
||||||
|
// TabbedBrowser2.exe --url=https://www.example.com
|
||||||
|
//
|
||||||
|
// We read the switch value and store it in a normal string.
|
||||||
|
TempURL := commandLine.GetSwitchValue('url');
|
||||||
|
|
||||||
|
// This event is executed in the CEF UI thread and the VCL is not
|
||||||
|
// thread-safe so we have to use TThread.Queue if we want to add VCL
|
||||||
|
// controls safely.
|
||||||
|
TThread.Queue(nil,
|
||||||
|
procedure
|
||||||
|
begin
|
||||||
|
MainForm.AddTab(TempURL);
|
||||||
|
end);
|
||||||
|
|
||||||
|
// The relaunch was handled correctly so we return true.
|
||||||
|
aResult := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure CreateGlobalCEFApp;
|
procedure CreateGlobalCEFApp;
|
||||||
begin
|
begin
|
||||||
GlobalCEFApp := TCefApplication.Create;
|
GlobalCEFApp := TCefApplication.Create;
|
||||||
GlobalCEFApp.cache := 'cache';
|
GlobalCEFApp.RootCache := 'RootCache';
|
||||||
GlobalCEFApp.EnablePrintPreview := True;
|
GlobalCEFApp.cache := 'RootCache\cache';
|
||||||
GlobalCEFApp.OnContextInitialized := GlobalCEFApp_OnContextInitialized;
|
GlobalCEFApp.EnablePrintPreview := True;
|
||||||
|
GlobalCEFApp.OnContextInitialized := GlobalCEFApp_OnContextInitialized;
|
||||||
|
GlobalCEFApp.OnAlreadyRunningAppRelaunch := GlobalCEFApp_OnAlreadyRunningAppRelaunch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.EnableButtonPnl;
|
procedure TMainForm.EnableButtonPnl;
|
||||||
@ -217,6 +248,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.AddTabBtnClick(Sender: TObject);
|
procedure TMainForm.AddTabBtnClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
AddTab;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.AddTab(const aURL : ustring);
|
||||||
var
|
var
|
||||||
TempNewTab : TBrowserTab;
|
TempNewTab : TBrowserTab;
|
||||||
begin
|
begin
|
||||||
@ -225,7 +261,10 @@ begin
|
|||||||
|
|
||||||
BrowserPageCtrl.ActivePageIndex := pred(BrowserPageCtrl.PageCount);
|
BrowserPageCtrl.ActivePageIndex := pred(BrowserPageCtrl.PageCount);
|
||||||
|
|
||||||
TempNewTab.CreateBrowser(HOMEPAGE_URL);
|
if (length(aURL) = 0) then
|
||||||
|
TempNewTab.CreateBrowser(HOMEPAGE_URL)
|
||||||
|
else
|
||||||
|
TempNewTab.CreateBrowser(aURL);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.CEFInitializedMsg(var aMessage : TMessage);
|
procedure TMainForm.CEFInitializedMsg(var aMessage : TMessage);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 682,
|
"InternalVersion" : 683,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "131.3.1"
|
"Version" : "131.3.1"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user