Skip to content

Commit

Permalink
preparing for 0.17.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mindiae committed Sep 21, 2024
1 parent 8eca5ab commit f35e5cd
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 607 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": ["prettier-plugin-go-template"],
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "go-template"
}
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For creating windows installation file you have to have innosetup insalled
```bash
git clone https://github.com/mindiae/ourbible.git
cd ourbible
go build -o build/ourbible.exe -ldflags "-H=windowsgui" ./src
go build -o build/ourbible.exe -ldflags "-H=windowsgui" ./cmd/webview/
./build/ourbible.exe
```

Expand Down
50 changes: 50 additions & 0 deletions cmd/webview/customStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,53 @@ func SetBookChapter(db *sql.DB, bookNumber int16, value int16) error {

return nil
}

func GetStrings(db *sql.DB) (map[string]string, error) {
strings := map[string]string{}

rows, err := db.Query("SELECT key, value FROM strings")
if err != nil {
return nil, err
}
defer rows.Close()

for rows.Next() {
var key string
var value string
if err := rows.Scan(&key, &value); err != nil {
return nil, err
}
strings[key] = value
}

if err := rows.Err(); err != nil {
return nil, err
}

return strings, nil
}

func GetInts(db *sql.DB) (map[string]int16, error) {
ints := map[string]int16{}

rows, err := db.Query("SELECT key, value FROM numbers")
if err != nil {
return nil, err
}
defer rows.Close()

for rows.Next() {
var key string
var value int16
if err := rows.Scan(&key, &value); err != nil {
return nil, err
}
ints[key] = value
}

if err := rows.Err(); err != nil {
return nil, err
}

return ints, nil
}
121 changes: 89 additions & 32 deletions cmd/webview/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io"
"log"
"os"
"path/filepath"
"text/template"

_ "github.com/mattn/go-sqlite3"
webview "github.com/webview/webview_go"
Expand Down Expand Up @@ -68,16 +71,6 @@ func main() {
}
defer db.Close()

head := `
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
`

alpineSwipeFileName := filepath.Join(APP_ROOT, "static/js/alpinejs-swipe.js")
alpineSwipe, err := os.ReadFile(alpineSwipeFileName)
if err != nil {
Expand Down Expand Up @@ -106,51 +99,115 @@ func main() {
return
}

htmlFileName := filepath.Join(APP_ROOT, "static/webview.html")
htmlFileName := filepath.Join(APP_ROOT, "static/webview.tmpl")
html, err := os.ReadFile(htmlFileName)
if err != nil {
fmt.Println("Error reading webview.html file:", err)
fmt.Println("Error reading webview.tmpl file:", err)
return
}

w := webview.New(false)
tmpl, err := template.New("main").Parse(string(html))
if err != nil {
fmt.Println("Error parsing template:", err)
return
}

modules, err := ModulesHandler()
if err != nil {
fmt.Println("Error getting modules", err)
}
modulesJson, _ := json.Marshal(modules)

strings, err := GetStrings(db)
if err != nil {
fmt.Println("Error getting strings", err)
}

ints, err := GetInts(db)
if err != nil {
fmt.Println("Error getting numbers", err)
}

books, err := GetBooks(db)
if err != nil {
fmt.Println("Error getting books", err)
}
booksJson, _ := json.Marshal(books)

booksTable, err := BooksHandler(strings["module"])
if err != nil {
fmt.Println("Error getting booksTable", err)
}
booksTableJson, _ := json.Marshal(booksTable)

booksTable2 := []Book{}

if strings["module2"] != "" {
booksTable2, err = BooksHandler(strings["module2"])
if err != nil {
fmt.Println("Error getting booksTable", err)
}
}

booksTable2Json, _ := json.Marshal(booksTable2)

data := struct {
Style string
Javascript string
Module string
Module2 string
BookNumber int16
Chapter int16
Verse int16
IsSystemDarkMode int16
DarkMode int16
Books string
Modules string
BooksTable string
BooksTable2 string
}{
Style: "<style>" + string(bibleviewer) + string(fontawesome) + "</style>",
Javascript: "<script>" + string(alpineSwipe) + string(alpine) + "</script>",
Module: strings["module"],
Module2: strings["module2"],
BookNumber: ints["bookNumber"],
Chapter: ints["chapter"],
Verse: ints["verse"],
IsSystemDarkMode: ints["isSystemDarkMode"],
DarkMode: ints["darkMode"],
Books: string(booksJson),
Modules: string(modulesJson),
BooksTable: string(booksTableJson),
BooksTable2: string(booksTable2Json),
}

var tpl bytes.Buffer

if err := tmpl.Execute(&tpl, data); err != nil {
fmt.Println("Error executing template:", err)
return
}

w := webview.New(true)
w.SetTitle("OurBible")
w.SetSize(800, 600, webview.HintNone)

w.Bind("getBooks", BooksHandler)
w.Bind("getModules", ModulesHandler)
w.Bind("getChapters", ChapterHandler)
w.Bind("getStringItem", func(key string) (string, error) {
return GetStringItem(db, key)
})
w.Bind("setStringItem", func(key string, value string) error {
return SetStringItem(db, key, value)
})
w.Bind("getNumberItem", func(key string) (int16, error) {
return GetIntItem(db, key)
})
w.Bind("setNumberItem", func(key string, value int16) error {
return SetIntItem(db, key, value)
})
w.Bind("getBooks", func() ([]map[string]int16, error) {
return GetBooks(db)
})
w.Bind("setBookVerse", func(bookNumber int16, value int16) error {
return SetBookVerse(db, bookNumber, value)
})
w.Bind("setBookChapter", func(bookNumber int16, value int16) error {
return SetBookChapter(db, bookNumber, value)
})

w.SetHtml(head +
string(bibleviewer) +
string(fontawesome) +
`</style></head>` +
string(html) +
`<script>` +
string(alpineSwipe) +
string(alpine) +
`</script></html>`)
w.SetHtml(tpl.String())

w.Run()
}
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/mindiae/o
module github.com/mindiae/ourbible

go 1.23.0
go 1.23.1

require (
github.com/joho/godotenv v1.5.1
github.com/a-h/templ v0.2.778
github.com/labstack/echo/v4 v4.12.0
github.com/mattn/go-sqlite3 v1.14.22
github.com/webview/webview_go v0.0.0-20240220051247-56f456ca3a43
github.com/mattn/go-sqlite3 v1.14.23
github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6
)

require (
Expand All @@ -15,8 +15,8 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
30 changes: 16 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/a-h/templ v0.2.778 h1:VzhOuvWECrwOec4790lcLlZpP4Iptt5Q4K9aFxQmtaM=
github.com/a-h/templ v0.2.778/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
Expand All @@ -11,8 +13,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0=
github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand All @@ -21,17 +23,17 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/webview/webview_go v0.0.0-20240220051247-56f456ca3a43 h1:PwbNdNumoKba+ZgrE6ZpSluJfNJfyMuqwVyUB5+iLDI=
github.com/webview/webview_go v0.0.0-20240220051247-56f456ca3a43/go.mod h1:yE65LFCeWf4kyWD5re+h4XNvOHJEXOCOuJZ4v8l5sgk=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6 h1:VQpB2SpK88C6B5lPHTuSZKb2Qee1QWwiFlC5CKY4AW0=
github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6/go.mod h1:yE65LFCeWf4kyWD5re+h4XNvOHJEXOCOuJZ4v8l5sgk=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
14 changes: 0 additions & 14 deletions innosetup.iss
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
; -- 64Bit.iss --
; Demonstrates installation of a program built for the x64 (a.k.a. AMD64)
; architecture.
; To successfully run this installation and the program it installs,
; you must have a "x64" edition of Windows or Windows 11 on Arm.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES!

[Setup]
AppName=OurBible
AppVersion=0.10.0
Expand All @@ -16,13 +8,7 @@ UninstallDisplayIcon={app}\static\favicon.ico
Compression=lzma2
SolidCompression=yes
OutputDir=.\output
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible

[Files]
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"prettier": "^3.3.3",
"prettier-plugin-go-template": "^0.0.15"
}
}
Loading

0 comments on commit f35e5cd

Please sign in to comment.