forked from wxbool/video-srt-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.新增软件新版本提醒 3.优化程序异常提醒
- Loading branch information
Showing
9 changed files
with
268 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package app | ||
|
||
import ( | ||
"errors" | ||
"github.com/PuerkitoBio/goquery" | ||
"github.com/lxn/walk" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const ( | ||
VERSION_SOURCE string = "https://gitee.com/641453620/video-srt-windows/tags" | ||
) | ||
|
||
type AppVersion struct { | ||
|
||
} | ||
|
||
//根据码云查询新版本 | ||
func (v *AppVersion) GetVersion () (string , error) { | ||
|
||
timeout := time.Duration(2 * time.Second) | ||
client := &http.Client{ | ||
Timeout:timeout, | ||
} | ||
//获取版本来源html | ||
response, err := client.Get(VERSION_SOURCE) | ||
if err != nil { | ||
return "" , err | ||
} | ||
defer response.Body.Close() | ||
if response.StatusCode != 200 { | ||
return "" , errors.New("status code error : " + strconv.Itoa(response.StatusCode)) | ||
} | ||
|
||
//加载html | ||
html, err := goquery.NewDocumentFromReader(response.Body) | ||
if err != nil { | ||
return "" , err | ||
} | ||
|
||
//查找节点 | ||
vs := "" | ||
html.Find("#git-tags-container .releases-tags-wrap .releases-tag-content .tag-list .tag-item").Each(func(i int, s *goquery.Selection) { | ||
if vs != "" { | ||
return | ||
} | ||
tag , is := s.Find(".tag-name a").Attr("title") | ||
if is && tag != "" { | ||
vs = strings.TrimSpace(tag) | ||
} | ||
}) | ||
|
||
return vs,nil | ||
} | ||
|
||
|
||
//显示更新提醒 | ||
func (v *AppVersion) ShowVersionNotifyInfo (version string , own *MyMainWindow) error { | ||
mw, err := walk.NewMainWindow() | ||
if err != nil { | ||
return err | ||
} | ||
ni, err := walk.NewNotifyIcon(mw) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
time.Sleep(time.Second * 15) | ||
_ = ni.Dispose() | ||
}() | ||
|
||
if err := ni.SetVisible(true); err != nil { | ||
return err | ||
} | ||
if err := ni.ShowMessage("更新提醒" , "检测到VideoSrt的新版本(v"+version+"),请及时下载更新哦") ; err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.