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
6 changes: 5 additions & 1 deletion components/src/stores/base.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

export interface BaseContext {
fs: FileSystem;
canUpgradeFs: boolean;
upgradeFs: (force?: boolean) => void;
closeFs: () => void;
upgraded?: string;
Expand Down Expand Up @@ -58,9 +59,10 @@ export function useBaseContext(): BaseContext {
});
}, [upgraded, replaceFs]);

const canUpgradeFs = `showDirectoryPicker` in window;
const upgradeFs = useCallback(
async (force = false) => {
if (upgraded && !force) return;
if (!canUpgradeFs || (upgraded && !force)) return;
const handler = await openNand2TetrisDirectory();
const adapter = await createAndStoreLocalAdapterInIndexedDB(handler);
replaceFs(adapter);
Expand All @@ -82,6 +84,7 @@ export function useBaseContext(): BaseContext {
status,
setStatus,
storage: localStorage,
canUpgradeFs,
upgradeFs,
closeFs,
upgraded,
Expand All @@ -90,6 +93,7 @@ export function useBaseContext(): BaseContext {

export const BaseContext = createContext<BaseContext>({
fs: new FileSystem(new LocalStorageFileSystemAdapter()),
canUpgradeFs: false,
// eslint-disable-next-line @typescript-eslint/no-empty-function
upgradeFs() {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
1 change: 1 addition & 0 deletions extension/views/hdl/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const baseContext: BaseContext = {
new ObjectFileSystemAdapter({ "projects/01/Not.hdl": Not.hdl })
),
upgraded: "true",
canUpgradeFs: false,
upgradeFs() {},
closeFs() {},
storage: {},
Expand Down
7 changes: 6 additions & 1 deletion web/src/shell/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const headerButtons: HeaderButton[] = [
headerButtonFromURL(URLs["cpu"], "developer_board"),
headerButtonFromURL(URLs["asm"], "list_alt"),
headerButtonFromURL(URLs["vm"], "computer"),
headerButtonFromURL(URLs["compiler"], "code"),
// TODO(https://github.com/nand2tetris/web-ide/issues/349)
// reenable when this is resolved for Firefox and safari
// https://caniuse.com/?search=showDirectoryPicker
...("showDirectoryPicker" in window
? [headerButtonFromURL(URLs["compiler"], "code")]
: []),
headerButtonFromURL(URLs["bitmap"], "grid_on"),
headerButtonFromURL(URLs["util"], "function", "Converter Tool"),
{
Expand Down
6 changes: 4 additions & 2 deletions web/src/shell/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const showUpgradeFs = false;

export const Settings = () => {
const { toolStates } = useContext(AppContext);
const { fs, setStatus, upgradeFs, closeFs, upgraded } =
const { fs, setStatus, canUpgradeFs, upgradeFs, closeFs, upgraded } =
useContext(BaseContext);
const { settings, monaco, theme, setTheme, tracking } =
useContext(AppContext);
Expand Down Expand Up @@ -155,7 +155,7 @@ export const Settings = () => {
<Trans>Files</Trans>
</dt>
<dd>
{showUpgradeFs && (
{showUpgradeFs && canUpgradeFs ? (
<>
<button
disabled={upgrading}
Expand Down Expand Up @@ -194,6 +194,8 @@ export const Settings = () => {
<></>
)}
</>
) : (
<></>
)}
<button
onClick={async () => {
Expand Down
1 change: 1 addition & 0 deletions web/src/testing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useTestingAppContext = () => ({
"projects/01/Not/Not.cmp": Not.cmp,
}),
),
canUpgradeFs: false,
// eslint-disable-next-line @typescript-eslint/no-empty-function
upgradeFs() {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down