Skip to content

Commit 46f39ac

Browse files
author
lampenlampen
authored
Feat/CmdLineActivation (#391)
* Activate CmdLineActivation & fixed Regression
1 parent 7e7c20a commit 46f39ac

File tree

2 files changed

+65
-20
lines changed

2 files changed

+65
-20
lines changed

Files/App.xaml.cs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Windows.UI.Core;
2323
using Windows.UI.Xaml.Controls.Primitives;
2424
using Windows.System;
25+
using Files.CommandLine;
2526
using Files.View_Models;
2627

2728
namespace Files
@@ -511,31 +512,74 @@ protected override void OnActivated(IActivatedEventArgs args)
511512
Window.Current.Content = rootFrame;
512513
}
513514

514-
if (args.Kind == ActivationKind.Protocol)
515+
switch (args.Kind)
515516
{
516-
var eventArgs = args as ProtocolActivatedEventArgs;
517+
case ActivationKind.Protocol:
518+
var eventArgs = args as ProtocolActivatedEventArgs;
517519

518-
if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
519-
{
520-
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
521-
}
522-
else
523-
{
524-
var trimmedPath = eventArgs.Uri.OriginalString.Split('=')[1];
525-
rootFrame.Navigate(typeof(InstanceTabsView), @trimmedPath, new SuppressNavigationTransitionInfo());
526-
}
527-
// Ensure the current window is active.
528-
Window.Current.Activate();
529-
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
530-
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
531-
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
532-
return;
520+
if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
521+
{
522+
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
523+
}
524+
else
525+
{
526+
var trimmedPath = eventArgs.Uri.OriginalString.Split('=')[1];
527+
rootFrame.Navigate(typeof(InstanceTabsView), @trimmedPath, new SuppressNavigationTransitionInfo());
528+
}
529+
// Ensure the current window is active.
530+
Window.Current.Activate();
531+
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
532+
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
533+
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
534+
return;
535+
536+
case ActivationKind.CommandLineLaunch:
537+
var cmdLineArgs = args as CommandLineActivatedEventArgs;
538+
var operation = cmdLineArgs.Operation;
539+
var cmdLineString = operation.Arguments;
540+
var activationPath = operation.CurrentDirectoryPath;
541+
542+
var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);
543+
544+
if (parsedCommands != null && parsedCommands.Count > 0)
545+
{
546+
foreach (var command in parsedCommands)
547+
{
548+
switch (command.Type)
549+
{
550+
case ParsedCommandType.OpenDirectory:
551+
// TODO Open Directory
552+
553+
rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());
554+
555+
// Ensure the current window is active.
556+
Window.Current.Activate();
557+
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
558+
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
559+
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
560+
561+
return;
562+
case ParsedCommandType.Unkwon:
563+
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
564+
// Ensure the current window is active.
565+
Window.Current.Activate();
566+
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
567+
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
568+
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
569+
return;
570+
}
571+
}
572+
}
573+
break;
533574
}
534-
575+
535576
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
536577

537578
// Ensure the current window is active.
538579
Window.Current.Activate();
580+
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
581+
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
582+
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
539583
}
540584

541585
private void TryEnablePrelaunch()

Files/ProHome.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
148148
break;
149149

150150
default:
151-
if (NavParams.Contains("C:", StringComparison.OrdinalIgnoreCase))
151+
if (NavParams[0] >= 'A' && NavParams[0] <= 'Z' && NavParams[1] == ':')
152152
{
153-
DrivesList.SelectedItem = SettingsViewModel.foundDrives.First(x => x.tag.ToString().Equals("C:\\", StringComparison.OrdinalIgnoreCase));
153+
ItemDisplayFrame.Navigate(typeof(GenericFileBrowser), NavParams, new SuppressNavigationTransitionInfo());
154+
DrivesList.SelectedItem = SettingsViewModel.foundDrives.First(x => x.tag.ToString().Equals($"{NavParams[0]}:\\", StringComparison.OrdinalIgnoreCase));
154155
}
155156
else
156157
{

0 commit comments

Comments
 (0)