Skip to content

Commit 603db81

Browse files
koronmartinRenou
authored andcommitted
Added a button to open the Origin Private File System
For more information about the OPFS, see: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system
1 parent a5dd06e commit 603db81

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

schema/plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"jupyter.lab.toolbars": {
55
"FileSystemAccess": [
66
{ "name": "open-folder", "rank": 0 },
7+
{ "name": "open-opfs", "rank": 5 },
78
{ "name": "uploader", "rank": 10 },
89
{ "name": "filename-searcher", "rank": 20 }
910
]

src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
2323
import {
2424
listIcon,
2525
folderIcon,
26+
trustedIcon,
2627
IScore,
2728
FilenameSearcher
2829
} from '@jupyterlab/ui-components';
@@ -116,6 +117,25 @@ const plugin: JupyterFrontEndPlugin<void> = {
116117
}
117118
);
118119

120+
toolbarRegistry.addFactory(
121+
DRIVE_NAME,
122+
'open-opfs',
123+
(browser: FileBrowser) => {
124+
const openOPFSButton = new ToolbarButton({
125+
icon: trustedIcon,
126+
onClick: async () => {
127+
const directoryHandle = await navigator.storage.getDirectory();
128+
if (directoryHandle) {
129+
drive.rootHandle = directoryHandle;
130+
widget.model.cd('/');
131+
}
132+
},
133+
tooltip: trans.__('Open the Origin Private File System')
134+
});
135+
return openOPFSButton;
136+
}
137+
);
138+
119139
toolbarRegistry.addFactory(
120140
DRIVE_NAME,
121141
'uploader',

0 commit comments

Comments
 (0)