fix: wire new instance action

This commit is contained in:
QiuSW
2026-07-22 15:24:25 +08:00
parent 63215bd181
commit f442fdc8df
+65 -5
View File
@@ -14,6 +14,7 @@ type page uint8
const ( const (
pageInstances page = iota pageInstances page = iota
pageSettings pageSettings
pageCreate
) )
// InstanceRow is the read-only view model used by the first Gio shell. // InstanceRow is the read-only view model used by the first Gio shell.
@@ -43,14 +44,22 @@ type Shell struct {
settingsClick widget.Clickable settingsClick widget.Clickable
newClick widget.Clickable newClick widget.Clickable
startClick widget.Clickable startClick widget.Clickable
createClick widget.Clickable
backClick widget.Clickable
chromeKind widget.Clickable
edgeKind widget.Clickable
saveClick widget.Clickable saveClick widget.Clickable
cancelClick widget.Clickable cancelClick widget.Clickable
chromePath widget.Editor chromePath widget.Editor
edgePath widget.Editor edgePath widget.Editor
dataDir widget.Editor dataDir widget.Editor
logDir widget.Editor logDir widget.Editor
closeOnExit widget.Bool closeOnExit widget.Bool
instanceName widget.Editor
instanceDir widget.Editor
instanceURL widget.Editor
newBrowser string
list widget.List list widget.List
rows []InstanceRow rows []InstanceRow
@@ -69,6 +78,7 @@ func NewShell(theme *material.Theme) *Shell {
s.dataDir.SetText(`C:\Users\Public\chub\profiles`) s.dataDir.SetText(`C:\Users\Public\chub\profiles`)
s.logDir.SetText(`C:\Users\Public\chub\logs`) s.logDir.SetText(`C:\Users\Public\chub\logs`)
s.closeOnExit.Value = true s.closeOnExit.Value = true
s.newBrowser = "Chrome"
return s return s
} }
@@ -96,6 +106,18 @@ func (s *Shell) Layout(gtx layout.Context) layout.Dimensions {
for s.settingsClick.Clicked(gtx) { for s.settingsClick.Clicked(gtx) {
s.page = pageSettings s.page = pageSettings
} }
for s.newClick.Clicked(gtx) {
s.page = pageCreate
}
for s.createClick.Clicked(gtx) {
if name := s.instanceName.Text(); name != "" {
s.rows = append(s.rows, InstanceRow{Name: name, Browser: s.newBrowser, Profile: "Default", Status: "已退出"})
s.page = pageInstances
}
}
for s.backClick.Clicked(gtx) {
s.page = pageInstances
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(s.header), layout.Rigid(s.header),
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions { layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
@@ -119,6 +141,9 @@ func (s *Shell) content(gtx layout.Context) layout.Dimensions {
if s.page == pageSettings { if s.page == pageSettings {
return s.settings(gtx) return s.settings(gtx)
} }
if s.page == pageCreate {
return s.createInstance(gtx)
}
return s.instances(gtx) return s.instances(gtx)
} }
@@ -194,6 +219,41 @@ func (s *Shell) settings(gtx layout.Context) layout.Dimensions {
) )
} }
func (s *Shell) createInstance(gtx layout.Context) layout.Dimensions {
for s.chromeKind.Clicked(gtx) {
s.newBrowser = "Chrome"
}
for s.edgeKind.Clicked(gtx) {
s.newBrowser = "Edge"
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(material.H4(s.theme, "新建实例").Layout),
layout.Rigid(material.Body1(s.theme, "为一个独立的 Chrome 或 Edge User Data Dir 创建托管实例").Layout),
layout.Rigid(layout.Spacer{Height: unit.Dp(18)}.Layout),
layout.Rigid(material.Editor(s.theme, &s.instanceName, "实例名称").Layout),
layout.Rigid(layout.Spacer{Height: unit.Dp(10)}.Layout),
layout.Rigid(material.Editor(s.theme, &s.instanceDir, "User Data Dir(绝对路径)").Layout),
layout.Rigid(layout.Spacer{Height: unit.Dp(10)}.Layout),
layout.Rigid(material.Editor(s.theme, &s.instanceURL, "启动 URL(可选)").Layout),
layout.Rigid(layout.Spacer{Height: unit.Dp(14)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(material.Button(s.theme, &s.chromeKind, "Chrome").Layout),
layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout),
layout.Rigid(material.Button(s.theme, &s.edgeKind, "Edge").Layout),
)
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(18)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(material.Button(s.theme, &s.createClick, "创建实例").Layout),
layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout),
layout.Rigid(material.Button(s.theme, &s.backClick, "取消").Layout),
)
}),
)
}
func (s *Shell) resetSettings() { func (s *Shell) resetSettings() {
s.chromePath.SetText(`C:\Program Files\Google\Chrome\Application\chrome.exe`) s.chromePath.SetText(`C:\Program Files\Google\Chrome\Application\chrome.exe`)
s.edgePath.SetText(`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`) s.edgePath.SetText(`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`)