Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/app/view/preview/preview-directory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,14 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
modtime: new Date().getTime(),
mimetype: "directory",
});
} else if (!finfo?.dir && finfo?.path) {
entries.unshift({
name: "..",
path: "",
isdir: true,
modtime: new Date().getTime(),
mimetype: "directory",
});
}
} catch (e) {
console.error("Directory Read Error", e);
Expand Down
10 changes: 7 additions & 3 deletions frontend/app/view/preview/preview-model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const BOOKMARKS: { label: string; path: string }[] = [
{ label: "Root", path: "/" },
];

if (window.navigator?.platform?.startsWith("Win")) {
BOOKMARKS.push({ label: "Drives", path: "" });
}

const MaxFileSize = 1024 * 1024 * 10; // 10MB
const MaxCSVSize = 1024 * 1024 * 1; // 1MB

Expand Down Expand Up @@ -207,7 +211,7 @@ export class PreviewModel implements ViewModel {
return {
elemtype: "iconbutton",
icon: "folder-open",
longClick: (e: React.MouseEvent<any>) => {
click: (e: React.MouseEvent<any>) => {
const menuItems: ContextMenuItem[] = BOOKMARKS.map((bookmark) => ({
label: `Go to ${bookmark.label} (${bookmark.path})`,
click: () => this.goHistory(bookmark.path),
Expand Down Expand Up @@ -315,7 +319,7 @@ export class PreviewModel implements ViewModel {
}
const mimeType = jotaiLoadableValue(get(this.fileMimeTypeLoadable), "");
const metaPath = get(this.metaFilePath);
if (mimeType == "directory" && metaPath == "/") {
if (mimeType == "directory" && (metaPath == "/" || metaPath == "")) {
return null;
}
return {
Expand Down Expand Up @@ -379,7 +383,7 @@ export class PreviewModel implements ViewModel {
});
this.metaFilePath = atom<string>((get) => {
const file = get(this.blockAtom)?.meta?.file;
if (isBlank(file)) {
if (file == null) {
return "~";
}
return file;
Expand Down
20 changes: 11 additions & 9 deletions frontend/util/historyutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import * as util from "@/util/util";

const MaxHistory = 20;

// this needs to be fixed for windows
function getParentDirectory(path: string): string {
if (util.isBlank(path) == null) {
// this not great, ideally we'd never be passed a null path
return "/";
}
if (path == "/") {
return "/";
if (path == "/" || path == "") {
return path;
}
const splitPath = path.split("/");
const separator = path.includes("\\") ? "\\" : "/";
const splitPath = path.split(separator);
splitPath.pop();
if (splitPath.length == 1 && splitPath[0] == "") {
return "/";
if (splitPath.length == 0 || (splitPath.length == 1 && splitPath[0] == "")) {
return separator == "\\" ? path.substring(0, 3) : "/";
}
const joined = splitPath.join(separator);
if (separator == "\\" && joined.length == 2 && joined[1] == ":") {
return joined + "\\";
}
const newPath = splitPath.join("/");
return newPath;
return joined;
}

function goHistoryBack(curValKey: "url" | "file", curVal: string, meta: MetaType, backToParent: boolean): MetaType {
Expand Down
3 changes: 3 additions & 0 deletions frontend/util/waveutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,8 @@ export function computeBgStyleFromMeta(meta: Omit<BackgroundConfigType, "display

export function formatRemoteUri(path: string, connection: string): string {
connection = connection ?? "local";
if (path === "") {
return `wsh://${connection}`;
}
return `wsh://${connection}/${path}`;
}
4 changes: 2 additions & 2 deletions pkg/wconfig/defaultconfig/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ai:timeoutms": 60000,
"app:defaultnewblock": "term",
"app:tabbar": "top",
"app:confirmquit": true,
"app:confirmquit": false,
"app:hideaibutton": false,
"term:showsplitbuttons": false,
"app:disablectrlshiftarrows": false,
Expand All @@ -27,7 +27,7 @@
"window:magnifiedblockblurprimarypx": 10,
"window:fullscreenonlaunch": false,
"window:magnifiedblockblursecondarypx": 2,
"window:confirmclose": true,
"window:confirmclose": false,
"window:savelastwindow": true,
"telemetry:enabled": true,
"term:bellsound": false,
Expand Down
47 changes: 47 additions & 0 deletions pkg/wshrpc/wshremote/wshremote_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -207,6 +208,18 @@ func (impl *ServerImpl) RemoteListEntriesCommand(ctx context.Context, data wshrp
panichandler.PanicHandler("RemoteListEntriesCommand", recover())
}()
defer close(ch)

if runtime.GOOS == "windows" && data.Path == "" {
drives, err := listDrives()
if err != nil {
ch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](err)
return
}
resp := wshrpc.CommandRemoteListEntriesRtnData{FileInfo: drives}
ch <- wshrpc.RespOrErrorUnion[wshrpc.CommandRemoteListEntriesRtnData]{Response: resp}
return
}

path, err := wavebase.ExpandHomeDir(data.Path)
if err != nil {
ch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](err)
Expand Down Expand Up @@ -327,14 +340,48 @@ func checkIsReadOnly(path string, fileInfo fs.FileInfo, exists bool) bool {

func computeDirPart(path string) string {
path = filepath.Clean(wavebase.ExpandHomeDirSafe(path))
if runtime.GOOS == "windows" {
vol := filepath.VolumeName(path)
if vol != "" && path == vol+"\\" {
return ""
}
}
path = filepath.ToSlash(path)
if path == "/" {
return "/"
}
return filepath.Dir(path)
}

func listDrives() ([]*wshrpc.FileInfo, error) {
var drives []*wshrpc.FileInfo
for _, letter := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
drivePath := string(letter) + ":\\"
finfo, err := os.Stat(drivePath)
if err != nil {
continue
}
driveInfo := statToFileInfo(drivePath, finfo, false)
driveInfo.Name = string(letter) + ":"
drives = append(drives, driveInfo)
}
if len(drives) == 0 {
return nil, fmt.Errorf("no drives found")
}
return drives, nil
}

func (*ServerImpl) fileInfoInternal(path string, extended bool) (*wshrpc.FileInfo, error) {
if runtime.GOOS == "windows" && path == "" {
return &wshrpc.FileInfo{
Path: "",
Dir: "",
Name: "Drives",
IsDir: true,
MimeType: "directory",
SupportsMkdir: false,
}, nil
}
cleanedPath := filepath.Clean(wavebase.ExpandHomeDirSafe(path))
finfo, err := os.Stat(cleanedPath)
if os.IsNotExist(err) {
Expand Down
Loading