Skip to content

Commit 3d9dd41

Browse files
committed
feat: add HTTP protocol preference for visit URLs
- Add support for optional HTTP protocol preference when generating visit URLs from remote repository links. - Add a preference option to prefer HTTP over HTTPS when generating visit URLs. - Add a preference option to prioritize HTTP over HTTPS when accessing URLs. - Add a new localization string for preferring HTTP when visiting URLs in Git preferences. - Update commit detail view model to set remote preference for HTTP protocol usage based on user settings. - Add a preference option to use HTTP when visiting repositories. - Update remote preferences to use HTTP when visiting based on user settings. - Add a property to toggle HTTP preference for repository visits. - Add a preference option to prefer HTTP when visiting repositories.
1 parent 9ac6afa commit 3d9dd41

File tree

9 files changed

+35
-3
lines changed

9 files changed

+35
-3
lines changed

src/Models/Remote.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public partial class Remote
3131

3232
public string Name { get; set; }
3333
public string URL { get; set; }
34+
public bool PreferHttpWhenVisit { get; set; }
3435

3536
public static bool IsSSH(string url)
3637
{
@@ -78,7 +79,8 @@ public bool TryGetVisitURL(out string url)
7879
var match = REG_TO_VISIT_URL_CAPTURE().Match(URL);
7980
if (match.Success)
8081
{
81-
url = $"https://{match.Groups[1].Value}/{match.Groups[2].Value}";
82+
var scheme = PreferHttpWhenVisit ? "http" : "https";
83+
url = $"{scheme}://{match.Groups[1].Value}/{match.Groups[2].Value}";
8284
return true;
8385
}
8486

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@
619619
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">Enable --ignore-cr-at-eol in diff</x:String>
620620
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Git (&gt;= 2.25.1) is required by this app</x:String>
621621
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Install Path</x:String>
622+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">Prefer HTTP when generating visit URLs</x:String>
622623
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Enable HTTP SSL Verify</x:String>
623624
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">Use git-credential-libsecret instead of git-credential-manager</x:String>
624625
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">User Name</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@
623623
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">对比文件时,默认忽略换行符变更 (--ignore-cr-at-eol)</x:String>
624624
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">本软件要求GIT最低版本为2.25.1</x:String>
625625
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">安装路径</x:String>
626+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">访问URL时优先使用HTTP</x:String>
626627
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">启用HTTP SSL验证</x:String>
627628
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 替代 git-credential-manager</x:String>
628629
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">用户名</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@
623623
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">對比檔案時,預設忽略行末的 CR 變更 (--ignore-cr-at-eol)</x:String>
624624
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">本軟體要求 Git 最低版本為 2.25.1</x:String>
625625
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">安裝路徑</x:String>
626+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">訪問URL時優先使用HTTP</x:String>
626627
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">啟用 HTTP SSL 驗證</x:String>
627628
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 取代 git-credential-manager</x:String>
628629
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">使用者名稱</x:String>

src/ViewModels/CommitDetail.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public CommitDetail(Repository repo, CommitDetailSharedData sharedData)
172172
{
173173
_repo = repo;
174174
_sharedData = sharedData ?? new CommitDetailSharedData();
175+
176+
foreach (var r in repo.Remotes)
177+
r.PreferHttpWhenVisit = Preferences.Instance.PreferHttpWhenVisit;
178+
175179
WebLinks = Models.CommitLink.Get(repo.Remotes);
176180
}
177181

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ public bool ShowHiddenSymbolsInDiffView
264264
set => SetProperty(ref _showHiddenSymbolsInDiffView, value);
265265
}
266266

267+
public bool PreferHttpWhenVisit
268+
{
269+
get => _preferHttpWhenVisit;
270+
set => SetProperty(ref _preferHttpWhenVisit, value);
271+
}
272+
267273
public bool UseFullTextDiff
268274
{
269275
get => _useFullTextDiff;
@@ -792,6 +798,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
792798
private bool _useSyntaxHighlighting = false;
793799
private bool _enableDiffViewWordWrap = false;
794800
private bool _showHiddenSymbolsInDiffView = false;
801+
private bool _preferHttpWhenVisit = false;
795802
private bool _useFullTextDiff = false;
796803
private int _lfsImageActiveIdx = 0;
797804
private int _imageDiffActiveIdx = 0;

src/ViewModels/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@ public void RefreshBranches()
10911091
var remotes = await new Commands.QueryRemotes(FullPath).GetResultAsync().ConfigureAwait(false);
10921092
var builder = BuildBranchTree(branches, remotes);
10931093

1094+
foreach (var r in remotes)
1095+
{
1096+
r.PreferHttpWhenVisit = Preferences.Instance.PreferHttpWhenVisit;
1097+
}
1098+
10941099
Dispatcher.UIThread.Invoke(() =>
10951100
{
10961101
if (token.IsCancellationRequested)

src/Views/Preferences.axaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
Height="32"
137137
Content="{DynamicResource Text.Preferences.General.ShowChangesPageByDefault}"
138138
IsChecked="{Binding ShowLocalChangesByDefault, Mode=TwoWay}"/>
139-
139+
140140
<CheckBox Grid.Row="6" Grid.Column="1"
141141
Height="32"
142142
Content="{DynamicResource Text.Preferences.General.ShowChangesTabInCommitDetailByDefault}"
@@ -300,7 +300,7 @@
300300
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.Git}"/>
301301
</TabItem.Header>
302302

303-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
303+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
304304
<TextBlock Grid.Row="0" Grid.Column="0"
305305
Text="{DynamicResource Text.Preferences.Git.Path}"
306306
HorizontalAlignment="Right"
@@ -389,6 +389,11 @@
389389
IsChecked="{Binding #ThisControl.EnableHTTPSSLVerify, Mode=TwoWay}"/>
390390

391391
<CheckBox Grid.Row="8" Grid.Column="1"
392+
Height="32"
393+
Content="{DynamicResource Text.Preferences.Git.PreferHttpWhenVisit}"
394+
IsChecked="{Binding PreferHttpWhenVisit, Mode=TwoWay}"/>
395+
396+
<CheckBox Grid.Row="9" Grid.Column="1"
392397
Height="32"
393398
Content="{DynamicResource Text.Preferences.Git.UseLibsecret}"
394399
IsChecked="{Binding UseLibsecretInsteadOfGCM, Mode=TwoWay}"

src/Views/Preferences.axaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public bool EnableHTTPSSLVerify
9595
set;
9696
} = false;
9797

98+
public bool PreferHttpWhenVisit
99+
{
100+
get;
101+
set;
102+
} = false;
103+
98104
public static readonly StyledProperty<Models.OpenAIService> SelectedOpenAIServiceProperty =
99105
AvaloniaProperty.Register<Preferences, Models.OpenAIService>(nameof(SelectedOpenAIService));
100106

0 commit comments

Comments
 (0)