@@ -5,21 +5,15 @@ import (
55 "io"
66 "net"
77 "net/http"
8- "runtime"
98 "time"
109
11- "github.com/blang/semver/v4"
1210 "github.com/loophole/cli/config"
1311 lm "github.com/loophole/cli/internal/app/loophole/models"
1412 "github.com/loophole/cli/internal/pkg/apiclient"
1513 "github.com/loophole/cli/internal/pkg/communication"
1614 "github.com/loophole/cli/internal/pkg/httpserver"
1715 "github.com/loophole/cli/internal/pkg/keys"
1816 "github.com/loophole/cli/internal/pkg/urlmaker"
19- "github.com/mitchellh/go-homedir"
20- "github.com/ncruces/zenity"
21- "github.com/pkg/browser"
22- "github.com/spf13/viper"
2317 "golang.org/x/crypto/ssh"
2418)
2519
@@ -41,92 +35,6 @@ var remoteEndpoint = lm.Endpoint{
4135 Port : 80 ,
4236}
4337
44- func CheckVersion () {
45- availableVersion , err := apiclient .GetLatestAvailableVersion ()
46- if err != nil {
47- communication .Debug ("There was a problem obtaining info response, skipping further checking" )
48- return
49- }
50- currentVersionParsed , err := semver .Make (config .Config .Version )
51- if err != nil {
52- communication .Debug (fmt .Sprintf ("Cannot parse current version '%s' as semver version, skipping further checking" , config .Config .Version ))
53- return
54- }
55- availableVersionParsed , err := semver .Make (availableVersion .Version )
56- if err != nil {
57- communication .Debug (fmt .Sprintf ("Cannot parse available version '%s' as semver version, skipping further checking" , availableVersion ))
58- return
59- }
60- if currentVersionParsed .LT (availableVersionParsed ) {
61- if config .Config .ClientMode == "cli" {
62- communication .NewVersionAvailable (availableVersion .Version )
63- } else {
64- remind , _ := remindAgainCheck ()
65- if ! remind {
66- return
67- }
68- dlLink := getDownloadLink (availableVersion .Version )
69- response , _ := zenity .Question (fmt .Sprintf ("A new version is available for you at \n %s \n Do you want to open the link in your browser now?" , dlLink ), zenity .NoWrap (), zenity .Title ("New version available!" ))
70- if response {
71- browser .OpenURL (dlLink )
72- }
73- }
74- }
75- }
76-
77- func getDownloadLink (availableVersion string ) string {
78- archiveExt := ".tar.gz"
79- arch := runtime .GOARCH
80- if arch == "windows" {
81- archiveExt = ".zip"
82- } else if arch == "darwin" {
83- arch = "macos"
84- }
85- if arch == "amd64" {
86- arch = "64bit"
87- } else if arch == "386" {
88- arch = "32bit"
89- } else {
90- communication .Error ("There was an error detecting your system architecture." ) //if arch is unexpected, only link to the release page
91- return fmt .Sprintf ("https://github.com/loophole/cli/releases/tag/%s" , availableVersion )
92- }
93- res := fmt .Sprintf ("https://github.com/loophole/cli/releases/download/%s/loophole-desktop_%s_%s_%s%s" , availableVersion , availableVersion , runtime .GOOS , arch , archiveExt )
94- fmt .Println (res )
95- return res
96- }
97-
98- func remindAgainCheck () (bool , error ) { //TODO: Error handling, moving this function to a more appropriate file (probably to config pkg)
99- home , err := homedir .Dir ()
100- if err != nil {
101- return true , err
102- }
103-
104- layout := "2006-02-01" //golangs arcane time format string
105- viper .SetDefault ("last-reminder" , time.Time {}.Format (layout )) //zero value for time
106- viper .SetConfigName ("config" ) // name of config file (without extension)
107- viper .SetConfigType ("json" ) // REQUIRED if the config file does not have the extension in the name
108- viper .AddConfigPath (fmt .Sprintf ("%s/.loophole/" , home ))
109- if err := viper .ReadInConfig (); err != nil {
110- if _ , ok := err .(viper.ConfigFileNotFoundError ); ok { //create a config if none exist yet
111- viper .WriteConfigAs (fmt .Sprintf ("%s/.loophole/config.json" , home ))
112- } else {
113- return true , err
114- }
115- }
116-
117- t , err := time .Parse (layout , fmt .Sprintf ("%v" , viper .Get ("last-reminder" )))
118- if err != nil {
119- return true , err
120- }
121- if (t .Year () < time .Now ().Year ()) || (t .YearDay () < time .Now ().YearDay ()) { //check if reminder has been done today
122- viper .Set ("last-reminder" , time .Now ().Format (layout ))
123- viper .WriteConfigAs ("/home/work/.loophole/config.json" )
124- return true , nil
125- }
126-
127- return false , nil
128- }
129-
13038func handleClient (tunnelID string , client net.Conn , local net.Conn ) {
13139 defer client .Close ()
13240 chDone := make (chan bool )
0 commit comments