Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Kernel
Commits
9312e9f5
Commit
9312e9f5
authored
Oct 08, 2022
by
Romain Casati
Browse files
GUI: state saved in storage.
parent
adb510f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
packages/gui-base/src/main.ts
View file @
9312e9f5
import
{
PromiseDelegate
}
from
"
promise-delegate
"
;
import
{
CheckpointsManager
}
from
"
@basthon/checkpoints
"
;
import
{
CheckpointsManager
,
Storage
}
from
"
@basthon/checkpoints
"
;
import
{
KernelBase
}
from
"
@basthon/kernel-base
"
;
import
{
KernelLoader
}
from
"
@basthon/kernel-loader
"
;
...
...
@@ -30,6 +30,7 @@ export class GUIBase {
protected
_contentFilename
:
string
=
"
content.txt
"
;
protected
_urlKey
:
string
=
"
content
"
;
private
_extensions
:
Map
<
string
,
(()
=>
Promise
<
void
>
)
>
=
new
Map
();
protected
_stateStorage
:
Storage
<
boolean
>
;
/* console errors redirected to notification system */
private
_console_error
:
(
message
:
string
)
=>
void
=
console
.
error
;
...
...
@@ -43,6 +44,8 @@ export class GUIBase {
if
(
!
options
.
noCheckpointsInit
)
this
.
_checkpoints
=
new
CheckpointsManager
<
string
>
(
`
${
options
.
uiName
}
.
${
options
.
language
}
`
,
this
.
_maxCheckpoints
);
/* globale states (not language specific) */
this
.
_stateStorage
=
new
Storage
(
`
${
options
.
uiName
}
.states`
);
}
/**
...
...
@@ -224,8 +227,23 @@ export class GUIBase {
kernel
.
addEventListener
(
"
eval.error
"
,
()
=>
{
this
.
validateBackup
();
});
/* instanciate the storage */
await
this
.
_stateStorage
.
ready
();
}
/**
* Get state from strorage.
*/
protected
async
getState
(
state
:
string
,
def
?:
any
):
Promise
<
any
>
{
return
await
this
.
_stateStorage
.
get
(
state
)
??
def
;
}
/**
* Set state in storage.
*/
protected
async
setState
(
state
:
string
,
value
:
any
)
{
await
this
.
_stateStorage
.
set
(
state
,
value
);
}
/**
* Load content at startup.
*/
...
...
@@ -361,7 +379,7 @@ export class GUIBase {
/**
* Get mode as a string (dark/light).
*/
public
theme
():
"
dark
"
|
"
light
"
|
undefined
{
return
;
}
public
async
theme
():
Promise
<
"
dark
"
|
"
light
"
|
undefined
>
{
return
;
}
/**
* Restart the kernel.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment