protected override async void OnActivated(IActivatedEventArgs args) { Logger.Info("App activated"); // Window management if (!(Window.Current.Content is Frame rootFrame)) { rootFrame = new Frame(); Window.Current.Content = rootFrame; } ThemeHelper.Initialize(); var currentView = SystemNavigationManager.GetForCurrentView(); switch (args.Kind) { case ActivationKind.Protocol: var eventArgs = args as ProtocolActivatedEventArgs; if (eventArgs.Uri.AbsoluteUri == "files-uwp:") { rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo()); } else { var trimmedPath = eventArgs.Uri.OriginalString.Split('=')[1]; rootFrame.Navigate(typeof(InstanceTabsView), @trimmedPath, new SuppressNavigationTransitionInfo()); } // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; currentView.BackRequested += Window_BackRequested; 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) { foreach (var command in parsedCommands) { switch (command.Type) { case ParsedCommandType.OpenDirectory: rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; currentView.BackRequested += Window_BackRequested; return; case ParsedCommandType.OpenPath: try { var det = await StorageFolder.GetFolderFromPathAsync(command.Payload); rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; currentView.BackRequested += Window_BackRequested; return; } catch (System.IO.FileNotFoundException ex) { //Not a folder Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}"); } catch (Exception ex) { Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}"); } break; case ParsedCommandType.Unknown: rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; currentView.BackRequested += Window_BackRequested; return; } } } break; } rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; }
protected override async void OnActivated(IActivatedEventArgs args) { Logger.Info("App activated"); // Window management if (!(Window.Current.Content is Frame rootFrame)) { rootFrame = new Frame(); rootFrame.CacheSize = 1; Window.Current.Content = rootFrame; } var currentView = SystemNavigationManager.GetForCurrentView(); 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]); 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) { foreach (var command in parsedCommands) { switch (command.Type) { case ParsedCommandType.OpenDirectory: rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; return; case ParsedCommandType.OpenPath: try { var det = await StorageFolder.GetFolderFromPathAsync(command.Payload); rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; return; } catch (System.IO.FileNotFoundException ex) { //Not a folder Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}"); } catch (Exception ex) { Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}"); } break; case ParsedCommandType.Unknown: rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); // 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") { // Launch the URI and open log files location //SettingsViewModel.OpenLogLocation(); SettingsViewModel.ReportIssueOnGitHub(); } break; } rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); // Ensure the current window is active. Window.Current.Activate(); Window.Current.CoreWindow.Activated += CoreWindow_Activated; }
private async void VisiblePath_TextChanged(object sender, KeyRoutedEventArgs e) { if (e.Key == VirtualKey.Enter) { var PathBox = (sender as TextBox); var CurrentInput = PathBox.Text; if (CurrentInput != ItemViewModel.PUIP.Path) { if (ItemViewModel.tokenSource != null) { ItemViewModel.tokenSource.Cancel(); ItemViewModel.FilesAndFolders.Clear(); } if (CurrentInput == "Home" || CurrentInput == "home") { MainPage.accessibleContentFrame.Navigate(typeof(YourHome)); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Recents"; } else if (CurrentInput == "Desktop" || CurrentInput == "desktop") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DesktopPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Desktop"; PathBox.Text = "Desktop"; } else if (CurrentInput == "Documents" || CurrentInput == "documents") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DocumentsPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Documents"; PathBox.Text = "Documents"; } else if (CurrentInput == "Downloads" || CurrentInput == "downloads") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DownloadsPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Downloads"; PathBox.Text = "Downloads"; } else if (CurrentInput == "Pictures" || CurrentInput == "pictures") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(PhotoAlbum), MainPage.PicturesPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Pictures"; } else if (CurrentInput == "Music" || CurrentInput == "music") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.MusicPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Music"; PathBox.Text = "Music"; } else if (CurrentInput == "Videos" || CurrentInput == "videos") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.VideosPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Videos"; PathBox.Text = "Videos"; } else if (CurrentInput == "OneDrive" || CurrentInput == "Onedrive" || CurrentInput == "onedrive") { ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.OneDrivePath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search OneDrive"; PathBox.Text = "OneDrive"; } else { if (CurrentInput.Contains(".")) { if (CurrentInput.Contains(".exe") || CurrentInput.Contains(".EXE")) { if (StorageFile.GetFileFromPathAsync(CurrentInput) != null) { await Interaction.LaunchExe(CurrentInput); PathBox.Text = ItemViewModel.PUIP.Path; } else { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } else { try { await StorageFile.GetFileFromPathAsync(CurrentInput); StorageFile file = await StorageFile.GetFileFromPathAsync(CurrentInput); var options = new LauncherOptions { DisplayApplicationPicker = false }; await Launcher.LaunchFileAsync(file, options); PathBox.Text = ItemViewModel.PUIP.Path; } catch (ArgumentException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } catch (FileNotFoundException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } } else { try { await StorageFolder.GetFolderFromPathAsync(CurrentInput); ItemViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), CurrentInput); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search"; } catch (ArgumentException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } catch (FileNotFoundException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } } } } }