Skip to content

Commit

Permalink
fix: desktop viewer dialog problem
Browse files Browse the repository at this point in the history
  • Loading branch information
XZB-1248 committed Oct 15, 2022
1 parent 52c4b8f commit 9236026
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion client/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func uploadFiles(pack modules.Packet, wsConn *common.Conn) {
}
}
if end > 0 && end < start {
wsConn.SendCallback(modules.Packet{Code: 1, Msg: `${i18n|invalidFileRange}`}, pack)
wsConn.SendCallback(modules.Packet{Code: 1, Msg: `${i18n|COMMON.INVALID_PARAMETER}`}, pack)
return
}
}
Expand Down
52 changes: 28 additions & 24 deletions client/service/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type session struct {
lock *sync.Mutex
}
type message struct {
t int
info string
data *[]*[]byte
t int
info string
frame *[]*[]byte
}

// +---------+---------+----------+----------+------------+---------+---------+---------+---------+-------+
Expand Down Expand Up @@ -62,7 +62,8 @@ var lock = &sync.Mutex{}
var working = false
var sessions = cmap.New()
var prevDesktop *image.RGBA
var ErrNoImage = errors.New(`no image yet`)
var displayBounds image.Rectangle
var ErrNoImage = errors.New(`DESKTOP.NO_IMAGE_YET`)

func init() {
go healthCheck()
Expand All @@ -73,18 +74,18 @@ func worker() {
lock.Lock()
if working {
lock.Unlock()
runtime.UnlockOSThread()
return
}
working = true
lock.Unlock()

var (
screen screen
bounds image.Rectangle
img *image.RGBA
err error
errors int
)
bounds = screenshot.GetDisplayBounds(displayIndex)
screen.init(displayIndex)
for working {
if sessions.Count() == 0 {
Expand All @@ -93,8 +94,8 @@ func worker() {
lock.Unlock()
break
}
img = image.NewRGBA(bounds)
err = screen.capture(img, bounds)
img = image.NewRGBA(displayBounds)
err = screen.capture(img, displayBounds)
if err != nil {
if err == ErrNoImage {
return
Expand All @@ -112,7 +113,7 @@ func worker() {
desktop := t.(*session)
desktop.lock.Lock()
if !desktop.escape {
desktop.channel <- message{t: 0, data: &diff}
desktop.channel <- message{t: 0, frame: &diff}
}
desktop.lock.Unlock()
return true
Expand Down Expand Up @@ -306,22 +307,15 @@ func InitDesktop(pack modules.Packet) error {
lock: &sync.Mutex{},
}
{
var rect image.Rectangle
displayBounds = screenshot.GetDisplayBounds(displayIndex)
if screenshot.NumActiveDisplays() == 0 {
rect = screenshot.GetDisplayBounds(0)
if rect.Dx() == 0 || rect.Dy() == 0 {
if displayBounds.Dx() == 0 || displayBounds.Dy() == 0 {
close(desktop.channel)
common.WSConn.SendCallback(modules.Packet{Act: `quitDesktop`, Msg: `${i18n|DESKTOP.NO_DISPLAY_FOUND}`}, pack)
return errors.New(`${i18n|DESKTOP.NO_DISPLAY_FOUND}`)
}
} else {
rect = screenshot.GetDisplayBounds(0)
}
buf := append([]byte{34, 22, 19, 17, 20, 02}, rawEvent...)
data := make([]byte, 4)
binary.BigEndian.PutUint16(data[:2], uint16(rect.Dx()))
binary.BigEndian.PutUint16(data[2:], uint16(rect.Dy()))
buf = append(buf, data...)
common.WSConn.SendData(buf)
desktop.channel <- message{t: 2}
}
go handleDesktop(pack, uuid, desktop)
if !working {
Expand All @@ -330,7 +324,7 @@ func InitDesktop(pack modules.Packet) error {
} else {
img := splitFullImage(prevDesktop, compress)
desktop.lock.Lock()
desktop.channel <- message{t: 0, data: &img}
desktop.channel <- message{t: 0, frame: &img}
desktop.lock.Unlock()
sessions.Set(uuid, desktop)
}
Expand Down Expand Up @@ -371,7 +365,7 @@ func KillDesktop(pack modules.Packet) {
desktop.escape = true
desktop.rawEvent = nil
desktop.lock.Unlock()
common.WSConn.SendCallback(modules.Packet{Act: `quitDesktop`, Msg: `${i18n|desktopClosed}`}, pack)
common.WSConn.SendCallback(modules.Packet{Act: `quitDesktop`, Msg: `${i18n|DESKTOP.SESSION_CLOSED}`}, pack)
}

func GetDesktop(pack modules.Packet) {
Expand All @@ -392,7 +386,7 @@ func GetDesktop(pack modules.Packet) {
img := splitFullImage(prevDesktop, compress)
lock.Unlock()
desktop.lock.Lock()
desktop.channel <- message{t: 0, data: &img}
desktop.channel <- message{t: 0, frame: &img}
desktop.lock.Unlock()
}
}
Expand All @@ -411,7 +405,7 @@ func handleDesktop(pack modules.Packet, uuid string, desktop *session) {
// send image
if msg.t == 0 {
buf := append([]byte{34, 22, 19, 17, 20, 00}, desktop.rawEvent...)
for _, slice := range *msg.data {
for _, slice := range *msg.frame {
if len(buf)+len(*slice) >= common.MaxMessageSize {
if common.WSConn.SendData(buf) != nil {
break
Expand All @@ -424,6 +418,16 @@ func handleDesktop(pack modules.Packet, uuid string, desktop *session) {
buf = nil
continue
}
// set resolution
if msg.t == 2 {
buf := append([]byte{34, 22, 19, 17, 20, 02}, desktop.rawEvent...)
data := make([]byte, 4)
binary.BigEndian.PutUint16(data[:2], uint16(displayBounds.Dx()))
binary.BigEndian.PutUint16(data[2:], uint16(displayBounds.Dy()))
buf = append(buf, data...)
common.WSConn.SendData(buf)
break
}
case <-time.After(time.Second * 5):
default:
time.Sleep(50 * time.Millisecond)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.18
require (
github.com/creack/pty v1.1.18
github.com/denisbrodbeck/machineid v1.0.1
github.com/gin-contrib/pprof v1.3.0
github.com/gin-gonic/gin v1.7.7
github.com/gorilla/websocket v1.5.0
github.com/imroc/req/v3 v3.8.2
Expand All @@ -16,7 +15,7 @@ require (
github.com/shirou/gopsutil/v3 v3.22.2
)

require github.com/kirides/screencapture v0.0.0-20211101142135-282f3f7e0f33 // indirect
require github.com/kirides/screencapture v0.0.0-20211101142135-282f3f7e0f33

require (
github.com/gen2brain/shm v0.0.0-20210511105953-083dbc7d9d83 // indirect
Expand Down Expand Up @@ -44,6 +43,6 @@ require (
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
golang.org/x/text v0.3.7
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
7 changes: 1 addition & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 h1:Y5Q2mEwfzjMt5+3u70Gtw93ZOu2UuPeeeTBDntF7FoY=
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5/go.mod h1:uF6rMu/1nvu+5DpiRLwusA6xB8zlkNoGzKn8lmYONUo=
github.com/gen2brain/shm v0.0.0-20210511105953-083dbc7d9d83 h1:fRNwUddc/xxdx5kQ38X4+q/Grnqlp9zfV/ssKzSzVk0=
github.com/gen2brain/shm v0.0.0-20210511105953-083dbc7d9d83/go.mod h1:uF6rMu/1nvu+5DpiRLwusA6xB8zlkNoGzKn8lmYONUo=
github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0=
github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
Expand All @@ -23,7 +20,6 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
Expand Down Expand Up @@ -84,7 +80,6 @@ github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
Expand Down
5 changes: 1 addition & 4 deletions web/src/components/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ function ScreenModal(props) {
if (op === 2) {
let width = dv.getUint16(1, false);
let height = dv.getUint16(3, false);
if (width === 0 || height === 0) {
message.warn(i18n.t('DESKTOP.NO_DISPLAY_FOUND'));
return;
}
if (width === 0 || height === 0) return;
canvas.width = width;
canvas.height = height;
return;
Expand Down

0 comments on commit 9236026

Please sign in to comment.