-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
95 lines (81 loc) · 3.92 KB
/
Copy pathindex.php
File metadata and controls
95 lines (81 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Grafida — edit Joomla! articles on your desktop.
*
* @copyright Copyright (c) 2026 Nicholas K. Dionysopoulos
* @license GNU General Public License version 3, or later
*/
declare(strict_types=1);
use Boson\Application;
use Boson\ApplicationCreateInfo;
use Boson\Component\Http\Static\FilesystemStaticProvider;
use Boson\WebView\Api\Schemes\Event\SchemeRequestReceived;
use Boson\WebView\WebViewCreateInfo;
use Boson\Window\WindowCreateInfo;
use Boson\Window\WindowDecoration;
use Grafida\Application\ContainerFactory;
use Grafida\Editor\MacSpellCheck;
use Grafida\FrontController;
require __DIR__ . '/vendor/autoload.php';
// Windows: grafida.exe runs on a console-subsystem PHP runtime (the phpmicro
// SFX is a CLI build), so Windows hands the process a console window. Grafida is
// a GUI app, so hide it immediately. Crucially, this also stops the "flashing
// CMD window on every click": the console subprocesses the backend spawns
// (registry theme probe, DPAPI secret store — see Grafida\Secret\ProcessRunner)
// INHERIT this now-hidden console instead of each allocating a fresh, visible one.
// Best-effort via FFI (already loaded for Boson); any failure just leaves the
// console as-is. Must run before the first proc_open, i.e. before the app boots.
if (\PHP_OS_FAMILY === 'Windows' && \extension_loaded('ffi')) {
try {
$kernel32 = \FFI::cdef('void* GetConsoleWindow(void);', 'kernel32.dll');
$user32 = \FFI::cdef('int ShowWindow(void *hWnd, int nCmdShow);', 'user32.dll');
$console = $kernel32->GetConsoleWindow();
if (!\FFI::isNull($console)) {
$user32->ShowWindow($console, 0); // SW_HIDE
}
} catch (\Throwable) {
// No console to hide, or FFI unavailable — nothing to do.
}
}
// macOS: WKWebView gates all native spell checking on the WebContinuousSpellChecking-
// Enabled user default, read once on the first spell-check. A normal Mac app toggles it
// from its Edit ▸ Spelling menu; Boson wires up no menu bar, so the flag stays off and no
// misspelling is ever underlined (gh-24). Turn it on in Grafida's own preferences domain
// before the webview boots. Best-effort; a failure just leaves spell checking off, as before.
MacSpellCheck::enable();
$app = new Application(new ApplicationCreateInfo(
schemes: ['boson'],
debug: (bool) filter_var(getenv('BOSON_DEBUG'), \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE),
window: new WindowCreateInfo(
title: 'Grafida',
width: 1280,
height: 860,
decoration: WindowDecoration::DarkMode,
webview: new WebViewCreateInfo(
// Enable the native webview context menu (gh-26). Boson leaves it off in
// non-debug builds (WebViewCreateInfo::$contextMenu defaults to $app->isDebug),
// but it is what carries the spell-check suggestions: Ctrl/Cmd + right-click
// makes TinyMCE step aside so the native menu shows. With it disabled (as in a
// release build) there is no native menu to fall back to — on Windows/WebView2
// Ctrl+right-click did nothing at all. TinyMCE preventDefaults its own
// plain-right-click menu, so this never produces a double menu inside the editor;
// devTools stays debug-gated, so "Inspect element" does not appear in production.
contextMenu: true,
devTools: (bool) filter_var(getenv('BOSON_DEBUG'), \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE),
),
),
));
$static = new FilesystemStaticProvider([
__DIR__ . '/assets/private',
__DIR__ . '/assets/public',
]);
$container = ContainerFactory::create([
'static.provider' => $static,
'dialog' => $app->dialog,
]);
$controller = $container->get(FrontController::class);
$app->on(static function (SchemeRequestReceived $e) use ($controller): void {
$e->response = $controller($e->request);
});
$app->webview->url = 'boson://app/';
$app->run();