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
2 changes: 2 additions & 0 deletions src/App.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public static bool IsCheckForUpdateCommandVisible
{
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
{
WindowTrace.Write($"Preferences open(menu): ownerState={owner.WindowState} ownerBounds={owner.Bounds} ownerClient={owner.ClientSize}");
var dialog = new Views.Preferences();
await dialog.ShowDialog(owner);
WindowTrace.Write($"Preferences closed(menu): ownerState={owner.WindowState} ownerBounds={owner.Bounds} ownerClient={owner.ClientSize}");
}
});

Expand Down
1 change: 1 addition & 0 deletions src/App.JsonCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public override void Write(Utf8JsonWriter writer, GridLength value, JsonSerializ
[JsonSerializable(typeof(List<Models.VisualStudioInstance>))]
[JsonSerializable(typeof(ViewModels.Preferences))]
[JsonSerializable(typeof(ViewModels.RepositoryNodeMinimalInfo))]
[JsonSerializable(typeof(Models.ProjectsSaveModel))]
[JsonSerializable(typeof(List<AI.ApiKey>))]
internal partial class JsonCodeGen : JsonSerializerContext { }
}
64 changes: 61 additions & 3 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static void Main(string[] args)
{
Native.OS.SetupBasicDirectories();

var scanLogFromEnv = Environment.GetEnvironmentVariable("SOURCEGIT_SCAN_LOG");
if (!string.IsNullOrEmpty(scanLogFromEnv))
Models.ScanLog.Open(scanLogFromEnv);

AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
Native.OS.LogException(e.ExceptionObject as Exception);
Expand All @@ -37,7 +41,9 @@ public static void Main(string[] args)

try
{
if (TryLaunchAsRebaseTodoEditor(args, out int exitTodo))
if (TryRunScanCommand(args, out int exitScan))
Environment.Exit(exitScan);
else if (TryLaunchAsRebaseTodoEditor(args, out int exitTodo))
Environment.Exit(exitTodo);
else if (TryLaunchAsRebaseMessageEditor(args, out int exitMessage))
Environment.Exit(exitMessage);
Expand All @@ -58,7 +64,7 @@ public static AppBuilder BuildAvaloniaApp()
builder.WithInterFont();
builder.With(new FontManagerOptions()
{
DefaultFamilyName = "fonts:Inter#Inter"
DefaultFamilyName = Models.PlatformFonts.PrimaryFamily
});
builder.ConfigureFonts(manager =>
{
Expand Down Expand Up @@ -183,6 +189,12 @@ public static void SetFonts(string defaultFont, string monospaceFont)
defaultFont = StringExtensions.FormatFontNames(defaultFont);
monospaceFont = StringExtensions.FormatFontNames(monospaceFont);

// An empty preference means "use the platform default", not "use Inter for everything":
// Inter has no CJK glyphs, so leaving it in place lets the platform fallback pick an
// arbitrary Chinese font and mixed lines end up with a mismatched baseline.
if (string.IsNullOrEmpty(defaultFont))
defaultFont = Models.PlatformFonts.DefaultFamily;

var resDic = new ResourceDictionary();
if (!string.IsNullOrEmpty(defaultFont))
resDic.Add("Fonts.Default", new FontFamily(defaultFont));
Expand All @@ -191,7 +203,7 @@ public static void SetFonts(string defaultFont, string monospaceFont)
{
if (!string.IsNullOrEmpty(defaultFont))
{
monospaceFont = $"fonts:SourceGit#JetBrains Mono NL,{defaultFont}";
monospaceFont = $"fonts:SourceGit#JetBrains Mono NL,{Models.PlatformFonts.MonospaceFallback},{defaultFont}";
resDic.Add("Fonts.Monospace", FontFamily.Parse(monospaceFont));
}
}
Expand Down Expand Up @@ -278,6 +290,52 @@ public override void OnFrameworkInitializationCompleted()
}
#endregion

#region Scan Diagnostics
/// <summary>
/// Headless diagnostic entry: `SourceGit --scan-log <dir> [--log <file>]` scans the
/// directory with the exact scanner used by the project tree, writes a trace and
/// exits. Used to tell a "slow scan" apart from a "scan finds nothing" failure.
/// </summary>
private static bool TryRunScanCommand(string[] args, out int exitCode)
{
exitCode = 0;

if (args == null || args.Length < 2 || !args[0].Equals("--scan-log", StringComparison.Ordinal))
return false;

var target = args[1];
var logPath = Path.Combine(Path.GetTempPath(), "sourcegit_scan.log");
if (args.Length >= 4 && args[2].Equals("--log", StringComparison.Ordinal))
logPath = args[3];

Models.ScanLog.Open(logPath);
Models.ScanLog.Write($"headless scan: target='{target}' log='{logPath}'");

// In GUI mode this is assigned while loading preferences. Headless runs must do
// it explicitly, otherwise every git process fails to start and is dropped.
Native.OS.GitExecutable = Native.OS.FindGitExecutable();
Models.ScanLog.Write($"headless scan: git executable='{Native.OS.GitExecutable}'");

try
{
var repos = Models.RepositoryScanner.ScanAsync(target, new Models.ScanLogProgress(), new Models.ScanLogProgress())
.GetAwaiter()
.GetResult();

Models.ScanLog.Write($"headless scan: RESULT {repos.Count} repositories");
foreach (var repo in repos)
Models.ScanLog.Write($"headless scan: {repo}");
}
catch (Exception e)
{
Models.ScanLog.Write($"headless scan: EXCEPTION {e}");
exitCode = 2;
}

return true;
}
#endregion

#region Launch Ways
private static bool TryLaunchAsRebaseTodoEditor(string[] args, out int exitCode)
{
Expand Down
72 changes: 72 additions & 0 deletions src/Models/PlatformFonts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;

namespace SourceGit.Models
{
/// <summary>
/// Per-platform font defaults.
///
/// The embedded Inter font is used so every build renders western text identically, but it
/// carries no CJK coverage: Chinese characters are then filled in by whatever family the
/// platform happens to fall back to, which leaves mixed-script lines with a mismatched
/// baseline and weight. Naming an explicit CJK family per platform fixes that without
/// embedding a CJK font (which would add 8-15 MB to every build).
///
/// Only used when the corresponding preference is empty, so whatever the user typed in
/// Preferences > Appearance always wins.
/// </summary>
public static class PlatformFonts
{
/// <summary>UI font for western text, followed by the CJK family to fall back to.</summary>
public static string DefaultFamily
{
get
{
if (OperatingSystem.IsWindows())
return "Segoe UI,Microsoft YaHei UI";

if (OperatingSystem.IsMacOS())
return "Helvetica Neue,PingFang SC";

return "Noto Sans,Noto Sans CJK SC,Source Han Sans SC,DejaVu Sans";
}
}

/// <summary>
/// Tail of the monospace list: JetBrains Mono NL is embedded and comes first, these only
/// cover the characters it does not have (CJK, and a last-resort system fallback).
/// </summary>
public static string MonospaceFallback
{
get
{
if (OperatingSystem.IsWindows())
return "Cascadia Mono,Consolas,Microsoft YaHei UI";

if (OperatingSystem.IsMacOS())
return "Menlo,Monaco,PingFang SC";

return "Noto Sans Mono CJK SC,DejaVu Sans Mono";
}
}

/// <summary>
/// Family used for controls that do not set a font themselves (Avalonia's
/// FontManagerOptions only takes a single name, so this is the first family above).
/// </summary>
public static string PrimaryFamily
{
get
{
var comma = DefaultFamily.IndexOf(',');
return comma < 0 ? DefaultFamily : DefaultFamily.Substring(0, comma).Trim();
}
}

/// <summary>
/// Same DIP size reads larger on Linux: fontconfig resolves a slightly bigger x-height
/// than DirectWrite, so 13 there looks like 14+ does on Windows. 12 keeps both builds
/// visually similar at the default 100% scaling.
/// </summary>
public static double DefaultFontSize => OperatingSystem.IsLinux() ? 12.0 : 13.0;
}
}
26 changes: 26 additions & 0 deletions src/Models/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace SourceGit.Models
{
/// <summary>
/// A "project" is a user-defined container that owns one or more directories.
/// Repositories are discovered by scanning those directories and are NOT stored
/// here - they are rebuilt on every scan so that the file system stays the source
/// of truth.
/// </summary>
public class Project
{
public string Name { get; set; } = string.Empty;
public List<string> Directories { get; set; } = new List<string>();
}

/// <summary>
/// Root object persisted to projects.json.
/// Nodes are expanded by default, so only the paths the user collapsed are stored.
/// </summary>
public class ProjectsSaveModel
{
public List<Project> Projects { get; set; } = new List<Project>();
public List<string> Collapsed { get; set; } = new List<string>();
}
}
Loading