Skip to content

Commit ff73051

Browse files
authored
refactor: Move Wails service bindings to internal/wails package (#18)
Moves all Wails service wrapper files from root directory to internal/wails/ for better organization and separation of concerns. Changes: - Moved: jwt_service.go, barcode_service.go, conversion_service.go, data_generator_service.go, codeformatter_service.go - Updated package from 'main' to 'wails' - Changed startup() to Startup() (exported method) - Updated main.go and server.go imports - Updated type references to use wails package
1 parent ccfe3bd commit ff73051

10 files changed

Lines changed: 84 additions & 32 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package wails
22

33
import (
44
"bytes"
@@ -22,7 +22,7 @@ func NewBarcodeService() *BarcodeService {
2222
return &BarcodeService{}
2323
}
2424

25-
func (s *BarcodeService) startup(ctx context.Context) {
25+
func (s *BarcodeService) Startup(ctx context.Context) {
2626
s.ctx = ctx
2727
}
2828

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package wails
22

33
import (
44
"context"
@@ -18,8 +18,8 @@ func NewCodeFormatterService() *CodeFormatterService {
1818
}
1919
}
2020

21-
// startup is called when the app starts (Wails lifecycle)
22-
func (c *CodeFormatterService) startup(ctx context.Context) {
21+
// Startup is called when the app starts (Wails lifecycle)
22+
func (c *CodeFormatterService) Startup(ctx context.Context) {
2323
c.ctx = ctx
2424
}
2525

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package wails
22

33
import (
44
"context"
@@ -16,7 +16,7 @@ func NewConversionService() *ConversionService {
1616
}
1717
}
1818

19-
func (s *ConversionService) startup(ctx context.Context) {
19+
func (s *ConversionService) Startup(ctx context.Context) {
2020
s.ctx = ctx
2121
}
2222

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package wails
22

33
import (
44
"context"
@@ -19,8 +19,8 @@ func NewDataGeneratorService() *DataGeneratorService {
1919
}
2020
}
2121

22-
// startup is called when the service starts
23-
func (d *DataGeneratorService) startup(ctx context.Context) {
22+
// Startup is called when the service starts
23+
func (d *DataGeneratorService) Startup(ctx context.Context) {
2424
d.ctx = ctx
2525
}
2626

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package wails
22

33
import (
44
"context"
@@ -21,8 +21,8 @@ func NewJWTService() *JWTService {
2121
}
2222
}
2323

24-
// startup is called when the app starts (Wails lifecycle)
25-
func (j *JWTService) startup(ctx context.Context) {
24+
// Startup is called when the app starts (Wails lifecycle)
25+
func (j *JWTService) Startup(ctx context.Context) {
2626
j.ctx = ctx
2727
}
2828

main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55
"embed"
66

7-
"github.com/wailsapp/wails/v2"
7+
"dev-toolbox/internal/wails"
8+
9+
wails_runtime "github.com/wailsapp/wails/v2"
810
"github.com/wailsapp/wails/v2/pkg/options"
911
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
1012
)
@@ -15,11 +17,11 @@ var assets embed.FS
1517
func main() {
1618
// Create instances of the app structures
1719
app := NewApp()
18-
jwtService := NewJWTService()
19-
conversionService := NewConversionService()
20-
barcodeService := NewBarcodeService()
21-
dataGeneratorService := NewDataGeneratorService()
22-
codeFormatterService := NewCodeFormatterService()
20+
jwtService := wails.NewJWTService()
21+
conversionService := wails.NewConversionService()
22+
barcodeService := wails.NewBarcodeService()
23+
dataGeneratorService := wails.NewDataGeneratorService()
24+
codeFormatterService := wails.NewCodeFormatterService()
2325

2426
// Start HTTP server for Web Mode (port 8081)
2527
go func() {
@@ -28,7 +30,7 @@ func main() {
2830
}()
2931

3032
// Create application with options
31-
err := wails.Run(&options.App{
33+
err := wails_runtime.Run(&options.App{
3234
Title: "dev-toolbox",
3335
Width: 1024,
3436
Height: 768,
@@ -38,11 +40,11 @@ func main() {
3840
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
3941
OnStartup: func(ctx context.Context) {
4042
app.startup(ctx)
41-
jwtService.startup(ctx)
42-
conversionService.startup(ctx)
43-
barcodeService.startup(ctx)
44-
dataGeneratorService.startup(ctx)
45-
codeFormatterService.startup(ctx)
43+
jwtService.Startup(ctx)
44+
conversionService.Startup(ctx)
45+
barcodeService.Startup(ctx)
46+
dataGeneratorService.Startup(ctx)
47+
codeFormatterService.Startup(ctx)
4648
},
4749
Bind: []interface{}{
4850
app,

server.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ import (
99

1010
"dev-toolbox/internal/codeformatter"
1111
"dev-toolbox/internal/datagenerator"
12+
"dev-toolbox/internal/wails"
1213
)
1314

1415
// Server represents the HTTP server for Web Mode
1516
type Server struct {
16-
jwtService *JWTService
17-
conversionService *ConversionService
18-
barcodeService *BarcodeService
19-
dataGeneratorService *DataGeneratorService
20-
codeFormatterService *CodeFormatterService
17+
jwtService *wails.JWTService
18+
conversionService *wails.ConversionService
19+
barcodeService *wails.BarcodeService
20+
dataGeneratorService *wails.DataGeneratorService
21+
codeFormatterService *wails.CodeFormatterService
2122
}
2223

2324
// NewServer creates a new Server instance
24-
func NewServer(jwtService *JWTService, conversionService *ConversionService, barcodeService *BarcodeService, dataGeneratorService *DataGeneratorService, codeFormatterService *CodeFormatterService) *Server {
25+
func NewServer(jwtService *wails.JWTService, conversionService *wails.ConversionService, barcodeService *wails.BarcodeService, dataGeneratorService *wails.DataGeneratorService, codeFormatterService *wails.CodeFormatterService) *Server {
2526
return &Server{
2627
jwtService: jwtService,
2728
conversionService: conversionService,
@@ -213,7 +214,7 @@ func (s *Server) handleBarcodeService(method string, w http.ResponseWriter, r *h
213214
return
214215
}
215216

216-
req := GenerateBarcodeRequest{
217+
req := wails.GenerateBarcodeRequest{
217218
Content: getStringFromMap(reqData, "content"),
218219
Standard: getStringFromMap(reqData, "standard"),
219220
Size: getIntFromMap(reqData, "size"),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
2+
// This file is automatically generated. DO NOT EDIT
3+
import {codeformatter} from '../models';
4+
5+
export function Format(arg1:codeformatter.FormatRequest):Promise<codeformatter.FormatResponse>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-check
2+
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
3+
// This file is automatically generated. DO NOT EDIT
4+
5+
export function Format(arg1) {
6+
return window['go']['main']['CodeFormatterService']['Format'](arg1);
7+
}

wailsjs/go/models.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
export namespace codeformatter {
2+
3+
export class FormatRequest {
4+
input: string;
5+
formatType: string;
6+
filter?: string;
7+
minify: boolean;
8+
9+
static createFrom(source: any = {}) {
10+
return new FormatRequest(source);
11+
}
12+
13+
constructor(source: any = {}) {
14+
if ('string' === typeof source) source = JSON.parse(source);
15+
this.input = source["input"];
16+
this.formatType = source["formatType"];
17+
this.filter = source["filter"];
18+
this.minify = source["minify"];
19+
}
20+
}
21+
export class FormatResponse {
22+
output: string;
23+
error?: string;
24+
25+
static createFrom(source: any = {}) {
26+
return new FormatResponse(source);
27+
}
28+
29+
constructor(source: any = {}) {
30+
if ('string' === typeof source) source = JSON.parse(source);
31+
this.output = source["output"];
32+
this.error = source["error"];
33+
}
34+
}
35+
36+
}
37+
138
export namespace datagenerator {
239

340
export class GenerateRequest {

0 commit comments

Comments
 (0)