7 Commits

9 changed files with 71 additions and 35 deletions

View File

@@ -12,7 +12,7 @@
### Features ### Features
- Notification relay - Notification relay
- Notificstion transliteration - Notification transliteration
- Music control - Music control
- Get info from watch (HRM, Battery level, Firmware version) - Get info from watch (HRM, Battery level, Firmware version)
- Set current time - Set current time

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
"path/filepath"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
@@ -18,11 +19,12 @@ import (
func upgradeTab(parent fyne.Window) *fyne.Container { func upgradeTab(parent fyne.Window) *fyne.Container {
var ( var (
archivePath string archivePath string
fiwmarePath string firmwarePath string
initPktPath string initPktPath string
) )
var archiveBtn *widget.Button
// Create archive selection dialog // Create archive selection dialog
archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
@@ -30,25 +32,29 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
} }
uc.Close() uc.Close()
archivePath = uc.URI().Path() archivePath = uc.URI().Path()
archiveBtn.SetText(fmt.Sprintf("Select archive (.zip) [%s]", filepath.Base(archivePath)))
}, parent) }, parent)
// Limit dialog to .zip files // Limit dialog to .zip files
archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"})) archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"}))
// Create button to show dialog // Create button to show dialog
archiveBtn := widget.NewButton("Select archive (.zip)", archiveDialog.Show) archiveBtn = widget.NewButton("Select archive (.zip)", archiveDialog.Show)
var firmwareBtn *widget.Button
// Create firmware selection dialog // Create firmware selection dialog
firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
return return
} }
uc.Close() uc.Close()
fiwmarePath = uc.URI().Path() firmwarePath = uc.URI().Path()
firmwareBtn.SetText(fmt.Sprintf("Select firmware (.bin) [%s]", filepath.Base(firmwarePath)))
}, parent) }, parent)
// Limit dialog to .bin files // Limit dialog to .bin files
firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"})) firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"}))
// Create button to show dialog // Create button to show dialog
firmwareBtn := widget.NewButton("Select init packet (.bin)", firmwareDialog.Show) firmwareBtn = widget.NewButton("Select firmware (.bin)", firmwareDialog.Show)
var initPktBtn *widget.Button
// Create init packet selection dialog // Create init packet selection dialog
initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
@@ -56,11 +62,12 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
} }
uc.Close() uc.Close()
initPktPath = uc.URI().Path() initPktPath = uc.URI().Path()
initPktBtn.SetText(fmt.Sprintf("Select init packet (.dat) [%s]", filepath.Base(initPktPath)))
}, parent) }, parent)
// Limit dialog to .dat files // Limit dialog to .dat files
initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"})) initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"}))
// Create button to show dialog // Create button to show dialog
initPktBtn := widget.NewButton("Select init packet (.dat)", initPktDialog.Show) initPktBtn = widget.NewButton("Select init packet (.dat)", initPktDialog.Show)
// Hide init packet and firmware buttons // Hide init packet and firmware buttons
initPktBtn.Hide() initPktBtn.Hide()
@@ -91,7 +98,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
startBtn := widget.NewButton("Start", func() { startBtn := widget.NewButton("Start", func() {
// If archive path does not exist and both init packet and firmware paths // If archive path does not exist and both init packet and firmware paths
// also do not exist, return error // also do not exist, return error
if archivePath == "" && (initPktPath == "" && fiwmarePath == "") { if archivePath == "" && (initPktPath == "" && firmwarePath == "") {
guiErr(nil, "Upgrade requires archive or files selected", false, parent) guiErr(nil, "Upgrade requires archive or files selected", false, parent)
return return
} }
@@ -119,7 +126,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
files = append(files, archivePath) files = append(files, archivePath)
case "Files": case "Files":
fwUpgType = types.UpgradeTypeFiles fwUpgType = types.UpgradeTypeFiles
files = append(files, initPktPath, fiwmarePath) files = append(files, initPktPath, firmwarePath)
} }
// Dial itd UNIX socket // Dial itd UNIX socket

2
go.mod
View File

@@ -21,7 +21,7 @@ require (
github.com/spf13/cast v1.4.1 // indirect github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.2.1 github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1 github.com/spf13/viper v1.8.1
go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4 go.arsenm.dev/infinitime v0.0.0-20211007000821-a1e08ed862f1
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.7 golang.org/x/text v0.3.7
) )

4
go.sum
View File

@@ -315,8 +315,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4 h1:XZyynxrvGxP0mwyhdiuMrvj5SkiK6N+MDiC6DiGzgWU= go.arsenm.dev/infinitime v0.0.0-20211007000821-a1e08ed862f1 h1:URdmeEE9G0vycCt7oLDHH9IV3Nz5L5guPwcBWb5ztrU=
go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= go.arsenm.dev/infinitime v0.0.0-20211007000821-a1e08ed862f1/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

View File

@@ -36,7 +36,7 @@ import (
) )
func startSocket(dev *infinitime.Device) error { func startSocket(dev *infinitime.Device) error {
// Make socket directory if non-existent // Make socket directory if non-existant
err := os.MkdirAll(filepath.Dir(viper.GetString("socket.path")), 0755) err := os.MkdirAll(filepath.Dir(viper.GetString("socket.path")), 0755)
if err != nil { if err != nil {
return err return err

View File

@@ -4,7 +4,9 @@ import (
"strings" "strings"
) )
type ArmenianTranslit struct{} type ArmenianTranslit struct {
initComplete bool
}
var armenianMap = []string{ var armenianMap = []string{
"աու", "au", "աու", "au",
@@ -120,16 +122,26 @@ var armenianMap = []string{
"ւ", "", "ւ", "",
} }
func init() { func (at *ArmenianTranslit) Init() {
lower := armenianMap if !at.initComplete {
for i, val := range lower { // Copy map as original will be changed
if i%2 == 1 { lower := armenianMap
continue // For every value in copied map
} for i, val := range lower {
capital := strings.Title(val) // If index is odd, skip
if capital != val { if i%2 == 1 {
armenianMap = append(armenianMap, capital, strings.Title(armenianMap[i+1])) continue
}
// Capitalize first letter
capital := strings.Title(val)
// If capital is not the same as lowercase
if capital != val {
// Add capital to map
armenianMap = append(armenianMap, capital, strings.Title(armenianMap[i+1]))
}
} }
// Set init complete to true so it is not run again
at.initComplete = true
} }
} }

View File

@@ -12,6 +12,8 @@ import (
// conversion library. // conversion library.
type ChineseTranslit struct{} type ChineseTranslit struct{}
func (ChineseTranslit) Init() {}
func (ct *ChineseTranslit) Transliterate(s string) string { func (ct *ChineseTranslit) Transliterate(s string) string {
// Create buffer for final output // Create buffer for final output
outBuf := &bytes.Buffer{} outBuf := &bytes.Buffer{}
@@ -37,6 +39,15 @@ func (ct *ChineseTranslit) Transliterate(s string) string {
outBuf.WriteRune(char) outBuf.WriteRune(char)
} }
} }
// If buffer contains characters
if tmpBuf.Len() > 0 {
// Convert to pinyin (without tones)
out := pinyin.LazyConvert(tmpBuf.String(), nil)
// Write space-separated string to output
outBuf.WriteString(strings.Join(out, " "))
// Reset temporary buffer
tmpBuf.Reset()
}
// Return output string // Return output string
return outBuf.String() return outBuf.String()
} }

View File

@@ -39,6 +39,8 @@ var compatJamoBlock = &unicode.RangeTable{
// This was translated to Go from the code in https://codeberg.org/Freeyourgadget/Gadgetbridge // This was translated to Go from the code in https://codeberg.org/Freeyourgadget/Gadgetbridge
type KoreanTranslit struct{} type KoreanTranslit struct{}
func (KoreanTranslit) Init() {}
// User input consisting of isolated jamo is usually mapped to the KS X 1001 compatibility // User input consisting of isolated jamo is usually mapped to the KS X 1001 compatibility
// block, but jamo resulting from decomposed syllables are mapped to the modern one. This // block, but jamo resulting from decomposed syllables are mapped to the modern one. This
// function maps compat jamo to modern ones where possible and returns all other characters // function maps compat jamo to modern ones where possible and returns all other characters

View File

@@ -9,9 +9,9 @@ func Transliterate(s string, useMaps ...string) string {
// Create variable to store modified string // Create variable to store modified string
out := s out := s
// If custom map exists // If custom map exists
if customMap, ok := Transliterators["custom"]; ok { if custom, ok := Transliterators["custom"]; ok {
// Perform transliteration with it // Perform transliteration with it
out = customMap.Transliterate(out) out = custom.Transliterate(out)
} }
// For every map to use // For every map to use
for _, useMap := range useMaps { for _, useMap := range useMaps {
@@ -20,12 +20,13 @@ func Transliterate(s string, useMaps ...string) string {
continue continue
} }
// Get requested map // Get requested map
translitMap, ok := Transliterators[useMap] transliterator, ok := Transliterators[useMap]
if !ok { if !ok {
continue continue
} }
transliterator.Init()
// Perform transliteration // Perform transliteration
out = translitMap.Transliterate(out) out = transliterator.Transliterate(out)
} }
// Return result // Return result
return out return out
@@ -36,10 +37,11 @@ func Transliterate(s string, useMaps ...string) string {
// and returns the resulting string. // and returns the resulting string.
type Transliterator interface { type Transliterator interface {
Transliterate(string) string Transliterate(string) string
Init()
} }
// Map implements Transliterator using a slice where // Map implements Transliterator using a slice where
// every odd element is a key and every even one is a value // every even element is a key and every odd one is a value
// which replaces the key. // which replaces the key.
type Map []string type Map []string
@@ -47,6 +49,8 @@ func (mt Map) Transliterate(s string) string {
return strings.NewReplacer(mt...).Replace(s) return strings.NewReplacer(mt...).Replace(s)
} }
func (Map) Init() {}
// Transliterators stores transliterator implementations for each supported language. // Transliterators stores transliterator implementations for each supported language.
// Some of these were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge // Some of these were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge
var Transliterators = map[string]Transliterator{ var Transliterators = map[string]Transliterator{
@@ -151,7 +155,7 @@ var Transliterators = map[string]Transliterator{
"Ζ", "Z", "Ζ", "Z",
"Η", "I", "Η", "I",
"Ή", "I", "Ή", "I",
"Θ", "TH", "Θ", "Th",
"Ι", "I", "Ι", "I",
"Ί", "I", "Ί", "I",
"Ϊ", "I", "Ϊ", "I",
@@ -159,7 +163,7 @@ var Transliterators = map[string]Transliterator{
"Λ", "L", "Λ", "L",
"Μ", "M", "Μ", "M",
"Ν", "N", "Ν", "N",
"Ξ", "KS", "Ξ", "Ks",
"Ο", "O", "Ο", "O",
"Ό", "O", "Ό", "O",
"Π", "P", "Π", "P",
@@ -170,8 +174,8 @@ var Transliterators = map[string]Transliterator{
"Ύ", "Y", "Ύ", "Y",
"Ϋ", "Y", "Ϋ", "Y",
"Φ", "F", "Φ", "F",
"Χ", "CH", "Χ", "Ch",
"Ψ", "PS", "Ψ", "Ps",
"Ω", "O", "Ω", "O",
"Ώ", "O", "Ώ", "O",
}, },
@@ -184,8 +188,8 @@ var Transliterators = map[string]Transliterator{
"є", "je", "є", "je",
"і", "i", "і", "i",
"ї", "ji", "ї", "ji",
"Ґ", "GH", "Ґ", "Gh",
"Є", "JE", "Є", "Je",
"І", "I", "І", "I",
"Ї", "JI", "Ї", "JI",
}, },