private async void ApplicationBase_Startup(object sender, StartupEventArgs e) { if (this.isInitialized) { return; } this.isInitialized = true; if (e.Args != null && e.Args.Length > 0 && e.Args[0] == "registerUriScheme") { try { RegisterUrlProtocols(); } catch { // don't show anything... This will only annoy users } this.Shutdown(); return; } ParamPassing.Configure(e.Args, x => { x.IsSingleInstance = this.IsSingleInstance; x.BringToFront = this.ShouldBringToFront; x.RandomSelectInstance = true; x.DataSeparator = '\n'; x.ParameterPassedCallback = new Action <string[]>(args => { if (args != null && args.Length > 0 && args[0].IndexOf(':') > 0 && ApplicationUrlProtocols.Contains(args[0].Split(':').First(), new DynamicEqualityComparer <string>((a, b) => string.Equals(a, b, StringComparison.CurrentCultureIgnoreCase)))) { try { this.OnActivationProtocol(new Uri(args[0])); } catch { // if the application recieves malformed or bad urls... We should just ignore it here } } else { this.OnActivated(args); } }); x.ExitDelegate = () => { this.Shutdown(); Environment.Exit(0); }; }); if (this.IsSingleInstance && ParamPassing.AreOtherInstanceActive) { if (ParamPassing.BringToFront()) { this.Shutdown(); } } else { if (this.IsSinglePage) { WindowType windowType = null; var window = Common.CreateWindow(ref windowType); window.ContentTemplateSelector = new CauldronTemplateSelector(); window.MinHeight = 353; window.MinWidth = 502; window.ShowInTaskbar = true; window.Topmost = false; window.WindowStartupLocation = WindowStartupLocation.Manual; window.WindowState = WindowState.Normal; window.Icon = await UnsafeNative.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync(); window.Title = ApplicationInfo.ApplicationName; PersistentWindowInformation.Load(window, this.GetType()); window.SizeChanged += (s, e1) => { if (window.WindowState == WindowState.Normal) { PersistentWindowProperties.SetHeight(window, e1.NewSize.Height); PersistentWindowProperties.SetWidth(window, e1.NewSize.Width); } }; window.Closing += (s, e1) => PersistentWindowInformation.Save(window, this.GetType()); window.Show(); window.Content = this; window.Activate(); await this.OnPreload(); var rootFrame = new NavigationFrame(); rootFrame.DataContext = this; window.Content = rootFrame; window.InputBindings.Add(new KeyBinding(new RelayCommand(async() => { await rootFrame.GoBack(); }, () => rootFrame.CanGoBack), Key.Back, ModifierKeys.None)); } else if (this.GetType().GetCustomAttribute <ViewAttribute>() != null || Application.Current.Resources.Contains($"View_{this.GetType().Name}")) { var oldShutdownMode = Application.Current.ShutdownMode; Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.Navigator.As <Navigator>()?.NavigateInternal <ApplicationBase>(this, null, null); await this.OnPreload(); if (Application.Current.MainWindow == null) { Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; Application.Current.Shutdown(); return; } Application.Current.MainWindow.Activate(); this.Navigator.TryClose(this); Application.Current.ShutdownMode = oldShutdownMode; } Application.Current.MainWindow = null; await this.OnStartup(new LaunchActivatedEventArgs(e.Args)); if (Application.Current.MainWindow != null) { Application.Current.MainWindow.AddHookParameterPassing(); Application.Current.MainWindow.Activate(); } } }
private async void ApplicationBase_Startup(object sender, StartupEventArgs e) { this.isInitialized = true; ParamPassing.Configure(e.Args, x => { x.IsSingleInstance = this.IsSingleInstance; x.BringToFront = this.ShouldBringToFront; x.RandomSelectInstance = true; x.DataSeparator = '\n'; x.ParameterPassedCallback = new Action <string[]>(args => this.OnActivated(args)); x.ExitDelegate = () => { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.Shutdown(); }; }); if (this.IsSingleInstance && ParamPassing.AreOtherInstanceActive) { if (ParamPassing.BringToFront()) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.Shutdown(); } } else { if (this.IsSinglePage) { WindowType windowType = null; var window = Common.CreateWindow(ref windowType); window.ContentTemplateSelector = new CauldronTemplateSelector(); window.MinHeight = 353; window.MinWidth = 502; window.ShowInTaskbar = true; window.Topmost = false; window.WindowStartupLocation = WindowStartupLocation.Manual; window.WindowState = WindowState.Normal; window.Icon = await UnsafeNative.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync(); window.Title = ApplicationInfo.ApplicationName; PersistentWindowInformation.Load(window, this.GetType()); window.SizeChanged += (s, e1) => { if (window.WindowState == WindowState.Normal) { PersistentWindowProperties.SetHeight(window, e1.NewSize.Height); PersistentWindowProperties.SetWidth(window, e1.NewSize.Width); } }; window.Closing += (s, e1) => PersistentWindowInformation.Save(window, this.GetType()); window.Show(); window.Content = this; window.Activate(); await this.OnPreload(); var rootFrame = new NavigationFrame(); rootFrame.DataContext = this; window.Content = rootFrame; window.InputBindings.Add(new KeyBinding(new RelayCommand(async() => { await rootFrame.GoBack(); }, () => rootFrame.CanGoBack), Key.Back, ModifierKeys.None)); } else if (this.GetType().GetCustomAttribute <ViewAttribute>() != null || Application.Current.Resources.Contains($"View_{this.GetType().Name}")) { this.Navigator.As <Navigator>()?.NavigateInternal <ApplicationBase>(this, null, null); await this.OnPreload(); Application.Current.MainWindow.Activate(); } await this.OnStartup(new LaunchActivatedEventArgs(e.Args)); this.Navigator.TryClose(this); if (Application.Current.MainWindow != null) { Application.Current.MainWindow.AddHookParameterPassing(); Application.Current.MainWindow.Activate(); } } }