Skip to content
Open
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
78 changes: 62 additions & 16 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,25 @@ public override void OnFrameworkInitializationCompleted()
_ipcChannel = new Models.IpcChannel();
if (!_ipcChannel.IsFirstInstance)
{
var arg = desktop.Args is { Length: > 0 } ? desktop.Args[0].Trim() : string.Empty;
if (!string.IsNullOrEmpty(arg))
var argsToSend = new List<string>();
if (desktop.Args != null)
{
if (arg.StartsWith('"') && arg.EndsWith('"'))
arg = arg.Substring(1, arg.Length - 2).Trim();
for (int i = 0; i < desktop.Args.Length; i++)
{
var arg = desktop.Args[i].Trim();
if (i == 0 && !arg.StartsWith("--"))
{
if (arg.StartsWith('"') && arg.EndsWith('"'))
arg = arg.Substring(1, arg.Length - 2).Trim();

if (arg.Length > 0 && !Path.IsPathFullyQualified(arg))
arg = Path.GetFullPath(arg);
if (arg.Length > 0 && !Path.IsPathFullyQualified(arg))
arg = Path.GetFullPath(arg);
}
argsToSend.Add(arg);
}
}

_ipcChannel.SendToFirstInstance(arg);
_ipcChannel.SendToFirstInstance(string.Join("\n", argsToSend));
Environment.Exit(0);
}
else
Expand Down Expand Up @@ -663,8 +671,8 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
Models.AvatarManager.Instance.Start();

string startupRepo = null;
if (desktop.Args is { Length: 1 } && Directory.Exists(desktop.Args[0]))
startupRepo = desktop.Args[0];
if (desktop.Args != null)
ParsedArgs = ParseArgs(desktop.Args, out startupRepo);

var pref = ViewModels.Preferences.Instance;
pref.SetCanModify();
Expand All @@ -679,8 +687,14 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
#endif
}

private void TryOpenRepository(string repo)
private void TryOpenRepository(string message)
{
if (string.IsNullOrWhiteSpace(message))
return;

string[] args = message.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
ParsedArgs = ParseArgs(args, out string repo);

if (!string.IsNullOrEmpty(repo) && Directory.Exists(repo))
{
var test = new Commands.QueryRepositoryRootPath(repo).GetResult();
Expand Down Expand Up @@ -801,16 +815,48 @@ private string FixFontFamilyName(string input)
}
}

return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty;
return string.Join(",", trimmed);
}

public class LaunchArguments
{
public bool IgnoreWorkspace { get; set; }
public bool NoSaveWorkspace { get; set; }
public int? StartupViewIndex { get; set; }
}

public static LaunchArguments ParseArgs(string[] args, out string repoPath)
{
repoPath = null;
var parsed = new LaunchArguments();
for (int i = 0; i < args.Length; i++)
{
var arg = args[i].Trim();
if (arg.Equals("--ignore-workspace", StringComparison.OrdinalIgnoreCase))
parsed.IgnoreWorkspace = true;
else if (arg.Equals("--no-save-workspace", StringComparison.OrdinalIgnoreCase))
parsed.NoSaveWorkspace = true;
else if (arg.Equals("--commit", StringComparison.OrdinalIgnoreCase))
parsed.StartupViewIndex = 1;
else if (arg.Equals("--history", StringComparison.OrdinalIgnoreCase))
parsed.StartupViewIndex = 0;
else if (arg.Equals("--stashes", StringComparison.OrdinalIgnoreCase))
parsed.StartupViewIndex = 2;
else if (i == 0 && !arg.StartsWith("--"))
repoPath = arg;
}
return parsed;
}

public static LaunchArguments ParsedArgs { get; set; } = new LaunchArguments();

[GeneratedRegex(@"^[a-z]+\s+([a-fA-F0-9]{4,40})(\s+.*)?$")]
private static partial Regex REG_REBASE_TODO();

private Models.IpcChannel _ipcChannel = null;
private ViewModels.Launcher _launcher = null;
private ResourceDictionary _activeLocale = null;
private ResourceDictionary _themeOverrides = null;
private ResourceDictionary _fontsOverrides = null;
private Models.IpcChannel _ipcChannel;
private ResourceDictionary _activeLocale;
private ResourceDictionary _themeOverrides;
private ResourceDictionary _fontsOverrides;
private ViewModels.Launcher _launcher;
}
}
23 changes: 13 additions & 10 deletions src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ public Launcher(string startupRepo)
ActiveWorkspace = pref.GetActiveWorkspace();

var repos = ActiveWorkspace.Repositories.ToArray();
foreach (var repo in repos)
if (!App.ParsedArgs.IgnoreWorkspace)
{
var node = pref.FindNode(repo) ??
new RepositoryNode
{
Id = repo,
Name = Path.GetFileName(repo),
Bookmark = 0,
IsRepository = true,
};
foreach (var repo in repos)
{
var node = pref.FindNode(repo) ??
new RepositoryNode
{
Id = repo,
Name = Path.GetFileName(repo),
Bookmark = 0,
IsRepository = true,
};

OpenRepositoryInTab(node, null);
OpenRepositoryInTab(node, null);
}
}

_ignoreIndexChange = false;
Expand Down
3 changes: 3 additions & 0 deletions src/ViewModels/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ public void Save()
if (_isLoading || _isReadonly)
return;

if (App.ParsedArgs != null && App.ParsedArgs.NoSaveWorkspace)
return;

var file = Path.Combine(Native.OS.DataDir, "preference.json");
using var stream = File.Create(file);
JsonSerializer.Serialize(stream, this, JsonCodeGen.Default.Preferences);
Expand Down
22 changes: 20 additions & 2 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -465,7 +465,25 @@ public void Open()
_stashesPage = new StashesPage(this);
_searchCommitContext = new SearchCommitContext(this);

if (Preferences.Instance.ShowLocalChangesByDefault)
if (App.ParsedArgs != null && App.ParsedArgs.StartupViewIndex.HasValue)
{
switch (App.ParsedArgs.StartupViewIndex.Value)
{
case 1:
_selectedView = _workingCopy;
_selectedViewIndex = 1;
break;
case 2:
_selectedView = _stashesPage;
_selectedViewIndex = 2;
break;
default:
_selectedView = _histories;
_selectedViewIndex = 0;
break;
}
}
else if (Preferences.Instance.ShowLocalChangesByDefault)
{
_selectedView = _workingCopy;
_selectedViewIndex = 1;
Expand Down