File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
libraries/Library/Std/Editor Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { editorSyscalls } from "./plugos/syscalls/editor.ts";
1515import { markdownSyscalls } from "./plugos/syscalls/markdown.ts" ;
1616import { languageSyscalls } from "./plugos/syscalls/language.ts" ;
1717import { 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 {
4344export 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
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments