@@ -16,7 +16,7 @@ import {
1616import { QueryParams } from "@cocalc/frontend/misc/query-params" ;
1717import { is_valid_uuid_string } from "@cocalc/util/misc" ;
1818
19- export function init_query_params ( ) : void {
19+ function init_fullscreen_mode ( ) : void {
2020 const actions = redux . getActions ( "page" ) ;
2121 // enable fullscreen mode upon loading a URL like /app?fullscreen and
2222 // additionally kiosk-mode upon /app?fullscreen=kiosk
@@ -40,13 +40,19 @@ export function init_query_params(): void {
4040 } else if ( COCALC_FULLSCREEN === "project" ) {
4141 actions . set_fullscreen ( "project" ) ;
4242 }
43+ }
4344
45+ function init_api_key ( ) : void {
46+ const actions = redux . getActions ( "page" ) ;
4447 const get_api_key_query_value = QueryParams . get ( "get_api_key" ) ;
4548 if ( get_api_key_query_value ) {
4649 actions . set_get_api_key ( get_api_key_query_value ) ;
4750 actions . set_fullscreen ( "project" ) ;
4851 }
52+ }
4953
54+ function init_session ( ) : void {
55+ const actions = redux . getActions ( "page" ) ;
5056 // configure the session
5157 // This makes it so the default session is 'default' and there is no
5258 // way to NOT have a session, except via session=, which is treated
@@ -79,5 +85,72 @@ export function init_query_params(): void {
7985 // not have session in the URL, so we can share url's without infected
8086 // other user's session.
8187 QueryParams . remove ( "session" ) ;
88+ }
89+
90+ function parse_accessibility_param ( param : string ) : boolean | null {
91+ if ( param === "true" || param === "on" || param === "1" ) {
92+ return true ;
93+ }
94+ if ( param === "false" || param === "off" || param === "0" ) {
95+ return false ;
96+ }
97+ return null ;
98+ }
99+
100+ async function init_accessibility ( ) : Promise < void > {
101+ // Handle accessibility query parameter
102+ // If ?accessibility=true or =on, enable accessibility mode permanently
103+ // If ?accessibility=false or =off, disable it permanently
104+ // This allows sharing URLs that automatically enable accessibility
105+ const accessibilityParam = QueryParams . get ( "accessibility" ) ;
106+ if ( accessibilityParam == null ) {
107+ return ;
108+ }
109+
110+ const enabled = parse_accessibility_param ( accessibilityParam ) ;
111+ QueryParams . remove ( "accessibility" ) ;
112+
113+ if ( enabled == null ) {
114+ return ;
115+ }
116+
117+ try {
118+ // Wait for account to be ready before setting accessibility
119+ const store = redux . getStore ( "account" ) ;
120+ await store . async_wait ( {
121+ until : ( ) => store . get_account_id ( ) != null ,
122+ timeout : 0 ,
123+ } ) ;
124+
125+ // Preserve existing accessibility settings
126+ const existingSettingsStr = store . getIn ( [
127+ "other_settings" ,
128+ "accessibility" ,
129+ ] ) ;
130+ let existingSettings = { enabled : false } ;
131+ if ( existingSettingsStr ) {
132+ try {
133+ existingSettings = JSON . parse ( existingSettingsStr ) ;
134+ } catch {
135+ // Ignore parse errors, use default
136+ }
137+ }
138+
139+ // Merge with new enabled value
140+ const settings = { ...existingSettings , enabled } ;
141+ const accountActions = redux . getActions ( "account" ) ;
142+ accountActions . set_other_settings (
143+ "accessibility" ,
144+ JSON . stringify ( settings ) ,
145+ ) ;
146+ } catch ( err ) {
147+ console . warn ( "Failed to set accessibility from query param:" , err ) ;
148+ }
149+ }
82150
151+ export async function init_query_params ( ) : Promise < void > {
152+ init_fullscreen_mode ( ) ;
153+ init_api_key ( ) ;
154+ init_session ( ) ;
155+ await init_accessibility ( ) ;
83156}
0 commit comments