Skip to content

Commit 5e2a946

Browse files
committed
feat(publish): release downloadable builds
1 parent c97fe74 commit 5e2a946

22 files changed

Lines changed: 842 additions & 80 deletions

.github/workflows/publish.yml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Desktop Publish
33
on:
44
workflow_dispatch:
55

6+
permissions:
7+
contents: write
8+
69
jobs:
710
build-browser:
811
runs-on: ubuntu-latest
@@ -90,13 +93,12 @@ jobs:
9093
Move-Item -Path publish/WebTranslator.Desktop.exe -Destination publish/WebTranslator.exe -Force
9194
}
9295
Get-ChildItem publish -Include *.pdb,*.dbg -File -ErrorAction SilentlyContinue | Remove-Item -Force
93-
& "${env:ProgramFiles}\7-Zip\7z.exe" a -t7z -mx=9 WebTranslator-windows_amd64.7z .\publish\*
9496
9597
- name: Upload Windows Build
9698
uses: actions/upload-artifact@v7
9799
with:
98100
name: WebTranslator-windows_amd64
99-
path: WebTranslator-windows_amd64.7z
101+
path: publish/WebTranslator.exe
100102
compression-level: 0
101103

102104
build-ubuntu:
@@ -113,7 +115,7 @@ jobs:
113115
dotnet-version: 9.0.x
114116

115117
- name: Install dependencies (AOT prerequisites)
116-
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev p7zip-full
118+
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev
117119

118120
- name: Publish (Linux, net9.0, AOT, self-contained)
119121
run: >-
@@ -128,20 +130,25 @@ jobs:
128130
- name: Rename and Clean Ubuntu Files
129131
run: |
130132
if [ -f publish/WebTranslator.Desktop ]; then mv publish/WebTranslator.Desktop publish/WebTranslator; fi
133+
chmod +x publish/WebTranslator
131134
rm -f publish/*.pdb publish/*.dbg || true
132-
7z a -t7z -mx=9 WebTranslator-linux_amd64.7z ./publish/*
133135
134136
- name: Upload Ubuntu Build
135137
uses: actions/upload-artifact@v7
136138
with:
137139
name: WebTranslator-linux_amd64
138-
path: WebTranslator-linux_amd64.7z
140+
path: publish/WebTranslator
139141
compression-level: 0
140142

141143
release:
142-
needs: [build-windows, build-ubuntu]
144+
needs: [build-browser, build-windows, build-ubuntu]
143145
runs-on: ubuntu-latest
144146
steps:
147+
- name: Checkout
148+
uses: actions/checkout@v6
149+
with:
150+
fetch-depth: 0
151+
145152
- name: Download Windows Build
146153
uses: actions/download-artifact@v8
147154
with:
@@ -153,3 +160,37 @@ jobs:
153160
with:
154161
name: WebTranslator-linux_amd64
155162
path: release/ubuntu
163+
164+
- name: Create release files
165+
run: |
166+
mkdir -p release/assets
167+
cp release/windows/WebTranslator.exe release/assets/WebTranslator-windows_amd64.exe
168+
cp release/ubuntu/WebTranslator release/assets/WebTranslator-linux_amd64
169+
chmod +x release/assets/WebTranslator-linux_amd64
170+
171+
- name: Create release notes
172+
run: |
173+
previous_tag="$(git describe --tags --abbrev=0 --match 'publish-*' 2>/dev/null || true)"
174+
if [ -n "$previous_tag" ]; then
175+
git log --pretty=format:'- %s (%h)' "${previous_tag}..HEAD" > release-notes.md
176+
else
177+
git log --pretty=format:'- %s (%h)' > release-notes.md
178+
fi
179+
if [ ! -s release-notes.md ]; then
180+
echo "- No commits since the previous publish release." > release-notes.md
181+
fi
182+
183+
- name: Publish GitHub Release
184+
env:
185+
GH_TOKEN: ${{ github.token }}
186+
RELEASE_TAG: publish-${{ github.run_number }}.${{ github.run_attempt }}
187+
run: |
188+
gh release create "$RELEASE_TAG" \
189+
release/assets/WebTranslator-windows_amd64.exe \
190+
release/assets/WebTranslator-linux_amd64 \
191+
--repo "$GITHUB_REPOSITORY" \
192+
--target "$GITHUB_SHA" \
193+
--title "$RELEASE_TAG" \
194+
--notes-file release-notes.md \
195+
--prerelease \
196+
--latest=false
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Runtime.InteropServices.JavaScript;
3+
using System.Threading.Tasks;
4+
using WebTranslator.Services;
5+
6+
internal partial class BrowserDictionaryStorage : IDictionaryStorage
7+
{
8+
public string DisplayLocation => "浏览器本地存储";
9+
public bool CanReadSynchronously => false;
10+
11+
public string? ReadText()
12+
{
13+
return null;
14+
}
15+
16+
public Task<string?> ReadTextAsync()
17+
{
18+
return ReadAsync();
19+
}
20+
21+
public Task WriteTextAsync(string text)
22+
{
23+
return WriteAsync(text);
24+
}
25+
26+
public Task DeleteAsync()
27+
{
28+
return DeleteAsyncCore();
29+
}
30+
31+
public DateTimeOffset? GetLastWriteTime()
32+
{
33+
return null;
34+
}
35+
36+
[JSImport("globalThis.webTranslatorDictionary.read")]
37+
private static partial Task<string?> ReadAsync();
38+
39+
[JSImport("globalThis.webTranslatorDictionary.write")]
40+
private static partial Task WriteAsync(string text);
41+
42+
[JSImport("globalThis.webTranslatorDictionary.remove")]
43+
private static partial Task DeleteAsyncCore();
44+
}

WebTranslator/WebTranslator.Browser/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
using Avalonia;
44
using Avalonia.Browser;
55
using WebTranslator;
6+
using WebTranslator.Services;
67

78
[assembly: SupportedOSPlatform("browser")]
89

910
internal sealed partial class Program
1011
{
11-
private static Task Main(string[] args) => BuildAvaloniaApp()
12-
.StartBrowserAppAsync("out");
12+
private static async Task Main(string[] args)
13+
{
14+
DictionaryService.SetStorage(new BrowserDictionaryStorage());
15+
await DictionaryService.InitializeAsync();
16+
await BuildAvaloniaApp().StartBrowserAppAsync("out");
17+
}
1318

1419
public static AppBuilder BuildAvaloniaApp()
1520
=> AppBuilder.Configure<App>();

WebTranslator/WebTranslator.Browser/WebTranslator.Browser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<DebuggerSupport>false</DebuggerSupport>
1111
<StackTraceSupport>false</StackTraceSupport>
1212
<UseSystemResourceKeys>true</UseSystemResourceKeys>
13+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1314
</PropertyGroup>
1415

1516
<ItemGroup>

WebTranslator/WebTranslator.Browser/wwwroot/app.css

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,21 @@
77

88
/* HTML styles for the splash screen */
99

10-
.highlight {
11-
color: white;
12-
font-size: 2.5rem;
13-
display: block;
14-
}
15-
16-
.purple {
17-
color: #8b44ac;
18-
}
19-
2010
.icon {
21-
opacity: 0.05;
11+
opacity: 0.04;
2212
height: 35%;
2313
width: 35%;
2414
position: absolute;
2515
background-repeat: no-repeat;
26-
right: 0px;
27-
bottom: 0px;
16+
right: 0;
17+
bottom: 0;
2818
margin-right: 3%;
2919
margin-bottom: 5%;
3020
z-index: 5000;
3121
background-position: right bottom;
3222
pointer-events: none;
3323
}
3424

35-
#avalonia-splash a {
36-
color: whitesmoke;
37-
text-decoration: none;
38-
}
39-
4025
.center {
4126
display: flex;
4227
justify-content: center;
@@ -48,16 +33,68 @@
4833
position: relative;
4934
height: 100%;
5035
width: 100%;
51-
color: whitesmoke;
52-
background: #1b2a4e;
53-
font-family: 'Nunito', sans-serif;
36+
color: #f8fafc;
37+
background: linear-gradient(135deg, #111827 0%, #172033 55%, #213547 100%);
38+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
5439
background-position: center;
5540
background-size: cover;
5641
background-repeat: no-repeat;
5742
justify-content: center;
5843
align-items: center;
5944
}
6045

46+
.boot-panel {
47+
position: relative;
48+
z-index: 6000;
49+
width: min(440px, calc(100vw - 48px));
50+
}
51+
52+
.boot-logo {
53+
width: 48px;
54+
height: 48px;
55+
margin-bottom: 18px;
56+
}
57+
58+
.boot-panel h1 {
59+
margin: 0;
60+
color: #ffffff;
61+
font-size: 2rem;
62+
font-weight: 650;
63+
}
64+
65+
.boot-panel p {
66+
min-height: 24px;
67+
margin: 14px 0 20px;
68+
color: #cbd5e1;
69+
font-size: 1rem;
70+
}
71+
72+
.boot-progress {
73+
width: 100%;
74+
height: 8px;
75+
overflow: hidden;
76+
border-radius: 999px;
77+
background: rgba(148, 163, 184, 0.24);
78+
}
79+
80+
#boot-progress-value {
81+
width: 0;
82+
height: 100%;
83+
border-radius: inherit;
84+
background: linear-gradient(90deg, #38bdf8 0%, #34d399 100%);
85+
transition: width 0.18s ease-out;
86+
}
87+
88+
.boot-progress-row {
89+
display: flex;
90+
justify-content: space-between;
91+
gap: 16px;
92+
margin-top: 12px;
93+
color: #e2e8f0;
94+
font-size: 0.9rem;
95+
font-variant-numeric: tabular-nums;
96+
}
97+
6198
.splash-close {
6299
animation: fadeout 0.25s linear forwards;
63100
}

WebTranslator/WebTranslator.Browser/wwwroot/index.html

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@
1616
<div id="out">
1717
<div id="avalonia-splash">
1818
<div class="center">
19-
<h2 class="purple">
20-
<span class="highlight">Loading..</span>
21-
<br />
22-
<br />
23-
Powered by
24-
<a class="highlight" href="https://www.avaloniaui.net/" target="_blank">Avalonia UI</a>
25-
</h2>
19+
<div class="boot-panel" role="status" aria-live="polite">
20+
<img class="boot-logo" src="Logo.svg" alt="" />
21+
<h1>WebTranslator</h1>
22+
<p id="boot-phase">正在准备加载资源</p>
23+
<div class="boot-progress" aria-hidden="true">
24+
<div id="boot-progress-value"></div>
25+
</div>
26+
<div class="boot-progress-row">
27+
<span id="boot-resource-count">已加载 0 / ? 个资源</span>
28+
<span id="boot-progress-percent">0%</span>
29+
</div>
30+
</div>
2631
</div>
2732
<img class="icon" src="Logo.svg" alt="Avalonia Logo" />
2833
</div>
2934
</div>
3035
<script type='module' src="./main.js"></script>
3136
</body>
3237

33-
</html>
38+
</html>

0 commit comments

Comments
 (0)