Skip to content

Commit d823b0c

Browse files
authored
Merge pull request #231 from c8ef/master
fix: code style by dotnet format
2 parents d6d8394 + bc6ec17 commit d823b0c

15 files changed

Lines changed: 70 additions & 73 deletions

.github/workflows/dotnet-build.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@ name: CI/CD Pipeline
33
on:
44
push:
55
branches:
6-
- '*'
6+
- "*"
77
tags:
8-
- 'v*'
8+
- "v*"
99
paths:
10-
- 'src/**'
11-
- 'Properties/**'
10+
- "src/**"
11+
- "Properties/**"
12+
- ".github/workflows/**"
1213
pull_request:
1314
workflow_dispatch:
1415

1516
jobs:
1617
build:
17-
if: >
18-
github.event_name == 'workflow_dispatch' ||
19-
github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') ||
20-
contains(github.event.head_commit.message, 'feat') ||
21-
contains(github.event.head_commit.message, 'fix') ||
22-
contains(github.event.head_commit.message, 'perf') ||
23-
contains(github.event.head_commit.message, 'build')
2418
name: Build and Test
2519
runs-on: windows-latest
2620

@@ -31,11 +25,14 @@ jobs:
3125
- name: Setup .NET
3226
uses: actions/setup-dotnet@v3
3327
with:
34-
dotnet-version: '8.0.x'
28+
dotnet-version: "8.0.x"
3529

3630
- name: Restore Dependencies
3731
run: dotnet restore
3832

33+
- name: Check code formatting
34+
run: dotnet format ./LiveCaptionsTranslator.csproj --verify-no-changes --verbosity diagnostic
35+
3936
- name: Build
4037
run: |
4138
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -o ./publish/x64/selfcontained
@@ -89,4 +86,4 @@ jobs:
8986
release/LiveCaptionsTranslator-win-arm64.exe
9087
release/LiveCaptionsTranslator-win-arm64-withruntime.exe
9188
env:
92-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/Translator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public static async Task Log(string originalText, string translatedText,
295295
}
296296
catch (Exception ex)
297297
{
298-
SnackbarHost.Show("[ERROR] Logging history failed.", ex.Message, SnackbarType.Error,
298+
SnackbarHost.Show("[ERROR] Logging history failed.", ex.Message, SnackbarType.Error,
299299
timeout: 2, closeButton: true);
300300
}
301301
}
@@ -315,7 +315,7 @@ public static async Task LogOnly(string originalText,
315315
}
316316
catch (Exception ex)
317317
{
318-
SnackbarHost.Show("[ERROR] Logging history failed.", ex.Message, SnackbarType.Error,
318+
SnackbarHost.Show("[ERROR] Logging history failed.", ex.Message, SnackbarType.Error,
319319
timeout: 2, closeButton: true);
320320
}
321321
}
@@ -348,11 +348,11 @@ public static async Task<bool> IsOverwrite(string originalText, CancellationToke
348348
string lastOriginalText = await SQLiteHistoryLogger.LoadLastSourceText(token);
349349
if (lastOriginalText == null)
350350
return false;
351-
351+
352352
int minLen = Math.Min(originalText.Length, lastOriginalText.Length);
353353
originalText = originalText.Substring(0, minLen);
354354
lastOriginalText = lastOriginalText.Substring(0, minLen);
355-
355+
356356
double similarity = TextUtil.Similarity(originalText, lastOriginalText);
357357
return similarity > TextUtil.SIM_THRESHOLD;
358358
}

src/apis/LLMRequestDataFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ public static class LLMRequestDataFactory
1919
};
2020

2121
public static int FallbackCount => typeSequence.Count;
22-
22+
2323
public static BaseLLMRequestData Create(string platform, string model, List<BaseLLMConfig.Message> messages, double temperature)
2424
{
2525
if (typeSequence[platform] == null)
2626
return null;
2727
return (BaseLLMRequestData)Activator.CreateInstance((Type)typeSequence[platform], model, messages, temperature);
2828
}
29-
29+
3030
public static BaseLLMRequestData Create(int index, string model, List<BaseLLMConfig.Message> messages, double temperature)
3131
{
3232
if (typeSequence[index] == null)
3333
return null;
3434
return (BaseLLMRequestData)Activator.CreateInstance((Type)typeSequence[index], model, messages, temperature);
3535
}
36-
36+
3737
public static BaseLLMRequestData Create(string model, List<BaseLLMConfig.Message> messages, double temperature)
3838
{
3939
return (BaseLLMRequestData)Activator.CreateInstance(typeof(BaseLLMRequestData), model, messages, temperature);

src/apis/TranslateAPI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static async Task<string> OpenAI(string text, CancellationToken token = d
6161
new BaseLLMConfig.Message { role = "system", content = string.Format(Prompt, language) },
6262
new BaseLLMConfig.Message { role = "user", content = $"🔤 {text} 🔤" }
6363
};
64-
64+
6565
if (Translator.Setting.ContextAware)
6666
{
6767
foreach (var entry in Translator.Caption.AwareContexts)
@@ -140,7 +140,7 @@ public static async Task<string> Ollama(string text, CancellationToken token = d
140140
new BaseLLMConfig.Message { role = "system", content = string.Format(Prompt, language) },
141141
new BaseLLMConfig.Message { role = "user", content = $"🔤 {text} 🔤" }
142142
};
143-
143+
144144
if (Translator.Setting.ContextAware)
145145
{
146146
foreach (var entry in Translator.Caption.AwareContexts)
@@ -203,7 +203,7 @@ public static async Task<string> OpenRouter(string text, CancellationToken token
203203
new BaseLLMConfig.Message { role = "system", content = string.Format(Prompt, language) },
204204
new BaseLLMConfig.Message { role = "user", content = $"🔤 {text} 🔤" }
205205
};
206-
206+
207207
if (Translator.Setting.ContextAware)
208208
{
209209
foreach (var entry in Translator.Caption.AwareContexts)

src/controls/SnackbarHost.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class SnackbarHost
77
public static Snackbar? mainSnackbar;
88
public static MainWindow? mainWindow = (MainWindow)App.Current.MainWindow;
99

10-
public static void Show(string title = "", string message = "", SnackbarType type = SnackbarType.Info,
11-
int width = 500, int timeout = 1, bool closeButton = false)
10+
public static void Show(string title = "", string message = "", SnackbarType type = SnackbarType.Info,
11+
int width = 500, int timeout = 1, bool closeButton = false)
1212
{
1313
ControlAppearance appearance;
1414
SymbolIcon icon;
@@ -49,7 +49,7 @@ public static void Show(string title = "", string message = "", SnackbarType typ
4949
snackbar.Show(true);
5050
}
5151
}
52-
52+
5353
public enum SnackbarType
5454
{
5555
Warning,

src/controls/StrokeDecorator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private void OnTextBlockPropertyChanged(object sender, EventArgs e)
233233

234234
private static T GetValue<T>(DependencyObject obj, DependencyProperty property, T fallback)
235235
{
236-
return obj.ReadLocalValue(property) != DependencyProperty.UnsetValue ?
236+
return obj.ReadLocalValue(property) != DependencyProperty.UnsetValue ?
237237
(T)obj.GetValue(property) : fallback;
238238
}
239239
}

src/models/Caption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Caption : INotifyPropertyChanged
2727
public IEnumerable<TranslationHistoryEntry> AwareContexts => GetPreviousContexts(Translator.Setting.NumContexts);
2828
public string AwareContextsCaption => GetPreviousText(Translator.Setting.NumContexts, TextType.Caption);
2929

30-
public IEnumerable<TranslationHistoryEntry> DisplayLogCards =>
30+
public IEnumerable<TranslationHistoryEntry> DisplayLogCards =>
3131
GetPreviousContexts(Translator.Setting.DisplaySentences).Reverse();
3232

3333
public string DisplayOriginalCaption

src/models/RequestData.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
namespace LiveCaptionsTranslator.models
22
{
33
// Reasoning/thinking for all LLMs is disabled or minimal to reduce response time.
4-
4+
55
public class BaseLLMRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
66
{
77
public string model { get; set; } = model;
88
public List<BaseLLMConfig.Message> messages { get; set; } = messages;
99
public double temperature { get; set; } = temperature;
10-
10+
1111
public int max_tokens { get; set; } = 128;
1212
public bool stream { get; set; } = false;
1313
}
14-
14+
1515
public class IntegratedLLMRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
1616
: BaseLLMRequestData(model, messages, temperature)
1717
{
1818
// Some platforms do not return 400/422 errors; instead, they automatically ignore incorrect parameters.
1919
// This request data is used for these platforms to ensure that model thinking is disabled.
20-
20+
2121
public class Reasoning
2222
{
2323
public bool exclude { get; set; } = true;
@@ -28,20 +28,20 @@ public class Thinking
2828
{
2929
public string type { get; set; } = "disabled";
3030
}
31-
31+
3232
public bool think { get; set; } = false;
3333
public bool enable_thinking { get; set; } = false;
3434
public string reasoning_effort { get; set; } = "low";
35-
public Reasoning reasoning { get; set; } = new ();
36-
public Thinking thinking { get; set; } = new ();
35+
public Reasoning reasoning { get; set; } = new();
36+
public Thinking thinking { get; set; } = new();
3737
}
38-
38+
3939
public class OllamaRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
4040
: BaseLLMRequestData(model, messages, temperature)
4141
{
4242
public bool think { get; set; } = false;
4343
}
44-
44+
4545
public class OpenRouterRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
4646
: BaseLLMRequestData(model, messages, temperature)
4747
{
@@ -50,9 +50,9 @@ public class Reasoning
5050
public bool exclude { get; set; } = true;
5151
public bool enabled { get; set; } = false;
5252
}
53-
public Reasoning reasoning { get; set; } = new ();
53+
public Reasoning reasoning { get; set; } = new();
5454
}
55-
55+
5656
public class AnthropicRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
5757
: BaseLLMRequestData(model, messages, temperature)
5858
{
@@ -61,16 +61,16 @@ public class Thinking
6161
{
6262
public string type { get; set; } = "disabled";
6363
}
64-
public Thinking thinking { get; set; } = new ();
64+
public Thinking thinking { get; set; } = new();
6565
}
66-
66+
6767
public class AliyunRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
6868
: BaseLLMRequestData(model, messages, temperature)
6969
{
7070
// Supported Platform: Aliyun (Bailian), Silicon Flow
7171
public bool enable_thinking { get; set; } = false;
7272
}
73-
73+
7474
public class OpenAIRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
7575
: BaseLLMRequestData(model, messages, temperature)
7676
{
@@ -79,9 +79,9 @@ public class Reasoning
7979
{
8080
public string effort { get; set; } = "low";
8181
}
82-
public Reasoning reasoning { get; set; } = new ();
82+
public Reasoning reasoning { get; set; } = new();
8383
}
84-
84+
8585
public class XAIRequestData(string model, List<BaseLLMConfig.Message> messages, double temperature)
8686
: BaseLLMRequestData(model, messages, temperature)
8787
{

src/models/Setting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Setting : INotifyPropertyChanged
2525
private string targetLanguage;
2626
private string prompt;
2727
private string? ignoredUpdateVersion;
28-
28+
2929
private MainWindowState mainWindowState;
3030
private OverlayWindowState overlayWindowState;
3131
private Dictionary<string, string> windowBounds;

src/models/TranslationTaskQueue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ private async Task OnTaskCompleted(TranslationTask translationTask)
3838
for (int i = index; i >= 0; i--)
3939
tasks.RemoveAt(i);
4040
}
41-
41+
4242
output = translationTask.Task.Result;
4343
var translatedText = output.Item1;
44-
44+
4545
// Log after translation.
4646
bool isOverwrite = await Translator.IsOverwrite(translationTask.OriginalText);
4747
if (!isOverwrite)

0 commit comments

Comments
 (0)