aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/service/updatestate.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-06 09:46:10 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-06 15:55:02 +0200
commit568528c747afe3ae991b0340d15cd6a897fd5c9d (patch)
treedd08e02b053b0cf27a75ed2e428701b1799e3bf1 /service/updatestate.go
parentui: do tray click action when popup clicked (diff)
downloadwireguard-windows-568528c747afe3ae991b0340d15cd6a897fd5c9d.tar.xz
wireguard-windows-568528c747afe3ae991b0340d15cd6a897fd5c9d.zip
updater: move into manager
Diffstat (limited to '')
-rw-r--r--service/updatestate.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/service/updatestate.go b/service/updatestate.go
new file mode 100644
index 00000000..c046edb2
--- /dev/null
+++ b/service/updatestate.go
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package service
+
+import (
+ "golang.zx2c4.com/wireguard/windows/updater"
+ "golang.zx2c4.com/wireguard/windows/version"
+ "log"
+ "time"
+)
+
+type UpdateState uint32
+
+const (
+ UpdateStateUnknown UpdateState = iota
+ UpdateStateFoundUpdate
+ UpdateStateUpdatesDisabledUnofficialBuild
+)
+
+var updateState = UpdateStateUnknown
+
+func checkForUpdates() {
+ if !version.IsRunningOfficialVersion() {
+ log.Println("Build is not official, so updates are disabled")
+ updateState = UpdateStateUpdatesDisabledUnofficialBuild
+ IPCServerNotifyUpdateFound(updateState)
+ return
+ }
+
+ time.Sleep(time.Second * 10)
+
+ first := true
+ for {
+ update, err := updater.CheckForUpdate()
+ if err == nil && update != nil {
+ log.Println("An update is available")
+ updateState = UpdateStateFoundUpdate
+ IPCServerNotifyUpdateFound(updateState)
+ return
+ }
+ if err != nil {
+ log.Printf("Update checker: %v", err)
+ if first {
+ time.Sleep(time.Minute * 4)
+ first = false
+ } else {
+ time.Sleep(time.Minute * 25)
+ }
+ } else {
+ time.Sleep(time.Hour)
+ }
+ }
+}