Skip to content

Commit

Permalink
Merge pull request #37 from synfinatic/remember-settings
Browse files Browse the repository at this point in the history
Remember settings
  • Loading branch information
synfinatic authored Aug 1, 2021
2 parents b898e9c + 42612dd commit 7c9d1a5
Show file tree
Hide file tree
Showing 7 changed files with 535 additions and 137 deletions.
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif
BUILDINFOSDET ?=
PROGRAM_ARGS ?=

PROJECT_VERSION := 2.0.1
PROJECT_VERSION := 2.1.0
BUILD_ID := 1
DOCKER_REPO := synfinatic
PROJECT_NAME := alpacascope
Expand Down Expand Up @@ -80,14 +80,14 @@ build-gui: darwin-gui darwin-release-gui windows linux-gui ## Build GUI binaries
@if test -z "`which fyne`"; then echo "Please install fyne: go get fyne.io/fyne/v2/cmd/fyne" ; exit 1 ; fi

.fyne-cross:
if test -z "`which fyne-cross`"; then echo "Please install fyne-cross: go get github.com/fyne-io/fyne-cross" ; exit 1 ; fi
@if test -z "`which fyne-cross`"; then echo "Please install fyne-cross: go get github.com/fyne-io/fyne-cross" ; exit 1 ; fi

# used by our github action to test building the release binaries + GUI on Linux
.build-test-binaries: $(LINUX_BIN) $(DARWIN_BIN) $(WINDOWS)

.PHONY: run
run: cmd/*.go ## build and run cria using $PROGRAM_ARGS
go run cmd/*.go $(PROGRAM_ARGS)
go run ./cmd/... $(PROGRAM_ARGS)

clean-all: clean ## clean _everything_

Expand All @@ -102,10 +102,11 @@ go-get: ## Get our go modules

.PHONY: build-race
build-race: .prepare ## Build race detection binary
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) cmd/*.go
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./cmd/...
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./gui/...

debug: .prepare ## Run debug in dlv
dlv debug cmd/*.go
dlv debug ./cmd/...

.PHONY: unittest
unittest: ## Run go unit tests
Expand Down Expand Up @@ -155,25 +156,25 @@ precheck: test test-fmt test-tidy ## Run all tests that happen in a PR
linux: $(LINUX_BIN) ## Build Linux/x86_64 CLI

$(LINUX_BIN): $(GO_FILES) | .prepare
GOARCH=amd64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUX_BIN) cmd/*.go
GOARCH=amd64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUX_BIN) ./cmd/...
@echo "Created: $(LINUX_BIN)"

linux-arm64: $(LINUXARM64_BIN) ## Build Linux/arm64 CLI

$(LINUXARM64_BIN): $(GO_FILES) | .prepare
GOARCH=arm64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM64_BIN) cmd/*.go
GOARCH=arm64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM64_BIN) ./cmd/...
@echo "Created: $(LINUXARM64_BIN)"

linux-arm32: $(LINUXARM32_BIN) ## Build Linux/arm64 CLI

$(LINUXARM32_BIN): $(GO_FILES) | .prepare
GOARCH=arm GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM32_BIN) cmd/*.go
GOARCH=arm GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM32_BIN) ./cmd/...
@echo "Created: $(LINUXARM32_BIN)"

darwin: $(DARWIN_BIN) ## Build MacOS/x86_64 CLI

$(DARWIN_BIN): $(GO_FILES) | .prepare
GOARCH=amd64 GOOS=darwin go build -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) cmd/*.go
GOARCH=amd64 GOOS=darwin go build -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) ./cmd/...
@echo "Created: $(DARWIN_BIN)"

darwin-gui: $(DARWIN_GUI) ## Build MacOS/x86_64 GUI
Expand All @@ -190,13 +191,14 @@ $(DARWIN_RELEASE_ZIP): $(DARWIN_RELEASE_GUI)


$(DARWIN_GUI): $(GO_FILES) | .build-gui-check .prepare
@go build -ldflags='$(LDFLAGS)' -o $(DARWIN_GUI) gui/*.go
go build -ldflags='$(LDFLAGS)' -o $(DARWIN_GUI) ./gui/...

windows: $(WINDOWS) ## Build Windows/x86_64 GUI

$(WINDOWS): $(GO_FILES) | .fyne-cross .prepare
@fyne-cross windows -app-id net.synfin.alpacascope -developer "Aaron Turner" \
-app-version $(PROJECT_VERSION) -ldflags '$(LDFLAGS)' \
-icon $(shell pwd)/gui/Icon.png \
-name AlpacaScope.exe $(shell pwd)/gui && \
mv fyne-cross/bin/windows-amd64/AlpacaScope.exe $(WINDOWS)

Expand All @@ -214,5 +216,6 @@ linux-gui: $(LINUX_GUI) ## Build Linux/x86_64 GUI
$(LINUX_GUI): $(GO_FILES) | .prepare .fyne-cross
@fyne-cross linux -app-id net.synfin.alpacascope \
-app-version $(PROJECT_VERSION) -ldflags '$(LDFLAGS)' \
-icon $(shell pwd)/gui/Icon.png \
-name alpacascope $(shell pwd)/gui && \
mv fyne-cross/bin/linux-amd64/alpacascope $(LINUX_GUI)
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ go 1.15

require (
fyne.io/fyne/v2 v2.0.3
github.com/fyne-io/fyne-cross v1.1.0 // indirect
github.com/go-resty/resty/v2 v2.3.0
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.8
github.com/sirupsen/logrus v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20201216054612-986b41b23924 // indirect
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742 // indirect
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fyne.io/fyne/v2 v2.0.3 h1:qzd2uLLrAVrNeqnLY44QZCsMxZwjoo1my+lMzHicMXY=
fyne.io/fyne/v2 v2.0.3/go.mod h1:nNpgL7sZkDVLraGtQII2ArNRnnl6kHup/KfQRxIhbvs=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand All @@ -11,8 +10,6 @@ github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fyne-io/fyne-cross v1.1.0 h1:JHdDNet6N5fyqygHd8PFAEcFooaPqwU7jPFtbZKBVCA=
github.com/fyne-io/fyne-cross v1.1.0/go.mod h1:ot1tAui7RAG2jIno8lG+H1EkOwgmfB7EikvlKN5rOR4=
github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a h1:3TAJhl8vXyli0tooKB0vd6gLCyBdWL4QEYbDoJpHEZk=
github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
Expand Down
100 changes: 100 additions & 0 deletions gui/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package main

/*
* AlpacaScope
* Copyright (c) 2020-2021 Aaron Turner <synfinatic at gmail dot com>
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or with the authors permission any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import (
"fmt"
"strings"

"github.com/synfinatic/alpacascope/alpaca"
)

// Our actual application config
type AlpacaScopeConfig struct {
TelescopeProtocol string `json:"TelescopeProtocol"`
TelescopeMount string `json:"TelescopeMount"`
ListenIp string `json:"ListenIp"`
ListenPort string `json:"ListenPort"`
AscomAuto bool `json:"AscomAuto"`
AscomIp string `json:"AscomIp"`
AscomPort string `json:"AscomPort"`
AscomTelescope string `json:"AscomTelescope"`
isRunning bool
Quit chan bool `json:"-"` // have to hide since public
EnableButtons chan bool `json:"-"`
store *SettingsStore // platform specific
}

// Loads the config from our SettingsStore (if it exists),
// otherwise will return our defaults. Errors are informational
// so you know why loading settings failed.
func NewAlpacaScopeConfig() (*AlpacaScopeConfig, error) {
config := &AlpacaScopeConfig{
TelescopeProtocol: "NexStar",
TelescopeMount: "Alt-Az",
AscomAuto: true,
ListenIp: "All-Interfaces/0.0.0.0",
ListenPort: "4030",
AscomIp: "127.0.0.1",
AscomPort: alpaca.DEFAULT_PORT_STR,
AscomTelescope: "0",
Quit: make(chan bool),
EnableButtons: make(chan bool),
store: nil,
}

s := NewSettingsStore()

// load config. maybe it worked? Don't care really....
err := s.GetSettings(config)
config.SetStore(s)

return config, err
}

// pass through these call to the underlying SettingsStore
func (a *AlpacaScopeConfig) Save() error {
if a.store != nil {
return a.store.SaveSettings(a)
}
return fmt.Errorf("No valid SettingsStore")
}

func (a *AlpacaScopeConfig) Delete() error {
if a.store != nil {
return a.store.Delete()
}
return fmt.Errorf("No valid SettingsStore")
}

func (c *AlpacaScopeConfig) ListenIpAddress() string {
ips := strings.SplitN(c.ListenIp, "/", 2)
if len(ips) == 2 {
return ips[1]
}
return ips[0]
}

func (c *AlpacaScopeConfig) IsRunning() bool {
return c.isRunning
}

func (c *AlpacaScopeConfig) SetStore(store *SettingsStore) {
c.store = store
}
Loading

0 comments on commit 7c9d1a5

Please sign in to comment.