4
4
5
5
namespace OCA \Notes \Controller ;
6
6
7
+ use OCA \Notes \AppInfo \Application ;
7
8
use OCA \Notes \Service \NotesService ;
8
9
10
+ use OCA \Notes \Service \SettingsService ;
9
11
use OCA \Text \Event \LoadEditor ;
12
+ use OCP \App \IAppManager ;
10
13
use OCP \AppFramework \Controller ;
11
14
use OCP \AppFramework \Http \TemplateResponse ;
12
15
use OCP \AppFramework \Http \ContentSecurityPolicy ;
13
16
use OCP \AppFramework \Http \RedirectResponse ;
17
+ use OCP \AppFramework \Services \IInitialState ;
14
18
use OCP \EventDispatcher \IEventDispatcher ;
19
+ use OCP \IConfig ;
15
20
use OCP \IRequest ;
16
21
use OCP \IURLGenerator ;
17
22
use OCP \IUserSession ;
18
23
19
24
class PageController extends Controller {
20
25
private NotesService $ notesService ;
26
+ private IConfig $ config ;
21
27
private IUserSession $ userSession ;
22
28
private IURLGenerator $ urlGenerator ;
23
29
private IEventDispatcher $ eventDispatcher ;
30
+ private IInitialState $ initialState ;
24
31
25
32
public function __construct (
26
33
string $ AppName ,
27
34
IRequest $ request ,
28
35
NotesService $ notesService ,
36
+ IConfig $ config ,
29
37
IUserSession $ userSession ,
30
38
IURLGenerator $ urlGenerator ,
31
- IEventDispatcher $ eventDispatcher
39
+ IEventDispatcher $ eventDispatcher ,
40
+ IInitialState $ initialState
32
41
) {
33
42
parent ::__construct ($ AppName , $ request );
34
43
$ this ->notesService = $ notesService ;
44
+ $ this ->config = $ config ;
35
45
$ this ->userSession = $ userSession ;
36
46
$ this ->urlGenerator = $ urlGenerator ;
37
47
$ this ->eventDispatcher = $ eventDispatcher ;
48
+ $ this ->initialState = $ initialState ;
38
49
}
39
50
40
51
41
52
/**
42
53
* @NoAdminRequired
43
54
* @NoCSRFRequired
55
+ * @suppress PhanUndeclaredClassReference, PhanTypeMismatchArgument, PhanUndeclaredClassMethod
44
56
*/
45
57
public function index () : TemplateResponse {
46
58
$ devMode = !is_file (dirname (__FILE__ ).'/../../js/notes-main.js ' );
@@ -50,10 +62,20 @@ public function index() : TemplateResponse {
50
62
[ ]
51
63
);
52
64
53
- if (class_exists (LoadEditor::class)) {
65
+ if (\ OCP \Server:: get (IAppManager::class)-> isEnabledForUser ( ' text ' ) && class_exists (LoadEditor::class)) {
54
66
$ this ->eventDispatcher ->dispatchTyped (new LoadEditor ());
55
67
}
56
68
69
+ $ this ->initialState ->provideInitialState (
70
+ 'config ' ,
71
+ \OCP \Server::get (SettingsService::class)->getPublic ($ this ->userSession ->getUser ()->getUID ())
72
+ );
73
+
74
+ $ this ->initialState ->provideInitialState (
75
+ 'editorHint ' ,
76
+ $ this ->config ->getUserValue ($ this ->userSession ->getUser ()->getUID (), Application::APP_ID , 'editorHint ' , '' )
77
+ );
78
+
57
79
$ csp = new ContentSecurityPolicy ();
58
80
$ csp ->addAllowedImageDomain ('* ' );
59
81
$ response ->setContentSecurityPolicy ($ csp );
0 commit comments