don't bookstrap the newwindow layout for the first run

This commit is contained in:
sawka 2024-09-17 00:00:20 -07:00
parent 46eb164778
commit d94a4bc666
2 changed files with 15 additions and 10 deletions

View File

@ -229,7 +229,7 @@ func main() {
log.Printf("error initializing wsh and shell-integration files: %v\n", err)
}
}()
window, err := wcore.EnsureInitialData()
window, firstRun, err := wcore.EnsureInitialData()
if err != nil {
log.Printf("error ensuring initial data: %v\n", err)
return
@ -237,10 +237,12 @@ func main() {
if window != nil {
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFn()
err = wlayout.BootstrapNewWindowLayout(ctx, window)
if err != nil {
log.Panicf("error applying new window layout: %v\n", err)
return
if !firstRun {
err = wlayout.BootstrapNewWindowLayout(ctx, window)
if err != nil {
log.Panicf("error applying new window layout: %v\n", err)
return
}
}
}
createMainWshClient()

View File

@ -135,25 +135,28 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Windo
return wstore.DBMustGet[*waveobj.Window](ctx, windowId)
}
func EnsureInitialData() (*waveobj.Window, error) {
// returns (new-window, first-time, error)
func EnsureInitialData() (*waveobj.Window, bool, error) {
// does not need to run in a transaction since it is called on startup
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFn()
firstRun := false
client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
if err == wstore.ErrNotFound {
client, err = CreateClient(ctx)
if err != nil {
return nil, fmt.Errorf("error creating client: %w", err)
return nil, false, fmt.Errorf("error creating client: %w", err)
}
firstRun = true
}
if len(client.WindowIds) > 0 {
return nil, nil
return nil, false, nil
}
window, err := CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0})
if err != nil {
return nil, fmt.Errorf("error creating window: %w", err)
return nil, false, fmt.Errorf("error creating window: %w", err)
}
return window, nil
return window, firstRun, nil
}
func CreateClient(ctx context.Context) (*waveobj.Client, error) {