Compare commits
12 Commits
ce29b8647b
...
main
Author | SHA1 | Date | |
---|---|---|---|
bc99e35c79 | |||
58de81e47c | |||
b3bc1c4965 | |||
d2164622c4 | |||
7bae1918c4 | |||
e55904f8f2 | |||
2b13e5c03a | |||
feb248e991 | |||
42e8605945 | |||
bd3b0a3377 | |||
1a82a75aaf | |||
0f710b8d9f |
@ -4,7 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
windows:
|
build:
|
||||||
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,32 +20,16 @@ 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
|
- 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
|
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 bins
|
- name: Archive win 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
|
||||||
linux:
|
- name: build for 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 bins
|
- name: Archive linux bins
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: linux-bins
|
name: linux-bins
|
||||||
|
36
.github/workflows/build.yml
vendored
Normal file
36
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
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,6 +6,8 @@ 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
6
app.go
@ -5,17 +5,19 @@ 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() *App {
|
func NewApp(db *gorm.DB) *App {
|
||||||
|
|
||||||
return &App{}
|
return &App{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
// startup is called when the app starts. The context is saved
|
// startup is called when the app starts. The context is saved
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
<!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>
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
<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 Home from "./routes/Home.svelte";
|
import Things from "./routes/Things.svelte";
|
||||||
import "./app.css";
|
import "./app.css";
|
||||||
import { Navbar, DarkMode, Heading } from "flowbite-svelte";
|
import { Navbar, DarkMode } 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>
|
||||||
|
|
||||||
<main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-900">
|
<div
|
||||||
|
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
|
||||||
@ -20,6 +26,13 @@
|
|||||||
</button>
|
</button>
|
||||||
<DarkMode />
|
<DarkMode />
|
||||||
</Navbar>
|
</Navbar>
|
||||||
<Route path="/"><Home /></Route>
|
<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>
|
||||||
</Router>
|
</Router>
|
||||||
</main>
|
</div>
|
||||||
|
26
frontend/src/routes/Thing.svelte
Normal file
26
frontend/src/routes/Thing.svelte
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<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>
|
@ -17,6 +17,7 @@
|
|||||||
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([]);
|
||||||
@ -33,10 +34,6 @@
|
|||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteEvent(id: number) {
|
|
||||||
DeleteThing(id).then(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(update);
|
onMount(update);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -53,6 +50,7 @@
|
|||||||
<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>
|
||||||
@ -65,8 +63,13 @@
|
|||||||
<TableBodyCell>
|
<TableBodyCell>
|
||||||
{t.Name}
|
{t.Name}
|
||||||
</TableBodyCell>
|
</TableBodyCell>
|
||||||
|
|
||||||
<TableBodyCell>
|
<TableBodyCell>
|
||||||
<Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button>
|
<Button onclick={() => navigate(`/things/${t.ID}`)}>View</Button>
|
||||||
|
</TableBodyCell>
|
||||||
|
|
||||||
|
<TableBodyCell>
|
||||||
|
<Button onclick={() => DeleteThing(t.ID).then(update)}>Delete</Button>
|
||||||
</TableBodyCell>
|
</TableBodyCell>
|
||||||
</TableBodyRow>
|
</TableBodyRow>
|
||||||
{/each}
|
{/each}
|
@ -14,7 +14,24 @@
|
|||||||
*/
|
*/
|
||||||
"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",
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
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'),
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,25 +1,8 @@
|
|||||||
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);
|
||||||
@ -29,25 +12,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
frontend/wailsjs/go/things/Service.d.ts
vendored
6
frontend/wailsjs/go/things/Service.d.ts
vendored
@ -2,14 +2,8 @@
|
|||||||
// 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>;
|
||||||
|
@ -2,22 +2,10 @@
|
|||||||
// 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']();
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -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-svelte-tailwind-ts",
|
Title: "wails-template",
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 768,
|
Height: 768,
|
||||||
AssetServer: &assetserver.Options{
|
AssetServer: &assetserver.Options{
|
||||||
|
@ -12,13 +12,6 @@ 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 {
|
||||||
@ -30,6 +23,6 @@ func InitDB() *gorm.DB {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
db.AutoMigrate(&Thing{}, &SubThing{})
|
db.AutoMigrate(&Thing{})
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
2
setup.sh
2
setup.sh
@ -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")
|
FILES=("main.go" "go.mod" "wails.json" "things/resource.go")
|
||||||
|
|
||||||
# String to be replaced
|
# String to be replaced
|
||||||
OLD_STRING="wails-template"
|
OLD_STRING="wails-template"
|
||||||
|
@ -31,24 +31,3 @@ 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user