@@ -80,12 +80,32 @@ func Start(src string) string {
80
80
}
81
81
82
82
// Otherwise copy to a path with -temp suffix
83
- if err := copyExe (src , AddTempSuffixToPath (src )); err != nil {
83
+ if err := copyExe (src , addTempSuffixToPath (src )); err != nil {
84
84
panic (err )
85
85
}
86
86
return ""
87
87
}
88
88
89
+ func CheckForUpdates (currentVersion string , updateAPIURL , updateBinURL string , cmdName string ) (string , error ) {
90
+ path , err := os .Executable ()
91
+ if err != nil {
92
+ return "" , err
93
+ }
94
+ var up = & Updater {
95
+ CurrentVersion : currentVersion ,
96
+ APIURL : updateAPIURL ,
97
+ BinURL : updateBinURL ,
98
+ DiffURL : "" ,
99
+ Dir : "update/" ,
100
+ CmdName : cmdName ,
101
+ }
102
+
103
+ if err := up .BackgroundRun (); err != nil {
104
+ return "" , err
105
+ }
106
+ return addTempSuffixToPath (path ), nil
107
+ }
108
+
89
109
func copyExe (from , to string ) error {
90
110
data , err := os .ReadFile (from )
91
111
if err != nil {
@@ -100,8 +120,8 @@ func copyExe(from, to string) error {
100
120
return nil
101
121
}
102
122
103
- // AddTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
104
- func AddTempSuffixToPath (path string ) string {
123
+ // addTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
124
+ func addTempSuffixToPath (path string ) string {
105
125
if filepath .Ext (path ) == "exe" {
106
126
path = strings .Replace (path , ".exe" , "-temp.exe" , - 1 )
107
127
} else {
@@ -266,7 +286,7 @@ func (u *Updater) update() error {
266
286
return err
267
287
}
268
288
269
- path = AddTempSuffixToPath (path )
289
+ path = addTempSuffixToPath (path )
270
290
271
291
old , err := os .Open (path )
272
292
if err != nil {
0 commit comments