Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
64e2603542 | |||
6d684b34ef | |||
35ca7620f4 |
100
.gitea/workflows/publish.yaml
Normal file
100
.gitea/workflows/publish.yaml
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
# TODO: Need to install node here... How the fuck am I going to cache that bullshit...
|
||||||
|
# Figure out how to cache bullshit node
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUNNER_TOOL_CACHE: /opt/hostedtoolcache
|
||||||
|
GOMODCACHE: /opt/hostedtoolcache/go/pkg/mod
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Get Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version-file: 'go.mod'
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Setup Wails
|
||||||
|
run: |
|
||||||
|
# Install Wails CLI (if needed)
|
||||||
|
go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
||||||
|
|
||||||
|
- name: Build wails
|
||||||
|
run: wails build -platform darwin/amd64,darwin/arm64,windows/amd64,windows/arm64,linux/amd64,linux/arm64
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref }}
|
||||||
|
release_name: Release ${{ github.ref }}
|
||||||
|
body: |
|
||||||
|
Release notes for ${{ github.ref }}
|
||||||
|
|
||||||
|
- name: Upload Windows AMD64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-amd64.exe
|
||||||
|
asset_name: calorie-counter-amd64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload Windows ARM64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-arm64.exe
|
||||||
|
asset_name: calorie-counter-arm64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload Linux AMD64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-amd64.exe
|
||||||
|
asset_name: calorie-counter-amd64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload Linux ARM64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-arm64.exe
|
||||||
|
asset_name: calorie-counter-arm64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload Darwin AMD64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-amd64.exe
|
||||||
|
asset_name: calorie-counter-amd64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload Darwin ARM64
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: build/bin/calorie-counter-arm64.exe
|
||||||
|
asset_name: calorie-counter-arm64.exe
|
||||||
|
asset_content_type: application/octet-stream
|
53
db.go
53
db.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@@ -44,6 +45,58 @@ func (db *DB) Open() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) Init(ddl string) error {
|
||||||
|
if !db.Ready {
|
||||||
|
return fmt.Errorf("database not ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows map[string]struct{} = make(map[string]struct{})
|
||||||
|
// TODO: Maybe make this better one day...
|
||||||
|
var expected = map[string]struct{}{
|
||||||
|
"food": {},
|
||||||
|
"weight": {},
|
||||||
|
"settings": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := db.readConn.Query("SELECT name FROM sqlite_master WHERE type='table';")
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Close()
|
||||||
|
for res.Next() {
|
||||||
|
var name string
|
||||||
|
err := res.Scan(&name)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows[name] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var needsInit bool
|
||||||
|
for table := range expected {
|
||||||
|
if _, ok := rows[table]; !ok {
|
||||||
|
log.Printf("Table %s not found, initializing", table)
|
||||||
|
needsInit = true
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !needsInit {
|
||||||
|
log.Printf("Database already initialized")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.writeConn.Exec(ddl)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("%++v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DB) Close() error {
|
func (db *DB) Close() error {
|
||||||
err := db.writeConn.Close()
|
err := db.writeConn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
1
food.ddl
1
food.ddl
@@ -5,7 +5,6 @@ create table weight (
|
|||||||
weight real not null
|
weight real not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
create index weightDateIdx on weight(date);
|
create index weightDateIdx on weight(date);
|
||||||
create index weightDailyIdx on weight(strftime('%Y-%m-%d', date));
|
create index weightDailyIdx on weight(strftime('%Y-%m-%d', date));
|
||||||
create index weightWeeklyIdx on weight(strftime('%Y-%W', date));
|
create index weightWeeklyIdx on weight(strftime('%Y-%W', date));
|
||||||
|
7
main.go
7
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
@@ -39,7 +40,11 @@ var (
|
|||||||
weightService *WeightService
|
weightService *WeightService
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed food.ddl
|
||||||
|
var foodDDL string
|
||||||
|
|
||||||
// TODO: Embed food.ddl and create DB if no exists
|
// TODO: Embed food.ddl and create DB if no exists
|
||||||
|
// TODO: Add averages to graphs (ie. R2) https://stackoverflow.com/questions/60622195/how-to-draw-a-linear-regression-line-in-chart-js
|
||||||
func main() {
|
func main() {
|
||||||
dbpath := flag.String("db", "food.db", "Path to the database file")
|
dbpath := flag.String("db", "food.db", "Path to the database file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -50,6 +55,8 @@ func main() {
|
|||||||
Error.Printf("%++v", err)
|
Error.Printf("%++v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
defer db.Close()
|
||||||
|
db.Init(foodDDL)
|
||||||
|
|
||||||
settingsService = &SettingsService{db: &db}
|
settingsService = &SettingsService{db: &db}
|
||||||
err = settingsService.LoadSettings()
|
err = settingsService.LoadSettings()
|
||||||
|
Reference in New Issue
Block a user