protected override async void OnFileActivated(FileActivatedEventArgs e) { await logWriter.InitializeAsync("debug.log"); Logger.Info("App activated by file"); //start tracking app usage SystemInformation.Instance.TrackAppUse(e); await EnsureSettingsAndConfigurationAreBootstrapped(); _ = InitializeAppComponentsAsync().ContinueWith(t => Logger.Warn(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted); var rootFrame = EnsureWindowIsInitialized(); var index = 0; if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Files.First().Path, new SuppressNavigationTransitionInfo()); index = 1; } for (; index < e.Files.Count; index++) { await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Files[index].Path); } // Ensure the current window is active Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; WindowDecorationsHelper.RequestWindowDecorationsAccess(); }
protected override async void OnActivated(IActivatedEventArgs args) { await logWriter.InitializeAsync("debug.log"); Logger.Info($"App activated by {args.Kind.ToString()}"); await EnsureSettingsAndConfigurationAreBootstrapped(); _ = InitializeAppComponentsAsync().ContinueWith(t => Logger.Warn(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted); var rootFrame = EnsureWindowIsInitialized(); switch (args.Kind) { case ActivationKind.Protocol: var eventArgs = args as ProtocolActivatedEventArgs; if (eventArgs.Uri.AbsoluteUri == "files-uwp:") { rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); } else { var parsedArgs = eventArgs.Uri.Query.TrimStart('?').Split('='); var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]); var folder = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(unescapedValue).AsTask()); if (folder != null && !string.IsNullOrEmpty(folder.Path)) { unescapedValue = folder.Path; // Convert short name to long name (#6190) } switch (parsedArgs[0]) { case "tab": rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo()); break; case "folder": rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo()); break; } } // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; return; case ActivationKind.CommandLineLaunch: var cmdLineArgs = args as CommandLineActivatedEventArgs; var operation = cmdLineArgs.Operation; var cmdLineString = operation.Arguments; var activationPath = operation.CurrentDirectoryPath; var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString); if (parsedCommands != null && parsedCommands.Count > 0) { async Task PerformNavigation(string payload, string selectItem = null) { if (!string.IsNullOrEmpty(payload)) { payload = CommonPaths.ShellPlaces.Get(payload.ToUpperInvariant(), payload); var folder = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(payload).AsTask()); if (folder != null && !string.IsNullOrEmpty(folder.Path)) { payload = folder.Path; // Convert short name to long name (#6190) } } var paneNavigationArgs = new PaneNavigationArguments { LeftPaneNavPathParam = payload, LeftPaneSelectItemParam = selectItem, }; if (rootFrame.Content != null) { await MainPageViewModel.AddNewTabByParam(typeof(PaneHolderPage), paneNavigationArgs); } else { rootFrame.Navigate(typeof(MainPage), paneNavigationArgs, new SuppressNavigationTransitionInfo()); } } foreach (var command in parsedCommands) { switch (command.Type) { case ParsedCommandType.OpenDirectory: case ParsedCommandType.OpenPath: case ParsedCommandType.ExplorerShellCommand: var selectItemCommand = parsedCommands.FirstOrDefault(x => x.Type == ParsedCommandType.SelectItem); await PerformNavigation(command.Payload, selectItemCommand?.Payload); break; case ParsedCommandType.SelectItem: if (Path.IsPathRooted(command.Payload)) { await PerformNavigation(Path.GetDirectoryName(command.Payload), Path.GetFileName(command.Payload)); } break; case ParsedCommandType.Unknown: if (command.Payload.Equals(".")) { await PerformNavigation(activationPath); } else { var target = Path.GetFullPath(Path.Combine(activationPath, command.Payload)); if (!string.IsNullOrEmpty(command.Payload)) { await PerformNavigation(target); } else { await PerformNavigation(null); } } break; case ParsedCommandType.OutputPath: OutputPath = command.Payload; break; } } if (rootFrame.Content != null) { // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; return; } } break; case ActivationKind.ToastNotification: var eventArgsForNotification = args as ToastNotificationActivatedEventArgs; if (eventArgsForNotification.Argument == "report") { await Launcher.LaunchUriAsync(new Uri(Constants.GitHub.FeedbackUrl)); } break; case ActivationKind.StartupTask: break; } rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; WindowDecorationsHelper.RequestWindowDecorationsAccess(); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { await logWriter.InitializeAsync("debug.log"); Logger.Info($"App launched. Prelaunch: {e.PrelaunchActivated}"); //start tracking app usage SystemInformation.Instance.TrackAppUse(e); bool canEnablePrelaunch = ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch"); await EnsureSettingsAndConfigurationAreBootstrapped(); _ = InitializeAppComponentsAsync().ContinueWith(t => Logger.Warn(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted); var rootFrame = EnsureWindowIsInitialized(); if (e.PrelaunchActivated == false) { if (canEnablePrelaunch) { TryEnablePrelaunch(); } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments, new SuppressNavigationTransitionInfo()); } else { if (!(string.IsNullOrEmpty(e.Arguments) && MainPageViewModel.AppInstances.Count > 0)) { await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments); } } // Ensure the current window is active Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; } else { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments, new SuppressNavigationTransitionInfo()); } else { if (!(string.IsNullOrEmpty(e.Arguments) && MainPageViewModel.AppInstances.Count > 0)) { await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments); } } } WindowDecorationsHelper.RequestWindowDecorationsAccess(); }