Skip to content

Commit 5154f0b

Browse files
committed
Add FontManager to better handle fonts. Remove the go-findfont dependency. Add Go examples.
1 parent 9fa5967 commit 5154f0b

File tree

13 files changed

+335
-29
lines changed

13 files changed

+335
-29
lines changed

v3/examples/badge/frontend/dist/assets/index-BguIgRNQ.js renamed to v3/examples/badge/frontend/dist/assets/index-sXwpgKSV.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ function eventTarget(event) {
127127
document.addEventListener("DOMContentLoaded", () => {
128128
});
129129
window.addEventListener("contextmenu", contextMenuHandler);
130-
const call$1 = newRuntimeCaller(objectNames.ContextMenu);
130+
const call$2 = newRuntimeCaller(objectNames.ContextMenu);
131131
const ContextMenuOpen = 0;
132132
function openContextMenu(id, x, y, data) {
133-
void call$1(ContextMenuOpen, { id, x, y, data });
133+
void call$2(ContextMenuOpen, { id, x, y, data });
134134
}
135135
function contextMenuHandler(event) {
136136
const target = eventTarget(event);
@@ -1138,7 +1138,7 @@ if (promiseWithResolvers && typeof promiseWithResolvers === "function") {
11381138
window._wails = window._wails || {};
11391139
window._wails.callResultHandler = resultHandler;
11401140
window._wails.callErrorHandler = errorHandler;
1141-
const call = newRuntimeCaller(objectNames.Call);
1141+
const call$1 = newRuntimeCaller(objectNames.Call);
11421142
const cancelCall = newRuntimeCaller(objectNames.CancelCall);
11431143
const callResponses = /* @__PURE__ */ new Map();
11441144
const CallBinding = 0;
@@ -1224,7 +1224,7 @@ function Call(options) {
12241224
const id = generateID();
12251225
const result = CancellablePromise.withResolvers();
12261226
callResponses.set(id, { resolve: result.resolve, reject: result.reject });
1227-
const request = call(CallBinding, Object.assign({ "call-id": id }, options));
1227+
const request = call$1(CallBinding, Object.assign({ "call-id": id }, options));
12281228
let running = false;
12291229
request.then(() => {
12301230
running = true;
@@ -1283,7 +1283,8 @@ function listenerOff(listener) {
12831283
}
12841284
window._wails = window._wails || {};
12851285
window._wails.dispatchWailsEvent = dispatchWailsEvent;
1286-
newRuntimeCaller(objectNames.Events);
1286+
const call = newRuntimeCaller(objectNames.Events);
1287+
const EmitMethod = 0;
12871288
class WailsEvent {
12881289
constructor(name, data = null) {
12891290
this.name = name;
@@ -1316,6 +1317,9 @@ function OnMultiple(eventName, callback, maxCallbacks) {
13161317
function On(eventName, callback) {
13171318
return OnMultiple(eventName, callback, -1);
13181319
}
1320+
function Emit(event) {
1321+
return call(EmitMethod, event);
1322+
}
13191323
window._wails = window._wails || {};
13201324
window._wails.invoke = invoke;
13211325
invoke("wails:runtime:ready");
@@ -1329,6 +1333,8 @@ function SetBadge(label) {
13291333
}
13301334
const setButton = document.getElementById("set");
13311335
const removeButton = document.getElementById("remove");
1336+
const setButtonUsingGo = document.getElementById("set-go");
1337+
const removeButtonUsingGo = document.getElementById("remove-go");
13321338
const labelElement = document.getElementById("label");
13331339
const timeElement = document.getElementById("time");
13341340
setButton.addEventListener("click", () => {
@@ -1338,6 +1344,16 @@ setButton.addEventListener("click", () => {
13381344
removeButton.addEventListener("click", () => {
13391345
RemoveBadge();
13401346
});
1347+
setButtonUsingGo.addEventListener("click", () => {
1348+
let label = labelElement.value;
1349+
void Emit({
1350+
name: "set:badge",
1351+
data: label
1352+
});
1353+
});
1354+
removeButtonUsingGo.addEventListener("click", () => {
1355+
void Emit({ name: "remove:badge", data: null });
1356+
});
13411357
On("time", (time) => {
13421358
timeElement.innerText = time.data;
13431359
});

v3/examples/badge/frontend/dist/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
77
<link rel="stylesheet" href="/style.css"/>
88
<title>Wails App</title>
9-
<script type="module" crossorigin src="/assets/index-BguIgRNQ.js"></script>
9+
<script type="module" crossorigin src="/assets/index-sXwpgKSV.js"></script>
1010
</head>
1111
<body>
1212
<div class="container">
@@ -25,6 +25,8 @@ <h1>Wails + Typescript</h1>
2525
<input class="input" id="label" type="text" autocomplete="off"/>
2626
<button class="btn" id="set">Set</button>
2727
<button class="btn" id="remove">Remove</button>
28+
<button class="btn" id="set-go">Set using Go</button>
29+
<button class="btn" id="remove-go">Remove using Go</button>
2830
</div>
2931
</div>
3032
<div class="footer">

v3/examples/badge/frontend/dist/style.css

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ a:hover {
4343
}
4444

4545
button {
46-
width: 60px;
47-
height: 30px;
4846
line-height: 30px;
4947
border-radius: 3px;
5048
border: none;

v3/examples/badge/frontend/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ <h1>Wails + Typescript</h1>
2424
<input class="input" id="label" type="text" autocomplete="off"/>
2525
<button class="btn" id="set">Set</button>
2626
<button class="btn" id="remove">Remove</button>
27+
<button class="btn" id="set-go">Set using Go</button>
28+
<button class="btn" id="remove-go">Remove using Go</button>
2729
</div>
2830
</div>
2931
<div class="footer">

v3/examples/badge/frontend/public/style.css

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ a:hover {
4343
}
4444

4545
button {
46-
width: 60px;
47-
height: 30px;
4846
line-height: 30px;
4947
border-radius: 3px;
5048
border: none;

v3/examples/badge/frontend/src/main.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {Events} from "@wailsio/runtime";
2-
import {SetBadge, RemoveBadge} from "../bindings/github.com/wailsapp/wails/v3/pkg/services/badge/service";
2+
import {SetBadge, RemoveBadge} from "../bindings/github.com/wailsapp/wails/v3/pkg/services/badge/service";
33

44
const setButton = document.getElementById('set')! as HTMLButtonElement;
55
const removeButton = document.getElementById('remove')! as HTMLButtonElement;
6+
const setButtonUsingGo = document.getElementById('set-go')! as HTMLButtonElement;
7+
const removeButtonUsingGo = document.getElementById('remove-go')! as HTMLButtonElement;
68
const labelElement : HTMLInputElement = document.getElementById('label')! as HTMLInputElement;
79
const timeElement = document.getElementById('time')! as HTMLDivElement;
810

@@ -15,6 +17,19 @@ removeButton.addEventListener('click', () => {
1517
RemoveBadge();
1618
});
1719

20+
setButtonUsingGo.addEventListener('click', () => {
21+
let label = (labelElement as HTMLInputElement).value
22+
void Events.Emit({
23+
name: "set:badge",
24+
data: label,
25+
})
26+
})
27+
28+
removeButtonUsingGo.addEventListener('click', () => {
29+
void Events.Emit({name:"remove:badge", data: null})
30+
})
31+
1832
Events.On('time', (time: {data: any}) => {
1933
timeElement.innerText = time.data;
2034
});
35+

v3/examples/badge/main.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ func main() {
2727
// 'Assets' configures the asset server with the 'FS' variable pointing to the frontend files.
2828
// 'Bind' is a list of Go struct instances. The frontend has access to the methods of these instances.
2929
// 'Mac' options tailor the application when running an macOS.
30+
31+
badgeService := badge.New()
32+
3033
app := application.New(application.Options{
3134
Name: "badge",
3235
Description: "A demo of using raw HTML & CSS",
3336
Services: []application.Service{
34-
application.NewService(badge.New()),
37+
application.NewService(badgeService),
3538
},
3639
Assets: application.AssetOptions{
3740
Handler: application.AssetFileServerFS(assets),
@@ -57,6 +60,21 @@ func main() {
5760
URL: "/",
5861
})
5962

63+
app.OnEvent("remove:badge", func(event *application.CustomEvent) {
64+
err := badgeService.RemoveBadge()
65+
if err != nil {
66+
log.Fatal(err)
67+
}
68+
})
69+
70+
app.OnEvent("set:badge", func(event *application.CustomEvent) {
71+
text := event.Data.(string)
72+
err := badgeService.SetBadge(text)
73+
if err != nil {
74+
log.Fatal(err)
75+
}
76+
})
77+
6078
// Create a goroutine that emits an event containing the current time every second.
6179
// The frontend can listen to this event and update the UI accordingly.
6280
go func() {

v3/examples/dev/go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ require (
3535
github.com/samber/lo v1.49.1 // indirect
3636
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
3737
github.com/stretchr/testify v1.10.0 // indirect
38-
github.com/wailsapp/go-webview2 v1.0.19 // indirect
38+
github.com/wailsapp/go-webview2 v1.0.21 // indirect
3939
github.com/wailsapp/mimetype v1.4.1 // indirect
4040
github.com/xanzy/ssh-agent v0.3.3 // indirect
41-
golang.org/x/crypto v0.33.0 // indirect
41+
golang.org/x/crypto v0.36.0 // indirect
4242
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
43-
golang.org/x/net v0.35.0 // indirect
44-
golang.org/x/sys v0.30.0 // indirect
43+
golang.org/x/net v0.37.0 // indirect
44+
golang.org/x/sys v0.31.0 // indirect
4545
gopkg.in/warnings.v0 v0.1.2 // indirect
4646
)
4747

v3/examples/dev/go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf
138138
github.com/wailsapp/go-webview2 v1.0.9 h1:lrU+q0cf1wgLdR69rN+ZnRtMJNaJRrcQ4ELxoO7/xjs=
139139
github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
140140
github.com/wailsapp/go-webview2 v1.0.19/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
141+
github.com/wailsapp/go-webview2 v1.0.21/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
141142
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
142143
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
143144
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
@@ -153,6 +154,7 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
153154
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
154155
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
155156
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
157+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
156158
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
157159
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
158160
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
@@ -167,6 +169,7 @@ golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
167169
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
168170
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
169171
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
172+
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
170173
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
171174
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
172175
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -191,6 +194,7 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
191194
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
192195
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
193196
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
197+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
194198
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
195199
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
196200
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=

v3/go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ require (
4949
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
5050
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
5151
github.com/charmbracelet/x/term v0.2.1 // indirect
52-
github.com/flopp/go-findfont v0.1.0 // indirect
5352
github.com/ncruces/go-strftime v0.1.9 // indirect
5453
)
5554

@@ -137,7 +136,7 @@ require (
137136
golang.org/x/crypto v0.36.0 // indirect
138137
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
139138
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac
140-
golang.org/x/image v0.24.0 // indirect
139+
golang.org/x/image v0.24.0
141140
golang.org/x/mod v0.24.0 // indirect
142141
golang.org/x/net v0.37.0 // indirect
143142
golang.org/x/sync v0.12.0 // indirect

v3/go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc
117117
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
118118
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
119119
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
120-
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
121-
github.com/flopp/go-findfont v0.1.0/go.mod h1:wKKxRDjD024Rh7VMwoU90i6ikQRCr+JTHB5n4Ejkqvw=
122120
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
123121
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
124122
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=

0 commit comments

Comments
 (0)