Compare commits
12 Commits
main
...
ce29b8647b
Author | SHA1 | Date | |
---|---|---|---|
ce29b8647b | |||
16228eba7b | |||
db6e9b162f | |||
03bffbda7e | |||
778a2983ed | |||
9e6b8f05a2 | |||
967f75fcf6 | |||
3d63cec5ab | |||
2eafcd0ee9 | |||
4f42e95f28 | |||
e0080233b4 | |||
ed523b8fe2 |
@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
windows:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@v4
|
||||
@ -20,16 +20,32 @@ jobs:
|
||||
version: 10
|
||||
- name: install wails
|
||||
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
|
||||
- name: Archive win bins
|
||||
- name: Archive bins
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: windows-bins
|
||||
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
|
||||
- name: Archive linux bins
|
||||
- name: Archive bins
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: linux-bins
|
||||
|
36
.github/workflows/build.yml
vendored
36
.github/workflows/build.yml
vendored
@ -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
|
@ -6,8 +6,6 @@ Feel free to use this template on your own. To set it up just run ```setup.sh```
|
||||
|
||||
Enjoy :)
|
||||
|
||||
|
||||
|
||||
## Links
|
||||
|
||||
- [gorm](https://gorm.io/docs/)
|
||||
|
6
app.go
6
app.go
@ -5,19 +5,17 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/beeep"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -1,15 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<meta charset="UTF-8"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>wails-svelte-tailwind-ts</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="./src/main.ts" type="module"></script>
|
||||
<div id="app"></div>
|
||||
<script src="./src/main.ts" type="module"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -1,20 +1,14 @@
|
||||
<script lang="ts">
|
||||
import "./app.css";
|
||||
import { Router, Route, Link, navigate } from "svelte-routing";
|
||||
import Things from "./routes/Things.svelte";
|
||||
import Home from "./routes/Home.svelte";
|
||||
import "./app.css";
|
||||
import { Navbar, DarkMode } from "flowbite-svelte";
|
||||
import { Navbar, DarkMode, Heading } from "flowbite-svelte";
|
||||
import { HomeOutline } from "flowbite-svelte-icons";
|
||||
import Thing from "./routes/Thing.svelte";
|
||||
let url: string = $state("/");
|
||||
$effect(() => {
|
||||
console.log(url);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex flex-col h-screen w-screen items-center bg-gray-50 dark:bg-gray-900 overflow-clip"
|
||||
>
|
||||
<main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-900">
|
||||
<Router bind:url>
|
||||
<Navbar class="border-b">
|
||||
<button
|
||||
@ -26,13 +20,6 @@
|
||||
</button>
|
||||
<DarkMode />
|
||||
</Navbar>
|
||||
<main
|
||||
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>
|
||||
<Route path="/"><Home /></Route>
|
||||
</Router>
|
||||
</div>
|
||||
</main>
|
||||
|
@ -17,7 +17,6 @@
|
||||
TableBodyRow,
|
||||
TableBodyCell,
|
||||
} from "flowbite-svelte";
|
||||
import { navigate } from "svelte-routing";
|
||||
|
||||
let name: string = $state();
|
||||
let thingsList: model.Thing[] = $state([]);
|
||||
@ -34,6 +33,10 @@
|
||||
name = "";
|
||||
}
|
||||
|
||||
function deleteEvent(id: number) {
|
||||
DeleteThing(id).then(update);
|
||||
}
|
||||
|
||||
onMount(update);
|
||||
</script>
|
||||
|
||||
@ -50,7 +53,6 @@
|
||||
<TableHead>
|
||||
<TableHeadCell>ID</TableHeadCell>
|
||||
<TableHeadCell>Name</TableHeadCell>
|
||||
<TableHeadCell>View</TableHeadCell>
|
||||
<TableHeadCell>Delete</TableHeadCell>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
@ -63,13 +65,8 @@
|
||||
<TableBodyCell>
|
||||
{t.Name}
|
||||
</TableBodyCell>
|
||||
|
||||
<TableBodyCell>
|
||||
<Button onclick={() => navigate(`/things/${t.ID}`)}>View</Button>
|
||||
</TableBodyCell>
|
||||
|
||||
<TableBodyCell>
|
||||
<Button onclick={() => DeleteThing(t.ID).then(update)}>Delete</Button>
|
||||
<Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button>
|
||||
</TableBodyCell>
|
||||
</TableBodyRow>
|
||||
{/each}
|
@ -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>
|
@ -14,24 +14,7 @@
|
||||
*/
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"isolatedModules": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@assets/*": [
|
||||
"src/assets/*"
|
||||
],
|
||||
"@components/*": [
|
||||
"src/components/*"
|
||||
],
|
||||
"@routes/*": [
|
||||
"src/routes/*"
|
||||
],
|
||||
"@wails/*": [
|
||||
"src/wailsjs/*"
|
||||
]
|
||||
}
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.d.ts",
|
||||
|
@ -1,17 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
import path from 'path';
|
||||
import {defineConfig} from 'vite'
|
||||
import {svelte} from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
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'),
|
||||
},
|
||||
},
|
||||
plugins: [svelte()]
|
||||
})
|
||||
|
@ -1,8 +1,25 @@
|
||||
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 {
|
||||
ID: number;
|
||||
Name: string;
|
||||
Subthings: SubThing[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Thing(source);
|
||||
@ -12,6 +29,25 @@ export namespace model {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.ID = source["ID"];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
6
frontend/wailsjs/go/things/Service.d.ts
vendored
6
frontend/wailsjs/go/things/Service.d.ts
vendored
@ -2,8 +2,14 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
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 GetSubThings(arg1:number):Promise<Array<model.SubThing>>;
|
||||
|
||||
export function GetThings():Promise<Array<model.Thing>>;
|
||||
|
||||
export function NewThing(arg1:string):Promise<void>;
|
||||
|
@ -2,10 +2,22 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// 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) {
|
||||
return window['go']['things']['Service']['DeleteThing'](arg1);
|
||||
}
|
||||
|
||||
export function GetSubThings(arg1) {
|
||||
return window['go']['things']['Service']['GetSubThings'](arg1);
|
||||
}
|
||||
|
||||
export function GetThings() {
|
||||
return window['go']['things']['Service']['GetThings']();
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -15,13 +15,13 @@ var assets embed.FS
|
||||
|
||||
func main() {
|
||||
// Create an instance of the app structure
|
||||
app := NewApp()
|
||||
db := model.InitDB()
|
||||
app := NewApp(db)
|
||||
things := &things.Service{DB: db}
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
Title: "wails-template",
|
||||
Title: "wails-svelte-tailwind-ts",
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
AssetServer: &assetserver.Options{
|
||||
|
@ -12,6 +12,13 @@ import (
|
||||
type Thing struct {
|
||||
ID int
|
||||
Name string
|
||||
Subthings []SubThing
|
||||
}
|
||||
|
||||
type SubThing struct {
|
||||
ID int
|
||||
ThingID int
|
||||
Name string
|
||||
}
|
||||
|
||||
func InitDB() *gorm.DB {
|
||||
@ -23,6 +30,6 @@ func InitDB() *gorm.DB {
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
db.AutoMigrate(&Thing{})
|
||||
db.AutoMigrate(&Thing{}, &SubThing{})
|
||||
return db
|
||||
}
|
||||
|
2
setup.sh
2
setup.sh
@ -4,7 +4,7 @@
|
||||
CURRENT_DIR_NAME=$(basename "$PWD")
|
||||
|
||||
# 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
|
||||
OLD_STRING="wails-template"
|
||||
|
@ -31,3 +31,24 @@ func (s *Service) DeleteThing(id int) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user