1 Star 1 Fork 0

归位/goscrcpy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 3.39 KB
一键复制 编辑 原始数据 按行查看 历史
jicg 提交于 2024-07-20 22:08 +08:00 . 升级scrcpy,使用wails3
package main
import (
"embed"
"fmt"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
"html/template"
"log"
)
//go:embed frontend/dist
var assets embed.FS
//go:embed build/icon.png
var icon []byte
//go:embed build/list.html
var listHtml string
var appServer = &AppServer{}
var listTpl, _ = template.New("list").Parse(listHtml)
func main() {
app := application.New(application.Options{
Icon: icon,
Name: "goscrcpy",
Assets: application.AssetOptions{
FS: assets,
Handler: &FileLoader{},
},
Bind: []any{
appServer,
},
Windows: application.WindowsOptions{
WndProcInterceptor: nil,
DisableQuitOnLastWindowClosed: false,
WebviewUserDataPath: "./data",
WebviewBrowserPath: "",
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
app.Events.On("selectDevice", func(event *application.WailsEvent) {
appServer.closeList()
err := appServer.ConnPhoneHelpWithDeviceName(fmt.Sprintf("%v", event.Data), appServer.Data.IsTop, appServer.Data.IsAwake)
if err != nil {
_, _ = appServer.Msg("错误", err.Error())
}
})
app.On(events.Common.ApplicationStarted, func(event *application.Event) {
mainWindow := createMainWindow(app)
appServer.init(app, mainWindow)
createTrayMenu(app).AttachWindow(appServer.mainWindow).WindowOffset(5)
})
err := app.Run()
if err != nil {
println("Error:", err.Error())
}
}
func createMainWindow(app *application.App) *application.WebviewWindow {
mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Frameless: true, DevToolsEnabled: true,
DisableResize: true,
AlwaysOnTop: true, Centered: true,
BackgroundColour: application.RGBA{Red: 27, Green: 38, Blue: 54, Alpha: 1},
})
mainWindow.On(events.Common.WindowClosing, func(event *application.WindowEvent) {
fmt.Println("WindowClosing")
appServer.onClose()
})
screen2, _ := app.CurrentWindow().GetScreen()
winW := 360 //int(float32(180) * screen2.Scale)
winH := 120 //int(float32(60) * screen2.Scale)
winRealW := int(float32(winW) * screen2.Scale)
winRealH := int(float32(winH) * screen2.Scale)
mainWindow.SetSize(winW, winH)
mainWindow.SetAbsolutePosition(screen2.Bounds.X+screen2.WorkArea.Width-winRealW, screen2.WorkArea.Height-winRealH)
log.Println("screen :", screen2.Name, screen2.ID, screen2.Size, screen2.Bounds, screen2.WorkArea, screen2.Scale)
var x, y = mainWindow.AbsolutePosition()
log.Println("wins :", screen2.WorkArea.Width-winRealW, screen2.WorkArea.Height-winRealH, x, y)
return mainWindow
}
func createTrayMenu(app *application.App) *application.SystemTray {
systemTray := app.NewSystemTray()
systemTray.SetTemplateIcon(icon)
systemTray.SetIcon(icon).SetLabel("goscrcpy")
var doShow = func() {
if appServer.mainWindow == nil || appServer.mainWindow.IsVisible() {
return
}
appServer.mainWindow.Show()
}
myMenu := app.NewMenu()
//myMenu.Add("goscrcpy").SetBitmap(icons.WailsLogoBlackTransparent).SetEnabled(false)
myMenu.Add("连接设备").OnClick(func(ctx *application.Context) {
appServer.ConnPhoneWithSelect()
})
myMenu.Add("显示").OnClick(func(ctx *application.Context) {
doShow()
})
myMenu.AddSeparator()
myMenu.Add("退出").OnClick(func(ctx *application.Context) {
if appServer.mainWindow != nil {
appServer.mainWindow.Close()
}
app.Quit()
})
systemTray.SetMenu(myMenu)
return systemTray
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jicg/goscrcpy.git
git@gitee.com:jicg/goscrcpy.git
jicg
goscrcpy
goscrcpy
main

搜索帮助