private void HandleLaunchRedirect(string[] args) { var cmdLine = new ParagonCommandLineParser(args); ApplicationMetadata appMetadata; IApplicationPackage appPackage; if (!ResolveMetadataAndPackage(cmdLine, out appMetadata, out appPackage)) { return; } if (appPackage.Manifest.SingleInstance) { var isSingleInstanceLaunched = false; var app = GetSingleApplicationInstance(appMetadata.Id, appPackage.Manifest.ProcessGroup, out isSingleInstanceLaunched); if (app != null || isSingleInstanceLaunched) { string protocolUrl; if (app != null && cmdLine.GetValue("url", out protocolUrl)) { app.OnProtocolInvoke(protocolUrl); } if (app != null && app.WindowManager.AllWindows.Length > 0) { var w = app.WindowManager.AllWindows[0]; w.ShowWindow(false); w.BringToFront(); } return; } } ParagonRuntime.MainThreadContext.Post(delegate { RunApplicationInternal(cmdLine, appPackage, appMetadata); }, null); }
protected virtual void RunApplicationInternal(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { IParagonSplashScreen splash = null; IApplication application = null; Window splashWindow = null; var manifest = package.Manifest; #if ENFORCE_PACKAGE_SECURITY var isSigned = package.Signature != null; #endif try { ParagonLogManager.AddApplicationTraceListener(manifest.Id); // Load custom WPF theme for the application var stylePart = !string.IsNullOrEmpty(manifest.CustomTheme) ? package.GetPart(manifest.CustomTheme) : null; var styleStream = stylePart != null?stylePart.GetStream() : null; if (styleStream != null) { var theme = XamlReader.Load(styleStream) as ResourceDictionary; if (theme != null) { #if ENFORCE_PACKAGE_SECURITY if (isSigned) #endif Application.Current.Resources.MergedDictionaries.Add(theme); } } // Create and show the splash screen if needed if (cmdLine != null && !cmdLine.HasFlag("no-splash") && _createSplashScreen != null) { #if ENFORCE_PACKAGE_SECURITY splash = _createSplashScreen(isSigned ? manifest.Name : manifest.Name + " (Unsigned)", manifest.Version, package.GetIcon()); #else splash = _createSplashScreen(manifest.Name, manifest.Version, package.GetIcon()); #endif splashWindow = (Window)splash; metadata.UpdateLaunchStatus = s => { if (splash != null && splashWindow != null && splashWindow.IsVisible) { splash.ShowText(s); } }; #if ENFORCE_PACKAGE_SECURITY if (!isSigned) { splashWindow.Style = Application.Current.Resources["AlarmSplashScreenStyle"] as Style; } #endif splashWindow.Show(); } // Extract the application arguments from the command line Dictionary <string, object> args = null; if (cmdLine != null && _appArgumentParser != null) { string appArgs, appUrl; if (cmdLine.GetValue("args", out appArgs)) { args = _appArgumentParser(appArgs); } else if (cmdLine.GetValue("url", out appUrl)) { Uri uri; if (Uri.TryCreate(appUrl, UriKind.Absolute, out uri)) { if (!string.IsNullOrEmpty(uri.Query)) { args = _appArgumentParser(uri.Query.Substring(1)); } } } } //Create and register application application = _createApplication(package, metadata, args); Register(application); // Launch the application var stopWatch = AutoStopwatch.TimeIt("Launching"); application.Launched += delegate { if (splashWindow != null) { splashWindow.Dispatcher.BeginInvoke(new Action(() => { if (splashWindow != null) { splashWindow.Close(); } })); } this.RemoveSingleInstanceLaunchMarker(metadata.Id); stopWatch.Dispose(); }; application.Launch(); string protocolUri = null; if (cmdLine != null) { cmdLine.GetValue("url", out protocolUri); if (!string.IsNullOrEmpty(protocolUri)) { application.OnProtocolInvoke(protocolUri); } } } catch (Exception ex) { Logger.Info("Error starting paragon application : {0}", ex); MessageBox.Show("Unable to start:\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (splashWindow != null) { splashWindow.Close(); } if (application != null) { RemoveSingleInstanceLaunchMarker(metadata.Id); application.Close(); application = null; } } }
/// <summary> /// Launch the first application in the host process /// </summary> /// <param name="package"></param> /// <param name="metadata"></param> public void RunApplication(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { if (IsInitialized) { throw new Exception("Application manger is already initialized"); } var manifest = package.Manifest; // Initialize the following from the first application manifest ProcessGroup = manifest.ProcessGroup ?? string.Empty; CacheFolder = Path.Combine(_paragonFolder, string.IsNullOrEmpty(manifest.ProcessGroup) ? manifest.Id : manifest.ProcessGroup); Environment = metadata.Environment; DisableSpellChecking = manifest.DisableSpellChecking; // set browser language from manifest - default is en-US // "automatic" will set browser language to os culture info if (!string.IsNullOrEmpty(manifest.BrowserLanguage)) { if (string.Equals(manifest.BrowserLanguage, "Automatic", StringComparison.InvariantCultureIgnoreCase)) { BrowserLanguage = CultureInfo.CurrentCulture.Name; } else { //verify specified culture CultureInfo cultureInfo = null; try { cultureInfo = new CultureInfo(manifest.BrowserLanguage); } catch (Exception) { Logger.Error("Manifest browser language is not valid. Using default browser language en-US"); } BrowserLanguage = (cultureInfo != null) ? (cultureInfo.Name) : (BrowserLanguage); } Logger.Info(string.Format("Browser language being used is {0}", BrowserLanguage)); } string auth_server_whitelist = null; string auth_delegate_whitelist = null; if (cmdLine != null) { cmdLine.GetValue("auth-server-whitelist", out auth_server_whitelist); Logger.Info(string.Format("auth-server-whitelist [{0}]", auth_server_whitelist)); cmdLine.GetValue("auth-delegate-whitelist", out auth_delegate_whitelist); Logger.Info(string.Format("auth-delegate-whitelist [{0}]", auth_delegate_whitelist)); } // Initialize CEF using (AutoStopwatch.TimeIt("CEF initialization")) { ParagonRuntime.Initialize( CacheFolder, null, BrowserLanguage, auth_server_whitelist, auth_delegate_whitelist, DisableSpellChecking, Environment == ApplicationEnvironment.Development); } RunApplicationInternal(cmdLine, package, metadata); }