Skip to content

Commit 68831b2

Browse files
committed
refactor: notifications
- Modal dialog must display error message on top of its self - Commands should only depends on Models and Native Signed-off-by: leo <longshuang@msn.cn>
1 parent 9e0ba44 commit 68831b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+235
-152
lines changed

src/App.axaml.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,6 @@ public static async Task<bool> AskConfirmAsync(string message, Models.ConfirmBut
221221
return Models.ConfirmEmptyCommitResult.Cancel;
222222
}
223223

224-
public static void RaiseException(string context, string message)
225-
{
226-
if (Current is App { _launcher: not null } app)
227-
app._launcher.DispatchNotification(context, message, true);
228-
}
229-
230-
public static void SendNotification(string context, string message)
231-
{
232-
if (Current is App { _launcher: not null } app)
233-
app._launcher.DispatchNotification(context, message, false);
234-
}
235-
236224
public static void SetLocale(string localeKey)
237225
{
238226
if (Current is not App app ||

src/Commands/Command.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task<bool> ExecAsync()
7070
catch (Exception e)
7171
{
7272
if (RaiseError)
73-
App.RaiseException(Context, e.Message);
73+
RaiseException(e.Message);
7474

7575
Log?.AppendLine(string.Empty);
7676
return false;
@@ -101,7 +101,7 @@ public async Task<bool> ExecAsync()
101101
{
102102
var errMsg = string.Join("\n", errs).Trim();
103103
if (!string.IsNullOrEmpty(errMsg))
104-
App.RaiseException(Context, errMsg);
104+
RaiseException(errMsg);
105105
}
106106

107107
return false;
@@ -219,6 +219,11 @@ protected ProcessStartInfo CreateGitStartInfo(bool redirect)
219219
return start;
220220
}
221221

222+
protected void RaiseException(string error)
223+
{
224+
Models.Notification.Send(Context, error, true);
225+
}
226+
222227
private void HandleOutput(string line, List<string> errs)
223228
{
224229
if (line == null)

src/Commands/DiffTool.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Open()
1717
var tool = Native.OS.GetDiffMergeTool(true);
1818
if (tool == null)
1919
{
20-
App.RaiseException(Context, "Invalid diff/merge tool in preference setting!");
20+
RaiseException("Invalid diff/merge tool in preference setting!");
2121
return;
2222
}
2323

@@ -40,7 +40,7 @@ public void Open()
4040
}
4141
catch (Exception ex)
4242
{
43-
App.RaiseException(Context, ex.Message);
43+
RaiseException(ex.Message);
4444
}
4545
}
4646

@@ -56,7 +56,7 @@ private bool CheckGitConfiguration()
5656
if (config.TryGetValue("merge.tool", out var mergeTool))
5757
return CheckCLIBasedTool(mergeTool);
5858

59-
App.RaiseException(Context, "Missing git configuration: diff.guitool");
59+
RaiseException("Missing git configuration: diff.guitool");
6060
return false;
6161
}
6262

@@ -65,7 +65,7 @@ private bool CheckCLIBasedTool(string tool)
6565
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
6666
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
6767
{
68-
App.RaiseException(Context, $"CLI based diff tool \"{tool}\" is not supported by this app!");
68+
RaiseException($"CLI based diff tool \"{tool}\" is not supported by this app!");
6969
return false;
7070
}
7171

src/Commands/Discard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static async Task AllAsync(string repo, bool includeModified, bool includ
3333
}
3434
catch (Exception e)
3535
{
36-
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
36+
Models.Notification.Send(repo, $"Failed to discard changes. Reason: {e.Message}", true);
3737
}
3838

3939
if (includeIgnored)
@@ -80,7 +80,7 @@ public static async Task ChangesAsync(string repo, List<Models.Change> changes,
8080
}
8181
catch (Exception e)
8282
{
83-
App.RaiseException(repo, $"Failed to discard changes. Reason: {e.Message}");
83+
Models.Notification.Send(repo, $"Failed to discard changes. Reason: {e.Message}", true);
8484
}
8585

8686
if (restores.Count > 0)

src/Commands/GitFlow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static async Task<bool> StartAsync(string repo, Models.GitFlowBranchType
4242
start.Args = $"flow hotfix start {name}";
4343
break;
4444
default:
45-
App.RaiseException(repo, "Bad git-flow branch type!!!");
45+
Models.Notification.Send(repo, "Bad git-flow branch type!!!", true);
4646
return false;
4747
}
4848

@@ -66,7 +66,7 @@ public static async Task<bool> FinishAsync(string repo, Models.GitFlowBranchType
6666
builder.Append("hotfix");
6767
break;
6868
default:
69-
App.RaiseException(repo, "Bad git-flow branch type!!!");
69+
Models.Notification.Send(repo, "Bad git-flow branch type!!!", true);
7070
return false;
7171
}
7272

src/Commands/MergeTool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task<bool> OpenAsync()
1717
var tool = Native.OS.GetDiffMergeTool(false);
1818
if (tool == null)
1919
{
20-
App.RaiseException(Context, "Invalid diff/merge tool in preference setting!");
20+
RaiseException("Invalid diff/merge tool in preference setting!");
2121
return false;
2222
}
2323

@@ -46,14 +46,14 @@ private async Task<bool> CheckGitConfigurationAsync()
4646

4747
if (string.IsNullOrEmpty(tool))
4848
{
49-
App.RaiseException(Context, "Missing git configuration: merge.guitool");
49+
RaiseException("Missing git configuration: merge.guitool");
5050
return false;
5151
}
5252

5353
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
5454
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
5555
{
56-
App.RaiseException(Context, $"CLI based merge tool \"{tool}\" is not supported by this app!");
56+
RaiseException($"CLI based merge tool \"{tool}\" is not supported by this app!");
5757
return false;
5858
}
5959

src/Commands/QueryCommits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
103103
}
104104
catch (Exception e)
105105
{
106-
App.RaiseException(Context, $"Failed to query commits. Reason: {e.Message}");
106+
RaiseException($"Failed to query commits. Reason: {e.Message}");
107107
}
108108

109109
return commits;

src/Commands/QueryCommitsForInteractiveRebase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public QueryCommitsForInteractiveRebase(string repo, string on)
2121
var rs = await ReadToEndAsync().ConfigureAwait(false);
2222
if (!rs.IsSuccess)
2323
{
24-
App.RaiseException(Context, $"Failed to query commits for interactive-rebase. Reason: {rs.StdErr}");
24+
RaiseException($"Failed to query commits for interactive-rebase. Reason: {rs.StdErr}");
2525
return commits;
2626
}
2727

src/Commands/QueryFileContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static async Task<Stream> RunAsync(string repo, string revision, string f
2727
}
2828
catch (Exception e)
2929
{
30-
App.RaiseException(repo, $"Failed to query file content: {e}");
30+
Models.Notification.Send(repo, $"Failed to query file content: {e}", true);
3131
}
3232

3333
stream.Position = 0;
@@ -58,7 +58,7 @@ public static async Task<Stream> FromLFSAsync(string repo, string oid, long size
5858
}
5959
catch (Exception e)
6060
{
61-
App.RaiseException(repo, $"Failed to query file content: {e}");
61+
Models.Notification.Send(repo, $"Failed to query file content: {e}", true);
6262
}
6363

6464
stream.Position = 0;

src/Commands/SaveChangesAsPatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static async Task<bool> ProcessSingleChangeAsync(string repo, Models.Dif
6969
}
7070
catch (Exception e)
7171
{
72-
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
72+
Models.Notification.Send(repo, "Save change to patch failed: " + e.Message, true);
7373
return false;
7474
}
7575
}

0 commit comments

Comments
 (0)