MirrorBar+ part 2: tray, weather, radar, local news data
This commit is contained in:
@@ -21,6 +21,8 @@ const (
|
||||
trayWifi
|
||||
trayChevron
|
||||
trayWeather // added after the others so saved orders from older versions still mean the same thing
|
||||
trayNews
|
||||
traySys
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,6 +47,10 @@ const (
|
||||
|
||||
menuWeatherID = 26
|
||||
menuWeatherZipID = 27
|
||||
menuNewsID = 28
|
||||
menuNewsZipID = 29
|
||||
menuSysID = 34
|
||||
menuSysCopyID = 35
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -105,7 +111,22 @@ func trayItemsAt(x, clientH int32) []trayItem {
|
||||
continue // this PC has no battery
|
||||
}
|
||||
w = px(36)
|
||||
case trayVolume, trayWifi, trayWeather:
|
||||
case trayVolume, trayWifi:
|
||||
w = px(36)
|
||||
case trayWeather:
|
||||
if !showWeather {
|
||||
continue
|
||||
}
|
||||
w = px(36)
|
||||
case trayNews:
|
||||
if !showNews {
|
||||
continue
|
||||
}
|
||||
w = px(36)
|
||||
case traySys:
|
||||
if !showSys {
|
||||
continue
|
||||
}
|
||||
w = px(36)
|
||||
case trayChevron:
|
||||
w = px(28)
|
||||
@@ -296,6 +317,10 @@ func drawTray(hdc uintptr, w, h int32) {
|
||||
drawChevron(hdc, it.r)
|
||||
case trayWeather:
|
||||
drawWeatherIcon(hdc, it.r)
|
||||
case trayNews:
|
||||
drawNewsIcon(hdc, it.r)
|
||||
case traySys:
|
||||
drawSysIcon(hdc, it.r)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -576,6 +601,10 @@ func trayClick(kind int) {
|
||||
tapChord(vkLWin, 'A') // quick settings
|
||||
case trayWeather:
|
||||
weatherToggle()
|
||||
case trayNews:
|
||||
newsToggle()
|
||||
case traySys:
|
||||
sysToggle()
|
||||
case trayChevron:
|
||||
// If the hidden icons are already showing, a second click closes them. Sending
|
||||
// Win+B and Enter again would instead press Enter on the highlighted icon.
|
||||
@@ -662,6 +691,14 @@ func addTrayMenu(add func(flags uintptr, id uintptr, text string), sep func(), k
|
||||
add(0, menuWeatherID, "Show weather")
|
||||
add(0, menuWeatherZipID, "Weather ZIP code...")
|
||||
sep()
|
||||
case trayNews:
|
||||
add(0, menuNewsID, "Show local news")
|
||||
add(0, menuNewsZipID, "News ZIP code...")
|
||||
sep()
|
||||
case traySys:
|
||||
add(0, menuSysID, "Show system stats")
|
||||
add(0, menuSysCopyID, "Copy system stats")
|
||||
sep()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -680,7 +717,20 @@ func handleTrayCommand(cmd uintptr) bool {
|
||||
if !wxShown {
|
||||
weatherToggle()
|
||||
}
|
||||
case menuWeatherZipID:
|
||||
case menuNewsID:
|
||||
if !newsShown {
|
||||
newsToggle()
|
||||
}
|
||||
case menuSysID:
|
||||
if !sysShown {
|
||||
sysToggle()
|
||||
}
|
||||
case menuSysCopyID:
|
||||
if clipboardSet(sysText(sysGather())) {
|
||||
sysCopied = "Copied everything"
|
||||
sysCopiedAt = time.Now()
|
||||
}
|
||||
case menuWeatherZipID, menuNewsZipID:
|
||||
openSettings()
|
||||
case menuAutostartID:
|
||||
setAutostart(!autostartEnabled())
|
||||
@@ -697,7 +747,7 @@ func handleTrayCommand(cmd uintptr) bool {
|
||||
// ---------- the right row can be rearranged too ----------
|
||||
|
||||
// trayOrder is the left to right order of the items to the right of center.
|
||||
var trayOrder = []int{trayClock, trayWeather, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||
var trayOrder = []int{trayClock, trayWeather, trayNews, traySys, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||
|
||||
var (
|
||||
dragTray int // the tray item the mouse went down on, 0 for none
|
||||
@@ -716,22 +766,33 @@ func loadTrayOrder() {
|
||||
seen := map[int]bool{}
|
||||
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
|
||||
n, err := strconv.Atoi(strings.TrimSpace(p))
|
||||
if err != nil || n < trayClock || n > trayWeather || seen[n] {
|
||||
if err != nil || n < trayClock || n > traySys || seen[n] {
|
||||
return
|
||||
}
|
||||
seen[n] = true
|
||||
order = append(order, n)
|
||||
}
|
||||
// An order saved before the weather cloud existed: put the cloud next to the clock.
|
||||
if !seen[trayWeather] {
|
||||
withCloud := make([]int, 0, len(order)+1)
|
||||
// An order saved before the weather cloud or the newspaper existed: put the new
|
||||
// icon next to the clock (the newspaper goes after the cloud).
|
||||
insertAfter := func(after, kind int) {
|
||||
out := make([]int, 0, len(order)+1)
|
||||
for _, k := range order {
|
||||
withCloud = append(withCloud, k)
|
||||
if k == trayClock {
|
||||
withCloud = append(withCloud, trayWeather)
|
||||
out = append(out, k)
|
||||
if k == after {
|
||||
out = append(out, kind)
|
||||
}
|
||||
}
|
||||
order = withCloud
|
||||
order = out
|
||||
seen[kind] = true
|
||||
}
|
||||
if !seen[trayWeather] {
|
||||
insertAfter(trayClock, trayWeather)
|
||||
}
|
||||
if !seen[trayNews] {
|
||||
insertAfter(trayWeather, trayNews)
|
||||
}
|
||||
if !seen[traySys] {
|
||||
insertAfter(trayNews, traySys)
|
||||
}
|
||||
if len(order) == len(trayOrder) {
|
||||
trayOrder = order
|
||||
|
||||
Reference in New Issue
Block a user