Compare commits

..

12 Commits

Author SHA1 Message Date
ce29b8647b updated readme
Some checks failed
build / windows (push) Successful in 2m20s
build / linux (push) Has been cancelled
2025-03-03 13:50:03 +01:00
16228eba7b finalize workflow
Some checks failed
build / linux (push) Has been cancelled
build / windows (push) Has been cancelled
2025-03-03 13:29:40 +01:00
db6e9b162f add windows pipeline
All checks were successful
build-linux / linux (push) Successful in 1m56s
build-linux / windows (push) Successful in 4m47s
2025-03-03 13:05:34 +01:00
03bffbda7e use upload-artifact v3 to pls pls pls work now
All checks were successful
build-linux / publish (push) Successful in 5m53s
2025-03-03 12:06:31 +01:00
778a2983ed does it work now pls
Some checks failed
build-linux / publish (push) Failing after 5m30s
2025-03-03 11:58:33 +01:00
9e6b8f05a2 added tag to pleeeease fix it
Some checks failed
build-linux / publish (push) Failing after 5m34s
2025-03-03 11:49:21 +01:00
967f75fcf6 install all deps
Some checks failed
build-linux / publish (push) Failing after 4m39s
2025-03-03 11:21:08 +01:00
3d63cec5ab install pnpm in pipeline
Some checks failed
build-linux / publish (push) Failing after 4m4s
2025-03-03 11:09:39 +01:00
2eafcd0ee9 pipiline v4
Some checks failed
build-linux / publish (push) Failing after 3m34s
2025-03-03 11:04:16 +01:00
4f42e95f28 pipeline v3
Some checks failed
build-linux / publish (push) Failing after 39s
2025-03-03 11:01:34 +01:00
e0080233b4 pipeline v2
Some checks failed
build-linux / publish (push) Failing after 3m26s
2025-03-03 10:56:15 +01:00
ed523b8fe2 pipeline v1
Some checks failed
build-linux / publish (push) Failing after 1m55s
2025-03-03 10:53:40 +01:00
17 changed files with 130 additions and 144 deletions

View File

@ -4,7 +4,7 @@ on:
push: push:
jobs: jobs:
build: windows:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: https://github.com/actions/checkout@v4 - uses: https://github.com/actions/checkout@v4
@ -20,16 +20,32 @@ jobs:
version: 10 version: 10
- name: install wails - name: install wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- name: build for windows - name: build
run: env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_CXXFLAGS="-IC:\msys64\mingw64\include" wails build -ldflags '-extldflags "-static"' -skipbindings -nsis run: env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_CXXFLAGS="-IC:\msys64\mingw64\include" wails build -ldflags '-extldflags "-static"' -skipbindings -nsis
- name: Archive win bins - name: Archive bins
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: windows-bins name: windows-bins
path: build/bin path: build/bin
- name: build for linux linux:
runs-on: ubuntu-latest
steps:
- uses: https://github.com/actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24
- name: install apt dependencies
run: apt-get update && apt-get install -y nodejs libgtk-3-dev libwebkit2gtk-4.1-dev
- name: install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: install wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- name: build
run: wails build -tags webkit2_41 run: wails build -tags webkit2_41
- name: Archive linux bins - name: Archive bins
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: linux-bins name: linux-bins

View File

@ -1,36 +0,0 @@
name: build
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: https://github.com/actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24
- name: install apt dependencies
run: apt-get update && apt-get install -y mingw-w64 nsis nodejs libgtk-3-dev libwebkit2gtk-4.1-dev
- name: install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: install wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- name: build for windows
run: env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_CXXFLAGS="-IC:\msys64\mingw64\include" wails build -ldflags '-extldflags "-static"' -skipbindings -nsis
- name: Archive win bins
uses: actions/upload-artifact@v3
with:
name: windows-bins
path: build/bin
- name: build for linux
run: wails build -tags webkit2_41
- name: Archive linux bins
uses: actions/upload-artifact@v3
with:
name: linux-bins
path: build/bin

View File

@ -6,8 +6,6 @@ Feel free to use this template on your own. To set it up just run ```setup.sh```
Enjoy :) Enjoy :)
## Links ## Links
- [gorm](https://gorm.io/docs/) - [gorm](https://gorm.io/docs/)

6
app.go
View File

@ -5,19 +5,17 @@ import (
"fmt" "fmt"
"github.com/gen2brain/beeep" "github.com/gen2brain/beeep"
"gorm.io/gorm"
) )
// App struct // App struct
type App struct { type App struct {
ctx context.Context ctx context.Context
db *gorm.DB
} }
// NewApp creates a new App application struct // NewApp creates a new App application struct
func NewApp(db *gorm.DB) *App { func NewApp() *App {
return &App{db: db} return &App{}
} }
// startup is called when the app starts. The context is saved // startup is called when the app starts. The context is saved

View File

@ -1,15 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>wails-svelte-tailwind-ts</title> <title>wails-svelte-tailwind-ts</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="./src/main.ts" type="module"></script> <script src="./src/main.ts" type="module"></script>
</body> </body>
</html> </html>

View File

@ -1,20 +1,14 @@
<script lang="ts"> <script lang="ts">
import "./app.css"; import "./app.css";
import { Router, Route, Link, navigate } from "svelte-routing"; import { Router, Route, Link, navigate } from "svelte-routing";
import Things from "./routes/Things.svelte"; import Home from "./routes/Home.svelte";
import "./app.css"; import "./app.css";
import { Navbar, DarkMode } from "flowbite-svelte"; import { Navbar, DarkMode, Heading } from "flowbite-svelte";
import { HomeOutline } from "flowbite-svelte-icons"; import { HomeOutline } from "flowbite-svelte-icons";
import Thing from "./routes/Thing.svelte";
let url: string = $state("/"); let url: string = $state("/");
$effect(() => {
console.log(url);
});
</script> </script>
<div <main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-900">
class="flex flex-col h-screen w-screen items-center bg-gray-50 dark:bg-gray-900 overflow-clip"
>
<Router bind:url> <Router bind:url>
<Navbar class="border-b"> <Navbar class="border-b">
<button <button
@ -26,13 +20,6 @@
</button> </button>
<DarkMode /> <DarkMode />
</Navbar> </Navbar>
<main <Route path="/"><Home /></Route>
class="size-full max-h-full max-w-full overflow-y-scroll overflow-x-clip"
>
<Route path="/"><Things /></Route>
<Route path="/things/:id" let:params>
<Thing thingID={parseInt(params.id)} />
</Route>
</main>
</Router> </Router>
</div> </main>

View File

@ -17,7 +17,6 @@
TableBodyRow, TableBodyRow,
TableBodyCell, TableBodyCell,
} from "flowbite-svelte"; } from "flowbite-svelte";
import { navigate } from "svelte-routing";
let name: string = $state(); let name: string = $state();
let thingsList: model.Thing[] = $state([]); let thingsList: model.Thing[] = $state([]);
@ -34,6 +33,10 @@
name = ""; name = "";
} }
function deleteEvent(id: number) {
DeleteThing(id).then(update);
}
onMount(update); onMount(update);
</script> </script>
@ -50,7 +53,6 @@
<TableHead> <TableHead>
<TableHeadCell>ID</TableHeadCell> <TableHeadCell>ID</TableHeadCell>
<TableHeadCell>Name</TableHeadCell> <TableHeadCell>Name</TableHeadCell>
<TableHeadCell>View</TableHeadCell>
<TableHeadCell>Delete</TableHeadCell> <TableHeadCell>Delete</TableHeadCell>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -63,13 +65,8 @@
<TableBodyCell> <TableBodyCell>
{t.Name} {t.Name}
</TableBodyCell> </TableBodyCell>
<TableBodyCell> <TableBodyCell>
<Button onclick={() => navigate(`/things/${t.ID}`)}>View</Button> <Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button>
</TableBodyCell>
<TableBodyCell>
<Button onclick={() => DeleteThing(t.ID).then(update)}>Delete</Button>
</TableBodyCell> </TableBodyCell>
</TableBodyRow> </TableBodyRow>
{/each} {/each}

View File

@ -1,26 +0,0 @@
<script lang="ts">
import { GetThings } from "../../wailsjs/go/things/Service";
import { model } from "../../wailsjs/go/models";
import { onMount } from "svelte";
import { Heading } from "flowbite-svelte";
let { thingID }: { thingID: number } = $props();
let thing: model.Thing = $state(new model.Thing());
function update() {
GetThings().then((ts) => {
ts.forEach((t) => {
if (t.ID === thingID) {
thing = t;
}
});
});
}
onMount(update);
</script>
<div class="m-5">
<Heading>
{thing.Name}
</Heading>
</div>

View File

@ -14,24 +14,7 @@
*/ */
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"isolatedModules": true, "isolatedModules": true
"paths": {
"@/*": [
"src/*"
],
"@assets/*": [
"src/assets/*"
],
"@components/*": [
"src/components/*"
],
"@routes/*": [
"src/routes/*"
],
"@wails/*": [
"src/wailsjs/*"
]
}
}, },
"include": [ "include": [
"src/**/*.d.ts", "src/**/*.d.ts",

View File

@ -1,17 +1,7 @@
import { defineConfig } from 'vite' import {defineConfig} from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte' import {svelte} from '@sveltejs/vite-plugin-svelte'
import path from 'path';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [svelte()], plugins: [svelte()]
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@assets': path.resolve(__dirname, './src/assets'),
'@components': path.resolve(__dirname, './src/components'),
'@routes': path.resolve(__dirname, './src/routes'),
'@wails': path.resolve(__dirname, './src/wailsjs'),
},
},
}) })

View File

@ -1,8 +1,25 @@
export namespace model { export namespace model {
export class SubThing {
ID: number;
ThingID: number;
Name: string;
static createFrom(source: any = {}) {
return new SubThing(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.ThingID = source["ThingID"];
this.Name = source["Name"];
}
}
export class Thing { export class Thing {
ID: number; ID: number;
Name: string; Name: string;
Subthings: SubThing[];
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
return new Thing(source); return new Thing(source);
@ -12,7 +29,26 @@ export namespace model {
if ('string' === typeof source) source = JSON.parse(source); if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"]; this.ID = source["ID"];
this.Name = source["Name"]; this.Name = source["Name"];
this.Subthings = this.convertValues(source["Subthings"], SubThing);
} }
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
} }
} }

View File

@ -2,8 +2,14 @@
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {model} from '../models'; import {model} from '../models';
export function AddSubThing(arg1:number,arg2:string):Promise<void>;
export function DeleteSubThing(arg1:number):Promise<void>;
export function DeleteThing(arg1:number):Promise<void>; export function DeleteThing(arg1:number):Promise<void>;
export function GetSubThings(arg1:number):Promise<Array<model.SubThing>>;
export function GetThings():Promise<Array<model.Thing>>; export function GetThings():Promise<Array<model.Thing>>;
export function NewThing(arg1:string):Promise<void>; export function NewThing(arg1:string):Promise<void>;

View File

@ -2,10 +2,22 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
export function AddSubThing(arg1, arg2) {
return window['go']['things']['Service']['AddSubThing'](arg1, arg2);
}
export function DeleteSubThing(arg1) {
return window['go']['things']['Service']['DeleteSubThing'](arg1);
}
export function DeleteThing(arg1) { export function DeleteThing(arg1) {
return window['go']['things']['Service']['DeleteThing'](arg1); return window['go']['things']['Service']['DeleteThing'](arg1);
} }
export function GetSubThings(arg1) {
return window['go']['things']['Service']['GetSubThings'](arg1);
}
export function GetThings() { export function GetThings() {
return window['go']['things']['Service']['GetThings'](); return window['go']['things']['Service']['GetThings']();
} }

View File

@ -15,13 +15,13 @@ var assets embed.FS
func main() { func main() {
// Create an instance of the app structure // Create an instance of the app structure
app := NewApp()
db := model.InitDB() db := model.InitDB()
app := NewApp(db)
things := &things.Service{DB: db} things := &things.Service{DB: db}
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
Title: "wails-template", Title: "wails-svelte-tailwind-ts",
Width: 1024, Width: 1024,
Height: 768, Height: 768,
AssetServer: &assetserver.Options{ AssetServer: &assetserver.Options{

View File

@ -10,8 +10,15 @@ import (
) )
type Thing struct { type Thing struct {
ID int ID int
Name string Name string
Subthings []SubThing
}
type SubThing struct {
ID int
ThingID int
Name string
} }
func InitDB() *gorm.DB { func InitDB() *gorm.DB {
@ -23,6 +30,6 @@ func InitDB() *gorm.DB {
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
db.AutoMigrate(&Thing{}) db.AutoMigrate(&Thing{}, &SubThing{})
return db return db
} }

View File

@ -4,7 +4,7 @@
CURRENT_DIR_NAME=$(basename "$PWD") CURRENT_DIR_NAME=$(basename "$PWD")
# Define the files to be updated # Define the files to be updated
FILES=("main.go" "go.mod" "wails.json" "things/resource.go") FILES=("main.go" "go.mod" "wails.json")
# String to be replaced # String to be replaced
OLD_STRING="wails-template" OLD_STRING="wails-template"

View File

@ -31,3 +31,24 @@ func (s *Service) DeleteThing(id int) {
log.Fatal(err) log.Fatal(err)
} }
} }
func (s *Service) GetSubThings(thingID int) (subthings []model.SubThing) {
if err := s.DB.Where("thing_id = ?", thingID).Find(&subthings).Error; err != nil {
log.Fatal(err)
}
return
}
func (s *Service) AddSubThing(thingID int, name string) {
if err := s.DB.Save(&model.SubThing{
ThingID: thingID,
Name: name,
}).Error; err != nil {
log.Fatal(err)
}
}
func (s *Service) DeleteSubThing(id int) {
if err := s.DB.Delete(model.SubThing{}, id).Error; err != nil {
log.Fatal(err)
}
}