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

View File

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