Skip to content

Commit

Permalink
prevended dual launch
Browse files Browse the repository at this point in the history
  • Loading branch information
opiopan committed Jun 18, 2024
1 parent 83e5843 commit 0160333
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/gui/App.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <winrt/Microsoft.UI.Windowing.h>
#include <winrt/Microsoft.UI.Interop.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
#include <winrt/Microsoft.Windows.AppLifecycle.h>

using namespace winrt;
using namespace Windows::Foundation;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Microsoft::UI::Xaml::Navigation;
using namespace Microsoft::Windows::AppLifecycle;
using namespace gui;
using namespace gui::implementation;

Expand Down Expand Up @@ -42,8 +44,16 @@ HWND App::TopWindowHandle() {
return hwnd;
}

void App::OnLaunched(LaunchActivatedEventArgs const&)
{
winrt::fire_and_forget App::OnLaunched(LaunchActivatedEventArgs const&){
auto mainInstance{ AppInstance::FindOrRegisterForKey(L"fsmapper") };
if (!mainInstance.IsCurrent()){
// Redirect the activation (and args) to the "main" instance, and exit.
auto activatedEventArgs{AppInstance::GetCurrent().GetActivatedEventArgs()};
co_await mainInstance.RedirectActivationToAsync(activatedEventArgs);
::ExitProcess(0);
co_return;
}

mapper = winrt::make<gui::Models::implementation::Mapper>();
window = make<MainWindow>();
window.Activate();
Expand Down
3 changes: 1 addition & 2 deletions src/gui/App.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace winrt::gui::implementation
{
App();

void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

winrt::fire_and_forget OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const &);
static winrt::Microsoft::UI::Xaml::Window TopWindow(){return window;}
static HWND TopWindowHandle();
static winrt::gui::Models::Mapper Mapper(){return mapper;}
Expand Down

0 comments on commit 0160333

Please sign in to comment.