Skip to content

Commit f6308c7

Browse files
committed
Adds back "lock" button on mobile
This can be used to toggle between read-only mode, useful for mobile users that are primarily navigating, not editing
1 parent b60496f commit f6308c7

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

client/boot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ safeRun(async () => {
6060
config = await loadConfig(
6161
bootstrapLuaScriptPages.map(extractSpaceLuaFromPageText).join("\n"),
6262
clientProxy.buildProxy(),
63+
!!bootConfig?.readOnly,
6364
);
6465
} catch (e: any) {
6566
alert(
@@ -74,6 +75,7 @@ safeRun(async () => {
7475
.map(extractSpaceLuaFromPageText)
7576
.join("\n"),
7677
clientProxy.buildProxy(),
78+
false,
7779
);
7880
} catch (e: any) {
7981
console.error("Boot error", e);

client/boot_config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { editorSyscalls } from "./plugos/syscalls/editor.ts";
1515
import { markdownSyscalls } from "./plugos/syscalls/markdown.ts";
1616
import { languageSyscalls } from "./plugos/syscalls/language.ts";
1717
import { jsonschemaSyscalls } from "./plugos/syscalls/jsonschema.ts";
18+
import { systemSyscalls } from "./plugos/syscalls/system.ts";
1819

1920
/**
2021
* Parses a page (CONFIG in practice) and extracts all space-lua code
@@ -43,6 +44,7 @@ export function extractSpaceLuaFromPageText(text: string): string {
4344
export async function loadConfig(
4445
luaCode: string,
4546
lateBoundClient: any,
47+
readOnly: boolean,
4648
): Promise<Config> {
4749
const config = new Config();
4850

@@ -54,6 +56,7 @@ export async function loadConfig(
5456
// Only expose a limited set of syscalls that we can offer at this point
5557
bootSystem.registerSyscalls(
5658
[],
59+
systemSyscalls(lateBoundClient, readOnly),
5760
// Collecting the config.* calls is basically what we're here for
5861
configSyscalls(config),
5962
// This offers calls like isMobile() which will be useful, and late binding for e.g. to make actionButtons run() work immediately on boot
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#meta
2+
3+
Adds commands and an action button (on mobile) for toggling read-only mode.
4+
5+
```space-lua
6+
function toggleReadOnlyMode()
7+
local ro = editor.getUiOption("forcedROMode")
8+
ro = not ro
9+
editor.setUiOption("forcedROMode", ro)
10+
editor.rebuildEditorState()
11+
if ro then
12+
editor.flashNotification("Read-only mode enabled")
13+
else
14+
editor.flashNotification("Read-only mode disabled")
15+
end
16+
end
17+
18+
print("System mode", system.getMode())
19+
20+
if system.getMode() == "rw" then
21+
command.define {
22+
name = "Editor: Toggle Read Only Mode",
23+
run = toggleReadOnlyMode
24+
}
25+
26+
actionButton.define {
27+
icon = "lock",
28+
description = "Toggle read-only mode",
29+
mobile = true,
30+
run = toggleReadOnlyMode
31+
}
32+
end
33+
```

0 commit comments

Comments
 (0)