fix: wire new instance action
This commit is contained in:
+65
-5
@@ -14,6 +14,7 @@ type page uint8
|
||||
const (
|
||||
pageInstances page = iota
|
||||
pageSettings
|
||||
pageCreate
|
||||
)
|
||||
|
||||
// InstanceRow is the read-only view model used by the first Gio shell.
|
||||
@@ -43,14 +44,22 @@ type Shell struct {
|
||||
settingsClick widget.Clickable
|
||||
newClick widget.Clickable
|
||||
startClick widget.Clickable
|
||||
createClick widget.Clickable
|
||||
backClick widget.Clickable
|
||||
chromeKind widget.Clickable
|
||||
edgeKind widget.Clickable
|
||||
saveClick widget.Clickable
|
||||
cancelClick widget.Clickable
|
||||
|
||||
chromePath widget.Editor
|
||||
edgePath widget.Editor
|
||||
dataDir widget.Editor
|
||||
logDir widget.Editor
|
||||
closeOnExit widget.Bool
|
||||
chromePath widget.Editor
|
||||
edgePath widget.Editor
|
||||
dataDir widget.Editor
|
||||
logDir widget.Editor
|
||||
closeOnExit widget.Bool
|
||||
instanceName widget.Editor
|
||||
instanceDir widget.Editor
|
||||
instanceURL widget.Editor
|
||||
newBrowser string
|
||||
|
||||
list widget.List
|
||||
rows []InstanceRow
|
||||
@@ -69,6 +78,7 @@ func NewShell(theme *material.Theme) *Shell {
|
||||
s.dataDir.SetText(`C:\Users\Public\chub\profiles`)
|
||||
s.logDir.SetText(`C:\Users\Public\chub\logs`)
|
||||
s.closeOnExit.Value = true
|
||||
s.newBrowser = "Chrome"
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -96,6 +106,18 @@ func (s *Shell) Layout(gtx layout.Context) layout.Dimensions {
|
||||
for s.settingsClick.Clicked(gtx) {
|
||||
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,
|
||||
layout.Rigid(s.header),
|
||||
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 {
|
||||
return s.settings(gtx)
|
||||
}
|
||||
if s.page == pageCreate {
|
||||
return s.createInstance(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() {
|
||||
s.chromePath.SetText(`C:\Program Files\Google\Chrome\Application\chrome.exe`)
|
||||
s.edgePath.SetText(`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`)
|
||||
|
||||
Reference in New Issue
Block a user