Skip to content

Commit d7ed367

Browse files
Default load puter users home directory
1 parent 3910d7a commit d7ed367

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

myDav/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"activationEvents": [
2121
"onFileSystem:webdav",
2222
"onFileSystem:webdavs",
23+
"*",
2324
"onCommand:extension.remote.webdav.open",
2425
"onCommand:extension.remote.webdav.resetAuth"
2526
],

myDav/src/extension.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ export async function resetAuth() {
4545
}
4646
}
4747

48+
export async function openDefaultFolder() {
49+
console.log("opening defauilt");
50+
let uriValue = "https://dav.puter.com/" + await fetch("/syscall/getUsername").then(r=>r.text());
51+
let name = uriValue.split("/").pop()
52+
let webdavUri = vscode.Uri.parse(uriValue.trim().replace(/^http/i, 'webdav'));
53+
54+
55+
await configureAuthForUri(toBaseUri(webdavUri));
56+
57+
vscode.workspace.updateWorkspaceFolders(
58+
0, 0,
59+
{
60+
uri: webdavUri,
61+
name: name?.trim() ?? webdavUri.authority,
62+
},
63+
);
64+
}
65+
4866
export async function openWebdav() {
4967
let uriValue = await fetch("/syscall/getFolderPicker").then(r=>r.text());
5068

@@ -76,6 +94,7 @@ export async function openWebdav() {
7694
}
7795

7896
export async function activate(context: vscode.ExtensionContext) {
97+
console.log("registering webdav workspace")
7998
context.subscriptions.push(
8099
outputChannel = vscode.window.createOutputChannel('WebDAV Workspaces')
81100
);
@@ -91,13 +110,15 @@ export async function activate(context: vscode.ExtensionContext) {
91110
vscode.workspace.registerFileSystemProvider(scheme, new WebDAVFileSystemProvider(), { isCaseSensitive: true })
92111
);
93112
}
113+
console.log("registering commands")
94114

95115
log(`Register extension.remote.webdav.resetAuth command... `);
96116
context.subscriptions.push(vscode.commands.registerCommand('extension.remote.webdav.resetAuth', resetAuth));
97117

98118
log(`Register extension.remote.webdav.open command... `);
99119
context.subscriptions.push(vscode.commands.registerCommand('extension.remote.webdav.open', openWebdav));
100-
120+
console.log("doing the default folder")
121+
openDefaultFolder();
101122
outputChannel.appendLine('Extension has been initialized.');
102123
}
103124

product.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
]
1818
}
1919
},
20-
20+
2121
"additionalBuiltinExtensions": [
2222
{
2323
"scheme": "https",
2424
"path": "/myDav"
25-
},
26-
{
27-
"scheme": "http",
28-
"path": "/myDav"
2925
}
3026
]
3127
}

puterjs-layer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ async function getFilePath() {
1414
return (await puter.ui.showFilePicker()).path.replace("~", "/" + (puter.whoami || await puter.getUser()).username);
1515
}
1616
async function ensureAuth() {
17-
await puter.ui.auth.signIn();
1817
if (!puter.authToken) {
1918
await ensureAuth();
2019
}
2120
}
21+
async function getUsername() {
22+
await ensureAuth();
23+
return ((puter.whoami || await puter.getUser()).username);
24+
}
25+
2226

2327
function initComlink() {
2428
const channel = new MessageChannel();
@@ -30,6 +34,7 @@ function initComlink() {
3034
sharedObject.getFolderPath = getFolderPath;
3135
sharedObject.getFilePath = getFilePath;
3236
sharedObject.ensureAuth = ensureAuth;
37+
sharedObject.getUsername = getUsername;
3338
// console.log("shared object: ", _runInSW);
3439
}
3540

sw.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ let routes = {
2626
console.log("MORTAL's folder path: ", thing);
2727
return new Response(thing);
2828
},
29+
['/syscall/getUsername']: async function (response) {
30+
await readyPromise;
31+
32+
return new Response(await sharedObject.getUsername());
33+
},
2934

3035
['/syscall/getToken']: async function (response) {
3136
await readyPromise;

0 commit comments

Comments
 (0)