Core - Add IBrowserProcessHandler.OnAlreadyRunningAppRelaunch

Issue #4668
This commit is contained in:
Alex Maitland
2024-01-13 13:23:01 +10:00
parent ae272a9b68
commit e329cdc1fb
3 changed files with 97 additions and 0 deletions
@@ -121,6 +121,36 @@ namespace CefSharp
_app->BrowserProcessHandler->OnScheduleMessagePumpWork(delay_ms);
}
virtual bool OnAlreadyRunningAppRelaunch(CefRefPtr<CefCommandLine> commandLine, const CefString& currentDirectory) override
{
if (Object::ReferenceEquals(_app, nullptr) || Object::ReferenceEquals(_app->BrowserProcessHandler, nullptr))
{
return false;
}
auto managedArgs = gcnew Dictionary<String^, String^>();
CefCommandLine::ArgumentList args;
commandLine->GetArguments(args);
for (auto arg : args)
{
managedArgs->Add(StringUtils::ToClr(arg), String::Empty);
}
CefCommandLine::SwitchMap switches;
commandLine->GetSwitches(switches);
for (auto s : switches)
{
managedArgs->Add(StringUtils::ToClr(s.first), StringUtils::ToClr(s.second));
}
auto readOnlyArgs = gcnew System::Collections::ObjectModel::ReadOnlyDictionary<String^, String^>(managedArgs);
return _app->BrowserProcessHandler->OnAlreadyRunningAppRelaunch(readOnlyArgs, StringUtils::ToClr(currentDirectory));
}
virtual void OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> commandLine) override
{
#ifndef NETCOREAPP
+38
View File
@@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Collections.Generic;
namespace CefSharp.Handler
{
@@ -55,6 +56,43 @@ namespace CefSharp.Handler
}
/// <inheritdoc/>
bool IBrowserProcessHandler.OnAlreadyRunningAppRelaunch(IReadOnlyDictionary<string, string> commandLine, string currentDirectory)
{
return OnAlreadyRunningAppRelaunch(commandLine, currentDirectory);
}
/// <summary>
/// Implement this method to provide app-specific behavior when an already
/// running app is relaunched with the same CefSettings.RootCachePath value.
/// For example, activate an existing app window or create a new app window.
///
/// To avoid cache corruption only a single app instance is allowed to run for
/// a given CefSettings.RootCachePath value. On relaunch the app checks a
/// process singleton lock and then forwards the new launch arguments to the
/// already running app process before exiting early. Client apps should
/// therefore check the Cef.Initialize() return value for early exit before
/// proceeding.
///
/// It's important to note that this method will be called on a CEF UI thread,
/// which by default is not the same as your application UI thread.
///
/// </summary>
/// <param name="commandLine">Command line arugments/switches</param>
/// <param name="currentDirectory">current directory (optional)</param>
/// <returns>
/// Return true if the relaunch is handled or false for default relaunch
/// behavior. Default behavior will create a new default styled Chrome window.
/// </returns>
/// <remarks>
/// The <paramref name="commandLine"/> dictionary may contain keys that have empty string values
/// (arugments).
/// </remarks>
protected virtual bool OnAlreadyRunningAppRelaunch(IReadOnlyDictionary<string, string> commandLine, string currentDirectory)
{
return false;
}
/// <summary>
/// IsDisposed
/// </summary>
@@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Collections.Generic;
namespace CefSharp
{
@@ -34,5 +35,33 @@ namespace CefSharp
/// specified delay and any currently pending scheduled call should be
/// cancelled.</param>
void OnScheduleMessagePumpWork(long delay);
/// <summary>
/// Implement this method to provide app-specific behavior when an already
/// running app is relaunched with the same CefSettings.RootCachePath value.
/// For example, activate an existing app window or create a new app window.
///
/// To avoid cache corruption only a single app instance is allowed to run for
/// a given CefSettings.RootCachePath value. On relaunch the app checks a
/// process singleton lock and then forwards the new launch arguments to the
/// already running app process before exiting early. Client apps should
/// therefore check the Cef.Initialize() return value for early exit before
/// proceeding.
///
/// It's important to note that this method will be called on a CEF UI thread,
/// which by default is not the same as your application UI thread.
///
/// </summary>
/// <param name="commandLine">Readonly command line args</param>
/// <param name="currentDirectory">current directory (optional)</param>
/// <returns>
/// Return true if the relaunch is handled or false for default relaunch
/// behavior. Default behavior will create a new default styled Chrome window.
/// </returns>
/// <remarks>
/// The <paramref name="commandLine"/> dictionary may contain keys that have empty string values
/// (arugments).
/// </remarks>
bool OnAlreadyRunningAppRelaunch(IReadOnlyDictionary<string, string> commandLine, string currentDirectory);
}
}