Google Messages text flyout, part 1
This commit is contained in:
+146
-128
@@ -1,128 +1,146 @@
|
||||
package main
|
||||
|
||||
// The two optional features, weather and local news. Each can be turned off in
|
||||
// the settings window: its icon leaves the bar, its panel is closed, and nothing
|
||||
// is downloaded for it. Both are on until switched off.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
showWeather = true
|
||||
showNews = true
|
||||
showSys = true
|
||||
)
|
||||
|
||||
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
||||
|
||||
func loadFeatures() {
|
||||
b, err := os.ReadFile(featuresFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, ln := range strings.Split(string(b), "\n") {
|
||||
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
on := strings.TrimSpace(v) != "0"
|
||||
switch strings.TrimSpace(k) {
|
||||
case "weather":
|
||||
showWeather = on
|
||||
case "news":
|
||||
showNews = on
|
||||
case "sys":
|
||||
showSys = on
|
||||
case "panelfade":
|
||||
flyMatchBar = on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveFeatures() {
|
||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\npanelfade=" + b01(flyMatchBar) + "\n"
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
func b01(b bool) string {
|
||||
if b {
|
||||
return "1"
|
||||
}
|
||||
return "0"
|
||||
}
|
||||
|
||||
// setShowWeather is called by the settings window.
|
||||
func setShowWeather(on bool) {
|
||||
if showWeather == on {
|
||||
return
|
||||
}
|
||||
showWeather = on
|
||||
saveFeatures()
|
||||
if on {
|
||||
weatherRefresh(false)
|
||||
} else {
|
||||
weatherHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setShowNews is called by the settings window.
|
||||
func setShowNews(on bool) {
|
||||
if showNews == on {
|
||||
return
|
||||
}
|
||||
showNews = on
|
||||
saveFeatures()
|
||||
if on {
|
||||
newsRefresh(false)
|
||||
} else {
|
||||
newsHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setShowSys is called by the settings window.
|
||||
func setShowSys(on bool) {
|
||||
if showSys == on {
|
||||
return
|
||||
}
|
||||
showSys = on
|
||||
saveFeatures()
|
||||
if !on {
|
||||
sysHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setFlyMatchBar is called by the settings window: should the panels be as
|
||||
// see-through as the bar?
|
||||
func setFlyMatchBar(on bool) {
|
||||
if flyMatchBar == on {
|
||||
return
|
||||
}
|
||||
flyMatchBar = on
|
||||
saveFeatures()
|
||||
flyRefreshAll()
|
||||
}
|
||||
|
||||
func featuresChanged() {
|
||||
settingsZipStatusUpdate()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
|
||||
// zipStatusText is the one line the settings window shows under the ZIP box.
|
||||
func zipStatusText() string {
|
||||
switch {
|
||||
case !showWeather && !showNews:
|
||||
return "Weather and news are both turned off."
|
||||
case wxZip == "":
|
||||
return "Type a 5 digit ZIP code to turn on weather and local news."
|
||||
case showWeather:
|
||||
return weatherStatusText()
|
||||
}
|
||||
return newsStatusText()
|
||||
}
|
||||
package main
|
||||
|
||||
// The two optional features, weather and local news. Each can be turned off in
|
||||
// the settings window: its icon leaves the bar, its panel is closed, and nothing
|
||||
// is downloaded for it. Both are on until switched off.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
showWeather = true
|
||||
showNews = true
|
||||
showSys = true
|
||||
showGM = true // the Google Messages bubble
|
||||
)
|
||||
|
||||
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
||||
|
||||
func loadFeatures() {
|
||||
b, err := os.ReadFile(featuresFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, ln := range strings.Split(string(b), "\n") {
|
||||
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
on := strings.TrimSpace(v) != "0"
|
||||
switch strings.TrimSpace(k) {
|
||||
case "weather":
|
||||
showWeather = on
|
||||
case "news":
|
||||
showNews = on
|
||||
case "sys":
|
||||
showSys = on
|
||||
case "messages":
|
||||
showGM = on
|
||||
case "panelfade":
|
||||
flyMatchBar = on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveFeatures() {
|
||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\n"
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
func b01(b bool) string {
|
||||
if b {
|
||||
return "1"
|
||||
}
|
||||
return "0"
|
||||
}
|
||||
|
||||
// setShowWeather is called by the settings window.
|
||||
func setShowWeather(on bool) {
|
||||
if showWeather == on {
|
||||
return
|
||||
}
|
||||
showWeather = on
|
||||
saveFeatures()
|
||||
if on {
|
||||
weatherRefresh(false)
|
||||
} else {
|
||||
weatherHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setShowNews is called by the settings window.
|
||||
func setShowNews(on bool) {
|
||||
if showNews == on {
|
||||
return
|
||||
}
|
||||
showNews = on
|
||||
saveFeatures()
|
||||
if on {
|
||||
newsRefresh(false)
|
||||
} else {
|
||||
newsHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setShowSys is called by the settings window.
|
||||
func setShowSys(on bool) {
|
||||
if showSys == on {
|
||||
return
|
||||
}
|
||||
showSys = on
|
||||
saveFeatures()
|
||||
if !on {
|
||||
sysHide()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setShowGM is called by the settings window.
|
||||
func setShowGM(on bool) {
|
||||
if showGM == on {
|
||||
return
|
||||
}
|
||||
showGM = on
|
||||
saveFeatures()
|
||||
if on {
|
||||
gmAutoTried = false // let the background check start Messages again
|
||||
} else {
|
||||
gmClose()
|
||||
}
|
||||
featuresChanged()
|
||||
}
|
||||
|
||||
// setFlyMatchBar is called by the settings window: should the panels be as
|
||||
// see-through as the bar?
|
||||
func setFlyMatchBar(on bool) {
|
||||
if flyMatchBar == on {
|
||||
return
|
||||
}
|
||||
flyMatchBar = on
|
||||
saveFeatures()
|
||||
flyRefreshAll()
|
||||
}
|
||||
|
||||
func featuresChanged() {
|
||||
settingsZipStatusUpdate()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
|
||||
// zipStatusText is the one line the settings window shows under the ZIP box.
|
||||
func zipStatusText() string {
|
||||
switch {
|
||||
case !showWeather && !showNews:
|
||||
return "Weather and news are both turned off."
|
||||
case wxZip == "":
|
||||
return "Type a 5 digit ZIP code to turn on weather and local news."
|
||||
case showWeather:
|
||||
return weatherStatusText()
|
||||
}
|
||||
return newsStatusText()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user