mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
working on wsh createblock (wsh view). bug fix for emain closed windows (#64)
This commit is contained in:
parent
21fa9a601f
commit
0a19aa31d4
@ -41,7 +41,9 @@ var RpcClient *wshutil.WshRpc
|
||||
func doShutdown(reason string, exitCode int) {
|
||||
shutdownOnce.Do(func() {
|
||||
defer os.Exit(exitCode)
|
||||
if reason != "" {
|
||||
log.Printf("shutting down: %s\r\n", reason)
|
||||
}
|
||||
if usingHtmlMode {
|
||||
cmd := &wshutil.BlockSetMetaCommand{
|
||||
Command: wshutil.BlockCommand_SetMeta,
|
||||
@ -157,6 +159,7 @@ func resolveSimpleId(id string) (string, error) {
|
||||
|
||||
// Execute executes the root command.
|
||||
func Execute() error {
|
||||
defer doShutdown("", 0)
|
||||
setupRpcClient(nil)
|
||||
return rootCmd.Execute()
|
||||
}
|
61
cmd/wsh/cmd/wshcmd-view.go
Normal file
61
cmd/wsh/cmd/wshcmd-view.go
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wshutil"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
|
||||
var viewNewBlock bool
|
||||
|
||||
var viewCmd = &cobra.Command{
|
||||
Use: "view",
|
||||
Short: "preview a file or directory",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: viewRun,
|
||||
}
|
||||
|
||||
func init() {
|
||||
viewCmd.Flags().BoolVarP(&viewNewBlock, "newblock", "n", false, "open view in a new block")
|
||||
rootCmd.AddCommand(viewCmd)
|
||||
}
|
||||
|
||||
func viewRun(cmd *cobra.Command, args []string) {
|
||||
fileArg := args[0]
|
||||
absFile, err := filepath.Abs(fileArg)
|
||||
if err != nil {
|
||||
log.Printf("error getting absolute path: %v\n", err)
|
||||
return
|
||||
}
|
||||
_, err = os.Stat(absFile)
|
||||
if err == fs.ErrNotExist {
|
||||
log.Printf("file does not exist: %q\n", absFile)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("error getting file info: %v\n", err)
|
||||
}
|
||||
setTermRawMode()
|
||||
viewWshCmd := &wshutil.CreateBlockCommand{
|
||||
Command: wshutil.Command_CreateBlock,
|
||||
BlockDef: &wstore.BlockDef{
|
||||
View: "preview",
|
||||
Meta: map[string]interface{}{
|
||||
"file": absFile,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = RpcClient.SendRpcRequest(viewWshCmd, 2000)
|
||||
if err != nil {
|
||||
log.Printf("error running view command: %v\r\n", err)
|
||||
return
|
||||
}
|
||||
}
|
@ -519,6 +519,12 @@ async function appMain() {
|
||||
let wins: WaveBrowserWindow[] = [];
|
||||
for (let windowId of clientData.windowids.slice().reverse()) {
|
||||
let windowData: WaveWindow = (await services.ObjectService.GetObject("window:" + windowId)) as WaveWindow;
|
||||
if (windowData == null) {
|
||||
services.WindowService.CloseWindow(windowId).catch((e) => {
|
||||
/* ignore */
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const win = createBrowserWindow(clientData, windowData);
|
||||
wins.push(win);
|
||||
}
|
||||
|
@ -267,6 +267,8 @@ func (bc *BlockController) waveOSCMessageHandler(ctx context.Context, cmd wshuti
|
||||
return staticHandleGetMeta(ctx, cmd.(*wshutil.BlockGetMetaCommand))
|
||||
case wshutil.Command_ResolveIds:
|
||||
return staticHandleResolveIds(ctx, cmd.(*wshutil.ResolveIdsCommand))
|
||||
case wshutil.Command_CreateBlock:
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ProcessStaticCommand(bc.BlockId, cmd)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
||||
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
|
||||
@ -96,5 +97,14 @@ func (svc *WindowService) CloseWindow(ctx context.Context, windowId string) erro
|
||||
if err != nil {
|
||||
return fmt.Errorf("error deleting window: %w", err)
|
||||
}
|
||||
client, err := wstore.DBGetSingleton[*wstore.Client](ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting client: %w", err)
|
||||
}
|
||||
utilfn.RemoveElemFromSlice(client.WindowIds, windowId)
|
||||
err = wstore.DBUpdate(ctx, client)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating client: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -750,6 +750,16 @@ func SliceIdx[T comparable](arr []T, elem T) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func RemoveElemFromSlice[T comparable](arr []T, elem T) []T {
|
||||
rtn := make([]T, 0, len(arr))
|
||||
for _, e := range arr {
|
||||
if e != elem {
|
||||
rtn = append(rtn, e)
|
||||
}
|
||||
}
|
||||
return rtn
|
||||
}
|
||||
|
||||
func MoveSliceIdxToFront[T any](arr []T, idx int) []T {
|
||||
// create and return a new slice with idx moved to the front
|
||||
if idx == 0 || idx >= len(arr) {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/wavetermdev/thenextwave/pkg/ijson"
|
||||
"github.com/wavetermdev/thenextwave/pkg/shellexec"
|
||||
"github.com/wavetermdev/thenextwave/pkg/tsgen/tsgenmeta"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||
)
|
||||
|
||||
const CommandKey = "command"
|
||||
@ -24,6 +25,7 @@ const (
|
||||
BlockCommand_AppendBlockFile = "blockfile:append"
|
||||
BlockCommand_AppendIJson = "blockfile:appendijson"
|
||||
Command_ResolveIds = "resolveids"
|
||||
Command_CreateBlock = "createblock"
|
||||
)
|
||||
|
||||
var CommandToTypeMap = map[string]reflect.Type{
|
||||
@ -35,6 +37,7 @@ var CommandToTypeMap = map[string]reflect.Type{
|
||||
BlockCommand_AppendBlockFile: reflect.TypeOf(BlockAppendFileCommand{}),
|
||||
BlockCommand_AppendIJson: reflect.TypeOf(BlockAppendIJsonCommand{}),
|
||||
Command_ResolveIds: reflect.TypeOf(ResolveIdsCommand{}),
|
||||
Command_CreateBlock: reflect.TypeOf(CreateBlockCommand{}),
|
||||
}
|
||||
|
||||
func CommandTypeUnionMeta() tsgenmeta.TypeUnionMeta {
|
||||
@ -158,3 +161,13 @@ type BlockAppendIJsonCommand struct {
|
||||
func (bwc *BlockAppendIJsonCommand) GetCommand() string {
|
||||
return BlockCommand_AppendIJson
|
||||
}
|
||||
|
||||
type CreateBlockCommand struct {
|
||||
Command string `json:"command" tstype:"\"createblock\""`
|
||||
BlockDef *wstore.BlockDef `json:"blockdef"`
|
||||
RtOpts *wstore.RuntimeOpts `json:"rtopts,omitempty"`
|
||||
}
|
||||
|
||||
func (cbc *CreateBlockCommand) GetCommand() string {
|
||||
return Command_CreateBlock
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user