]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
修复致命错误SIGSEGV
authorqydysky <qydysky@foxmail.com>
Fri, 23 Oct 2020 07:00:35 +0000 (15:00 +0800)
committerqydysky <qydysky@foxmail.com>
Fri, 23 Oct 2020 07:00:35 +0000 (15:00 +0800)
Reply/F.go
Reply/gtk.go
demo/config_F.json
demo/go.mod
demo/go.sum

index 1618aee0702eaa9d8f50f5821f76f09a01f02788..23f551493e0b5fca787adf9f7bdf8d38dd534388 100644 (file)
@@ -33,7 +33,7 @@ var AllF = map[string]bool{
                obs https://obsproject.com/download
                obs-websocket https://github.com/Palakis/obs-websocket/releases
        */
-       "Autoban":true,//自动封禁(仅提示,未完成)
+       "Autoban":false,//自动封禁(仅提示,未完成)
        "Jiezou":true,//带节奏预警,提示弹幕礼仪
        "Danmuji":true,//反射型弹幕机,回应弹幕
        "Danmuji_auto":false,//自动型弹幕机,定时输出
@@ -154,7 +154,7 @@ var qtd = Qtd {
 
 func Qtdf(){
        if !IsOn("Qtd") {return}
-       go Qtdanmu()
+       Qtdanmu()
 }
 
 //Ass 弹幕转字幕
index 263d5082d6f65c60f3242730550da93183caa646..defea9cada2f22696e34bb8cef2af4fe1037e55a 100644 (file)
@@ -13,136 +13,181 @@ import (
 )
 
 const appId = "com.github.qydysky.bili_danmu.reply"
-var BTList = list.New()
-var BIList = list.New()
+type gtk_list struct {
+       text *gtk.TextView
+       img *gtk.Image
+       handle glib.SignalHandle
+}
+
+type gtk_get struct {
+       src string
+       uid string
+}
+var gtkGetList = list.New()
 
+var imgbuf = make(map[string](*gdk.Pixbuf))
 var (
        Gtk_on bool
        Gtk_Tra bool
        Gtk_img_path string = "face"
-       Gtk_danmuChan chan string = make(chan string, 100)
-       Gtk_danmuChan_uid chan string = make(chan string, 100)
+       Gtk_danmuChan chan string = make(chan string, 1000)
+       Gtk_danmuChan_uid chan string = make(chan string, 1000)
 )
 
 func Gtk_danmu() {
        if Gtk_on {return}
 
+       var y func(string,string)
+       var win *gtk.Window
+       var scrolledwindow0 *gtk.ScrolledWindow
+       var viewport0 *gtk.Viewport
+
        application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
-       if err != nil {return}
+       if err != nil {log.Println(err);return}
 
        application.Connect("startup", func() {
                log.Println("application startup")      
+               var grid0 *gtk.Grid;
 
                builder, err := gtk.BuilderNewFromFile("ui/1.glade")
-               if err != nil {return}
+               if err != nil {log.Println(err);return}
 
-               signals := map[string]interface{}{
-                       "on_main_window_destroy": onMainWindowDestroy,
+               {
+                       signals := map[string]interface{}{
+                               "on_main_window_destroy": onMainWindowDestroy,
+                       }
+                       builder.ConnectSignals(signals)
+               }
+               {
+                       obj, err := builder.GetObject("main_window")
+                       if err != nil {log.Println(err);return}
+                       win, err = isWindow(obj)
+                       if err != nil {log.Println(err);return}
+                       application.AddWindow(win)
+                       defer win.ShowAll()
                }
-               builder.ConnectSignals(signals)
-
-               obj, err := builder.GetObject("main_window")
-               if err != nil {return}
-
-
-
-               win, err := isWindow(obj)
-               if err != nil {return}
-
-               var scrolledwindow0 *gtk.ScrolledWindow
                {
                        obj, err := builder.GetObject("scrolledwindow0")
-                       if err != nil {return}
+                       if err != nil {log.Println(err);return}
                        if tmp,ok := obj.(*gtk.ScrolledWindow); ok {
                                scrolledwindow0 = tmp
-                       }
+                       }else{log.Println("cant find #scrolledwindow0 in .glade");return}
                }
 
-               var viewport0 *gtk.Viewport
                {
                        obj, err := builder.GetObject("viewport0")
-                       if err != nil {return}
+                       if err != nil {log.Println(err);return}
                        if tmp,ok := obj.(*gtk.Viewport); ok {
                                viewport0 = tmp
-                       }
+                       }else{log.Println("cant find #viewport0 in .glade");return}
                }
 
-               var grid0 *gtk.Grid;
                {
                        obj, err := builder.GetObject("grid0")
-                       if err != nil {return}
+                       if err != nil {log.Println(err);return}
                        if tmp,ok := obj.(*gtk.Grid); ok {
                                grid0 = tmp
-                       }
+                       }else{log.Println("cant find #grid0 in .glade");return}
                }
 
-               var y func(bool)
-               y = func(tra bool){
-                       Gtk_Tra = true
-                       
-                       s:=<-Gtk_danmuChan
-                       t,_ := gtk.TextViewNew();
-                       BTList.PushBack(t)
-                       t.SetMarginStart(5)
-                       t.SetEditable(false)
-                       t.SetHExpand(true)
-                       t.SetVExpand(false)
-                       t.SetWrapMode(gtk.WRAP_WORD_CHAR)
+               imgbuf["face/0default"],_ = gdk.PixbufNewFromFileAtSize("face/0default", 40, 40);
+
+               y = func(s,img_src string){
+                       var tmp_list gtk_list
+
+                       tmp_list.text,_ = gtk.TextViewNew();
+                       {
+                               tmp_list.text.SetMarginStart(5)
+                               tmp_list.text.SetEditable(false)
+                               tmp_list.text.SetHExpand(true)
+                               tmp_list.text.SetWrapMode(gtk.WRAP_WORD_CHAR)
+                       }
+                       {
+                               var e error
+                               tmp_list.handle,e = tmp_list.text.Connect("size-allocate", func(){
+
+                                       b,e := tmp_list.text.GetBuffer()
+                                       if e != nil {log.Println(e);return}
+                                       b.SetText(s)
+
+                                       {
+                                               var e error
+                                                       tmp := scrolledwindow0.GetVAdjustment()
+                                                       h := viewport0.GetViewWindow().WindowGetHeight()
+                                                       if tmp.GetUpper() - tmp.GetValue() < float64(h) * 1.3 {
+                                                               tmp.SetValue(tmp.GetUpper() - float64(h))
+                                                       }
+                                               if e != nil {log.Println(e)}
+                                       }
+                               })
+                               if e != nil {log.Println(e)}
+                       }
+
+                       tmp_list.img,_ =gtk.ImageNew();
+                       {
+                               var pixbuf *gdk.Pixbuf
+                               if v,ok := imgbuf[img_src];ok{
+                                       pixbuf,_ = gdk.PixbufCopy(v)
+                               } else {
+                                       pixbuf,_ = gdk.PixbufNewFromFileAtSize(img_src, 40, 40);
+                                       imgbuf[img_src],_ = gdk.PixbufCopy(pixbuf)
+                               }
+                               tmp_list.img.SetFromPixbuf(pixbuf)
+                       }
+                       {
+                               loc := int(grid0.Container.GetChildren().Length())/2;
+                               grid0.InsertRow(loc);
+                               grid0.Attach(tmp_list.img, 0, loc, 1, 1)
+                               grid0.Attach(tmp_list.text, 1, loc, 1, 1)
+
+                               for loc > 50 {
+
+                                       if i,e := grid0.GetChildAt(0,0); e != nil{i.(*gtk.Widget).Destroy()}
+                                       if i,e := grid0.GetChildAt(1,0); e != nil{i.(*gtk.Widget).Destroy()}
+                                       grid0.RemoveRow(0)
+                                       loc = int(grid0.Container.GetChildren().Length())/2;
+                               }
+                       }
                        
-                       img,_ :=gtk.ImageNew();
-                       BIList.PushBack(img)
-
-                       var handle glib.SignalHandle
-                       handle,_ = t.Connect("size-allocate", func(){
-                               Gtk_Tra = false
-                               b,e := t.GetBuffer()
-                               if e != nil {return}
-                               b.SetText(s)
-
-                               img_src := load_face(<-Gtk_danmuChan_uid)
-                               pixbuf,e := gdk.PixbufNewFromFileAtSize(img_src, 40, 40);
-                               if e != nil {return}
-                               img.SetFromPixbuf(pixbuf)
-                               t.HandlerDisconnect(handle)
-
-                               if tra {
-                                       handle,_ = t.Connect("size-allocate", func(){
-                                               tmp := scrolledwindow0.GetVAdjustment()
-                                               tmp.SetValue(tmp.GetUpper())
-                                               t.HandlerDisconnect(handle)
-                                       })
+                       glib.TimeoutAdd(uint(3000), func()(o bool){
+                               o = true
+
+                               if gtkGetList.Len() == 0 {return}
+                               el := gtkGetList.Front()
+                               if el == nil {return}
+                               if tmp_get,ok := gtkGetList.Remove(el).(gtk_get);ok{
+                                       req := p.Req()
+                                       if e := req.Reqf(p.Rval{
+                                               Url:tmp_get.src,
+                                               SaveToPath:Gtk_img_path + `/` + tmp_get.uid,
+                                               Timeout:3,
+                                       }); e != nil{log.Println(e);}
                                }
-                               if len(Gtk_danmuChan) != 0 {y(tra)}
+
+                               {
+                                       if len(imgbuf) > 100 {
+                                               for k,_ := range imgbuf {delete(imgbuf,k);break}
+                                       }
+                               }
+                               return
                        })
 
-                       tmp,_ := t.Container.Widget.Cast()
-                       loc := BTList.Len();
-                       grid0.InsertRow(loc);
-                       grid0.Attach(img, 0, loc - 1, 1, 1)
-                       grid0.Attach(tmp, 1, loc - 1, 1, 1)
-                       for tra && BTList.Len() > 50 {
-                               BTList.Remove(BTList.Front()).(*gtk.TextView).Destroy()
-                               BIList.Remove(BIList.Front()).(*gtk.Image).Destroy()
-                               grid0.RemoveRow(0)
-                       }
                        win.ShowAll()
                }
 
-               glib.TimeoutAdd(uint(100), func() bool {
-                       if !Gtk_Tra && len(Gtk_danmuChan) != 0 {
-                               tmp := scrolledwindow0.GetVAdjustment()
-                               h := viewport0.GetViewWindow().WindowGetHeight()
-                               y(tmp.GetUpper() - tmp.GetValue() < float64(h) * 1.3)
-                       }
-                       return true
-               })
-               win.Show()
-               application.AddWindow(win)
                Gtk_on = true
        })
 
        application.Connect("activate", func() {
                log.Println("application activate")
+               glib.TimeoutAdd(uint(300),func()(o bool){
+                       o = true
+                       for len(Gtk_danmuChan) != 0 {
+                               y(<-Gtk_danmuChan,load_face(<-Gtk_danmuChan_uid))
+                       }
+                       return
+               })
+
        })
 
        application.Connect("shutdown", func() {
@@ -164,17 +209,18 @@ func onMainWindowDestroy() {
        log.Println("onMainWindowDestroy")
 }
 
-func load_face(uid string) string {
-       defaultuid := "0default"
-       if uid != "" && p.Checkfile().IsExist(Gtk_img_path + `/` + uid) {return Gtk_img_path + `/` + uid}
+func load_face(uid string) (loc string) {
+       loc = Gtk_img_path + `/` + "0default"
+       if uid != "" && p.Checkfile().IsExist(Gtk_img_path + `/` + uid) && p.Rand().MixRandom(1,100) > 5 {
+               loc = Gtk_img_path + `/` + uid
+               return
+       }
        if src := F.Get_face_src(uid);src != "" {
-               req := p.Req()
-               if e := req.Reqf(p.Rval{
-                       Url:src,
-                       SaveToPath:Gtk_img_path + `/` + uid,
-                       Timeout:3,
-               }); e != nil{log.Println(e);return Gtk_img_path + `/` + defaultuid}
-               return Gtk_img_path + `/` + uid
+               if gtkGetList.Len() > 1000 {return}
+               gtkGetList.PushBack(gtk_get{
+                       src:src,
+                       uid:uid,
+               })
        }
-       return Gtk_img_path + `/` + defaultuid
+       return
 }
\ No newline at end of file
index fdcfe72a4b45dce2d7f0352f239d0bef47038052..944a7bceed1de00f90942d69c277f9d617991021 100644 (file)
@@ -1,10 +1,10 @@
 {
     "Gtk": true,
     "Qtd": false,
-    "Saveflv": true,
+    "Saveflv": false,
     "Ass": true,
     "Obs": false,
-    "Autoban": true,
+    "Autoban": false,
     "Jiezou": true,
     "Danmuji": true,
     "Danmuji_auto": false,
index 98c757e04cafaf02d337342ae33c04628ab89a9e..6514f700f1f7737e985161f7febe07c27a73d7d9 100644 (file)
@@ -9,7 +9,7 @@ require (
        github.com/klauspost/compress v1.11.1 // indirect
        github.com/mitchellh/mapstructure v1.3.3 // indirect
        github.com/qydysky/bili_danmu v0.0.0
-       github.com/qydysky/part v0.0.7 // indirect
+       github.com/qydysky/part v0.0.8 // indirect
        github.com/shirou/gopsutil v2.20.9+incompatible // indirect
        github.com/therecipe/env_darwin_amd64_513 v0.0.0-20190626001412-d8e92e8db4d0 // indirect
        github.com/therecipe/env_linux_amd64_513 v0.0.0-20190626000307-e137a3934da6 // indirect
index 2d828dcaef1f80847c72ef46c7d637b27b9e28d1..5edccbc0732b40195134b7d7d4abb5b7356b8e46 100644 (file)
@@ -86,6 +86,8 @@ github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0=
 github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/qydysky/part v0.0.7 h1:nT7Y5WIMvKv/AhW+AyQJ+RccMO5zAML9SZZyCeWZs24=
 github.com/qydysky/part v0.0.7/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
+github.com/qydysky/part v0.0.8 h1:W7icXUo22y1hewPev0u/H+DL+Ks0zP58HjrhVBaRgco=
+github.com/qydysky/part v0.0.8/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=
 github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=