| 1 |
<?php |
| 2 |
/** |
| 3 |
* Station Home — the native Dashboard, as an OpenStation app. |
| 4 |
* |
| 5 |
* THE Station Home: the App Framework rebuild replaced the legacy |
| 6 |
* native window whole and claims its id — `desktop-mode-dashboard` is |
| 7 |
* the id the shell's Dashboard URL remap opens (`src/desktop.ts`), so |
| 8 |
* every `index.php` menu entry, portal fallback, bookmark and saved |
| 9 |
* session keeps working unchanged. The window is this file; the body |
| 10 |
* is a SERVER view (`parts/view.php`) painted from the snapshot model |
| 11 |
* (`parts/snapshot.php`) — the first app with no client half at all. |
| 12 |
* The plugin-card registry (`includes/station-home/cards.php`) is |
| 13 |
* untouched: same registration API, same preference meta, same hooks. |
| 14 |
* |
| 15 |
* What the framework replaced: the window registration and template, |
| 16 |
* the two REST routes and the bundle's fetch/paint choreography |
| 17 |
* (`refresh` is the built-in; Customize is one state key; a switch is |
| 18 |
* an action), the imperative click delegates (a quick action is a |
| 19 |
* link, or a button dispatching `launch`), and the restore-time |
| 20 |
* reload (`show`). |
| 21 |
* |
| 22 |
* @package OpenStation |
| 23 |
*/ |
| 24 |
|
| 25 |
namespace OpenStation\Apps\StationHome; |
| 26 |
|
| 27 |
use OpenStation\App; |
| 28 |
use OpenStation\App\Os; |
| 29 |
use OpenStation\App\State; |
| 30 |
|
| 31 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 32 |
if ( ! defined( 'ABSPATH' ) ) { |
| 33 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 34 |
} |
| 35 |
|
| 36 |
require_once __DIR__ . '/parts/snapshot.php'; |
| 37 |
require_once __DIR__ . '/parts/view.php'; |
| 38 |
|
| 39 |
/** The window id the Dashboard URL remap opens. */ |
| 40 |
const APP_ID = 'desktop-mode-dashboard'; |
| 41 |
|
| 42 |
return App::define( APP_ID ) |
| 43 |
->title( __( 'Station Home', 'desktop-mode' ) ) |
| 44 |
->icon( 'dashicons-dashboard' ) |
| 45 |
->size( 1240, 760 ) |
| 46 |
->min_size( 640, 480 ) |
| 47 |
// No dock tile of its own: the Dashboard entry the shell already |
| 48 |
// has opens it through the URL remap, per-user opt-in and all. |
| 49 |
->placement( 'none' ) |
| 50 |
->capabilities( 'read' ) |
| 51 |
// The only state: whether the Customize picker is open. Everything |
| 52 |
// else is derived from the snapshot on every render. |
| 53 |
->state( array( 'customizing' => false ) ) |
| 54 |
->action( |
| 55 |
'customize', |
| 56 |
static function ( State $state ) { |
| 57 |
$state->set( 'customizing', true ); |
| 58 |
} |
| 59 |
) |
| 60 |
->action( |
| 61 |
'customize_close', |
| 62 |
static function ( State $state ) { |
| 63 |
$state->set( 'customizing', false ); |
| 64 |
} |
| 65 |
) |
| 66 |
// A picker switch: store the choice, and the re-render adds or |
| 67 |
// removes the card in the same paint that settles the switch. An |
| 68 |
// id that is not registered for this user is refused. |
| 69 |
->action( |
| 70 |
'toggle_card', |
| 71 |
static function ( State $state, Os $os, array $args ) { |
| 72 |
$stored = openstation_station_home_set_card_preference( |
| 73 |
$os->auth->user_id(), |
| 74 |
isset( $args['id'] ) ? (string) $args['id'] : '', |
| 75 |
! empty( $args['checked'] ) |
| 76 |
); |
| 77 |
if ( ! $stored ) { |
| 78 |
$os->toast( __( 'That Station Home card is not available.', 'desktop-mode' ) ); |
| 79 |
} |
| 80 |
} |
| 81 |
) |
| 82 |
// A quick action that is not a link: the WP Explorer app, or the |
| 83 |
// classic Dashboard in an iframe window. Resolved against the |
| 84 |
// capability-gated list, so a button the user was never shown |
| 85 |
// launches nothing. |
| 86 |
->action( |
| 87 |
'launch', |
| 88 |
static function ( State $state, Os $os, array $args ) { |
| 89 |
$id = isset( $args['id'] ) ? sanitize_key( (string) $args['id'] ) : ''; |
| 90 |
foreach ( quick_actions( $os ) as $action ) { |
| 91 |
if ( $action['id'] !== $id ) { |
| 92 |
continue; |
| 93 |
} |
| 94 |
if ( 'native' === $action['kind'] && ! empty( $action['windowId'] ) ) { |
| 95 |
$os->open( $action['windowId'] ); |
| 96 |
} elseif ( 'classic' === $action['kind'] ) { |
| 97 |
$os->open_url( $action['url'], $action['label'], $action['icon'] ); |
| 98 |
} |
| 99 |
return; |
| 100 |
} |
| 101 |
} |
| 102 |
) |
| 103 |
// Lifecycle: a restored window repaints itself — the legacy |
| 104 |
// bundle's `onShow` reload. Declaring the handler is the whole |
| 105 |
// point; there is nothing to run before the re-render. |
| 106 |
->action( |
| 107 |
'show', |
| 108 |
static function () { |
| 109 |
// The re-render that follows every action is the refresh. |
| 110 |
} |
| 111 |
) |
| 112 |
// Anything published, trashed or moderated anywhere on the desktop |
| 113 |
// repaints Continue working, the instruments and the queue. |
| 114 |
->watch( '*' ) |
| 115 |
->view( __NAMESPACE__ . '\\render' ); |
| 116 |
|