diff --git a/flake.nix b/flake.nix index bbe2ec2..e0a1f95 100644 --- a/flake.nix +++ b/flake.nix @@ -16,11 +16,11 @@ in { xintray = pkgs.buildGoModule { pname = "xintray"; - version = "v0.1.5"; + version = "v0.1.6"; src = ./.; vendorSha256 = - "sha256-j/dpn2+a88ZzTXnQy3QpyTby37skQwkK4NG+aBeLeyc="; + "sha256-MKMAV5UNB6bl6/qe7Xb9+OIczfoPrXeHVqcDIaKDHms="; proxyVendor = true; nativeBuildInputs = with pkgs; [ pkg-config ]; diff --git a/go.mod b/go.mod index f1a67ac..2c5ec24 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module suah.dev/xintray go 1.17 require ( - fyne.io/fyne/v2 v2.3.0 - golang.org/x/crypto v0.5.0 + fyne.io/fyne/v2 v2.3.1 + golang.org/x/crypto v0.6.0 ) require ( - fyne.io/systray v1.10.1-0.20221115204952-d16a6177e6f1 // indirect + fyne.io/systray v1.10.1-0.20230207085535-4a244dbb9d03 // indirect github.com/benoitkugler/textlayout v0.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fredbi/uri v1.0.0 // indirect @@ -31,9 +31,9 @@ require ( github.com/yuin/goldmark v1.5.3 // indirect golang.org/x/image v0.3.0 // indirect golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect - golang.org/x/net v0.5.0 // indirect - golang.org/x/sys v0.4.0 // indirect - golang.org/x/text v0.6.0 // indirect + golang.org/x/net v0.6.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect honnef.co/go/js/dom v0.0.0-20221001195520-26252dedbe70 // indirect ) diff --git a/go.sum b/go.sum index a4952c0..38177cc 100644 --- a/go.sum +++ b/go.sum @@ -37,10 +37,10 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -fyne.io/fyne/v2 v2.3.0 h1:g9tPI3lyBK50IvyPbXqv2zI3JJ4uhMAffu89f3nX5PU= -fyne.io/fyne/v2 v2.3.0/go.mod h1:odfJmbFnODiKn1MXdL44JR6CK+0v8lrmgdPlrUF6w0M= -fyne.io/systray v1.10.1-0.20221115204952-d16a6177e6f1 h1:OiHw+bZAGEaSreHsA8dDkBOVJmSFzsNTOc/htpM+fOc= -fyne.io/systray v1.10.1-0.20221115204952-d16a6177e6f1/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE= +fyne.io/fyne/v2 v2.3.1 h1:2/dHeRXEpn/D4MyTHdK43g3/pxeLOi3FcdNJI+iphlM= +fyne.io/fyne/v2 v2.3.1/go.mod h1:dl/M+f0r5lJRhy+gdPbmYy97tbu3SWF/RF6/9KXMs+s= +fyne.io/systray v1.10.1-0.20230207085535-4a244dbb9d03 h1:zb84y6X6lIi4Aeo8ehu6Qtu2fipBZ6Wzp41Ki/F4qdg= +fyne.io/systray v1.10.1-0.20230207085535-4a244dbb9d03/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -325,8 +325,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -413,8 +413,8 @@ golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -491,12 +491,12 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -506,8 +506,9 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/main.go b/main.go index 3a33b75..9a5694e 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,11 @@ package main import ( "bytes" "encoding/json" + "encoding/xml" "fmt" "io/ioutil" "log" + "net/http" "os" "os/exec" "path" @@ -61,6 +63,7 @@ type Config struct { Statuses []*Status `json:"statuses"` Repo string `json:"repo"` PrivKeyPath string `json:"priv_key_path"` + FlakeRSS string `json:"flake_rss"` } func (c *commit) getInfo(repo string) error { @@ -143,18 +146,34 @@ func (x *xinStatus) getCommit(c string) (*commit, error) { } func (x *xinStatus) updateRepoInfo() error { - revCmd := exec.Command("git", "rev-parse", "HEAD") - revCmd.Dir = x.config.Repo - currentRev, err := revCmd.Output() - if err != nil { - return err - } + switch { + case (x.config.Repo != "" && x.config.FlakeRSS == ""): + revCmd := exec.Command("git", "rev-parse", "HEAD") + revCmd.Dir = x.config.Repo + currentRev, err := revCmd.Output() + if err != nil { + return err + } - commit, err := x.getCommit(trim(currentRev)) - if err != nil { - return err + commit, err := x.getCommit(trim(currentRev)) + if err != nil { + return err + } + x.repoCommit = *commit + default: + resp := &Feed{} + res, err := http.Get(x.config.FlakeRSS) + if err != nil { + return err + } + + defer res.Body.Close() + + if err = xml.NewDecoder(res.Body).Decode(&resp); err != nil { + return err + } + x.repoCommit = resp.LatestHash() } - x.repoCommit = *commit return nil } diff --git a/rss.go b/rss.go new file mode 100644 index 0000000..cb5242a --- /dev/null +++ b/rss.go @@ -0,0 +1,61 @@ +package main + +import ( + "encoding/xml" + "html" + "strings" + "time" +) + +type Feed struct { + XMLName xml.Name `xml:"feed"` + Text string `xml:",chardata"` + Xmlns string `xml:"xmlns,attr"` + Media string `xml:"media,attr"` + Lang string `xml:"lang,attr"` + ID string `xml:"id"` + Link []struct { + Text string `xml:",chardata"` + Type string `xml:"type,attr"` + Rel string `xml:"rel,attr"` + Href string `xml:"href,attr"` + } `xml:"link"` + Title string `xml:"title"` + Updated time.Time `xml:"updated"` + Entry []struct { + Text string `xml:",chardata"` + ID string `xml:"id"` + Link struct { + Text string `xml:",chardata"` + Type string `xml:"type,attr"` + Rel string `xml:"rel,attr"` + Href string `xml:"href,attr"` + } `xml:"link"` + Title string `xml:"title"` + Updated time.Time `xml:"updated"` + Thumbnail struct { + Text string `xml:",chardata"` + Height string `xml:"height,attr"` + Width string `xml:"width,attr"` + URL string `xml:"url,attr"` + } `xml:"thumbnail"` + Author struct { + Text string `xml:",chardata"` + Name string `xml:"name"` + URI string `xml:"uri"` + } `xml:"author"` + Content struct { + Text string `xml:",chardata"` + Type string `xml:"type,attr"` + } `xml:"content"` + } `xml:"entry"` +} + +func (f *Feed) LatestHash() commit { + return commit{ + hash: strings.Split(f.Entry[0].ID, "/")[1], + // TODO: use x/html to pull out the info? + message: html.UnescapeString(f.Entry[0].Content.Text), + date: f.Entry[0].Updated, + } +}