Skip to content

Feature: Added option to open tab in new/existing instance #13743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Files.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void Main()
WinRT.ComWrappersSupport.InitializeComWrappers();

var proc = Process.GetCurrentProcess();
var alwaysOpenNewInstance = ApplicationData.Current.LocalSettings.Values.Get("AlwaysOpenANewInstance", false);
var OpenTabInExistingInstance = ApplicationData.Current.LocalSettings.Values.Get("OpenTabInExistingInstance", true);
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();

if (activatedArgs.Data is ICommandLineActivatedEventArgs cmdLineArgs)
Expand Down Expand Up @@ -76,7 +76,7 @@ private static void Main()

// Always open a new instance for OpenDialog, never open new instance for "-Tag" command
if (parsedCommands is null || !parsedCommands.Any(x => x.Type == ParsedCommandType.OutputPath) &&
(!alwaysOpenNewInstance || parsedCommands.Any(x => x.Type == ParsedCommandType.TagFiles)))
(OpenTabInExistingInstance || parsedCommands.Any(x => x.Type == ParsedCommandType.TagFiles)))
{
var activePid = ApplicationData.Current.LocalSettings.Values.Get("INSTANCE_ACTIVE", -1);
var instance = AppInstance.FindOrRegisterForKey(activePid.ToString());
Expand All @@ -102,7 +102,7 @@ private static void Main()
}
}

if (!alwaysOpenNewInstance)
if (OpenTabInExistingInstance)
{
if (activatedArgs.Data is ILaunchActivatedEventArgs launchArgs)
{
Expand All @@ -117,7 +117,8 @@ private static void Main()
else if (activatedArgs.Data is IProtocolActivatedEventArgs protocolArgs)
{
var parsedArgs = protocolArgs.Uri.Query.TrimStart('?').Split('=');
if (parsedArgs.Length == 2 && parsedArgs[0] == "cmd") // Treat as command line launch
if ((parsedArgs.Length == 2 && parsedArgs[0] == "cmd") ||
parsedArgs.Length == 1) // Treat Win+E & Open file location as command line launch
{
var activePid = ApplicationData.Current.LocalSettings.Values.Get("INSTANCE_ACTIVE", -1);
var instance = AppInstance.FindOrRegisterForKey(activePid.ToString());
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Services/Settings/GeneralSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public bool OpenNewTabOnStartup
set => Set(value);
}

public bool AlwaysOpenNewInstance
public bool OpenTabInExistingInstance
{
get => Get(false);
get => Get(true);
set => Set(value);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(OpenSpecificPageOnStartup):
case nameof(ContinueLastSessionOnStartUp):
case nameof(OpenNewTabOnStartup):
case nameof(AlwaysOpenNewInstance):
case nameof(OpenTabInExistingInstance):
case nameof(AlwaysOpenDualPaneInNewTab):
case nameof(ShowQuickAccessWidget):
case nameof(ShowRecentFilesWidget):
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1815,8 +1815,8 @@
<data name="RestoreDefault" xml:space="preserve">
<value>Restore default</value>
</data>
<data name="OpenNewInstance" xml:space="preserve">
<value>Open new instance when opening directories from the taskbar jumplist</value>
<data name="OpenTabInExistingInstance" xml:space="preserve">
<value>Open tab in existing instance when opening Files from another app</value>
</data>
<data name="StartupSettings" xml:space="preserve">
<value>Startup settings</value>
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ public ReadOnlyCollection<IMenuFlyoutItemViewModel> AddFlyoutItemsSource
set => SetProperty(ref addFlyoutItemsSource, value);
}

public bool AlwaysOpenANewInstance
public bool OpenTabInExistingInstance
{
get => UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance;
get => UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance;
set
{
if (value != UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance)
if (value != UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance)
{
UserSettingsService.GeneralSettingsService.AlwaysOpenNewInstance = value;
UserSettingsService.GeneralSettingsService.OpenTabInExistingInstance = value;

// Needed in Program.cs
ApplicationData.Current.LocalSettings.Values["AlwaysOpenANewInstance"] = value;
ApplicationData.Current.LocalSettings.Values["OpenTabInExistingInstance"] = value;

OnPropertyChanged();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Views/Settings/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@
</ListView>
</Grid>

<local:SettingsBlockControl Title="{helpers:ResourceString Name=OpenNewInstance}" HorizontalAlignment="Stretch">
<local:SettingsBlockControl Title="{helpers:ResourceString Name=OpenTabInExistingInstance}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=OpenNewInstance}"
IsOn="{x:Bind ViewModel.AlwaysOpenANewInstance, Mode=TwoWay}"
AutomationProperties.Name="{helpers:ResourceString Name=OpenTabInExistingInstance}"
IsOn="{x:Bind ViewModel.OpenTabInExistingInstance, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>
</StackPanel>
Expand Down
4 changes: 2 additions & 2 deletions src/Files.Core/Services/Settings/IGeneralSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
bool OpenNewTabOnStartup { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not opening the app from the jumplist should open the directory in a new instance.
/// Gets or sets a value indicating whether or not opening Files from another app should open a tab in the existing instance.
/// </summary>
bool AlwaysOpenNewInstance { get; set; }
bool OpenTabInExistingInstance { get; set; }

/// <summary>
/// A list containing all paths to open at startup.
Expand Down