PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.8.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.8.8
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / assets.php

assets.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 0.8.8, at includes/assets.php

337 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode asset registration.
4 *
5 * Registers all desktop-mode CSS and JS handles with WordPress so they can
6 * be enqueued from anywhere in the plugin (or by third parties).
7 *
8 * @package WPDesktopMode
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Registers the desktop mode CSS and JS handles.
15 *
16 * @since 0.1.0
17 */
18 function desktop_mode_register_assets() {
19 $version = DESKTOP_MODE_VERSION;
20 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
21
22 // `filemtime`-stamped version for built bundles. The plugin-wide
23 // `DESKTOP_MODE_VERSION` is bumped per release, but the bundles
24 // iterate faster — without a per-file mtime stamp, two clients
25 // loading the same `?ver=…` URL can be served different bytes
26 // (whichever build was on disk at upload time). Stamping with the
27 // file's modification time guarantees the URL changes whenever the
28 // file does, so "is my fix deployed?" is answerable from the
29 // network tab. Falls back to `$version` when the file is missing
30 // (test envs that import this file before the build runs).
31 $built_version = static function ( $relative ) use ( $version ) {
32 $path = DESKTOP_MODE_DIR . $relative;
33 return file_exists( $path ) ? (string) filemtime( $path ) : $version;
34 };
35
36 // Styles.
37 wp_register_style(
38 'desktop-mode-variables',
39 DESKTOP_MODE_URL . 'assets/css/variables.css',
40 array(),
41 $version
42 );
43 wp_register_style(
44 'desktop-mode',
45 DESKTOP_MODE_URL . 'assets/css/desktop.css',
46 array( 'desktop-mode-variables' ),
47 $version
48 );
49 // `filemtime`-stamped — window-chrome iteration (drop overlays,
50 // new drag affordances, third-party-plugin compat) lands faster
51 // than plugin version bumps. Without an mtime stamp the browser
52 // keeps `?ver=<plugin-version>` valid for the whole release cycle
53 // and the user keeps seeing yesterday's CSS even after a hard
54 // reload. Stamps the parent `windows.css` only; the @imports inside
55 // (`window-chrome.css`, `window-states.css`, …) inherit the cache
56 // directive from the parent fetch, so a busted `windows.css` busts
57 // the whole subtree.
58 wp_register_style(
59 'desktop-mode-windows',
60 DESKTOP_MODE_URL . 'assets/css/windows.css',
61 array( 'desktop-mode-variables', 'dashicons' ),
62 $built_version( 'assets/css/windows.css' )
63 );
64 wp_register_style(
65 'desktop-mode-dock',
66 DESKTOP_MODE_URL . 'assets/css/dock.css',
67 array( 'desktop-mode-variables', 'dashicons' ),
68 $version
69 );
70 wp_register_style(
71 'desktop-mode-dock-peek',
72 DESKTOP_MODE_URL . 'assets/css/dock-peek.css',
73 array( 'desktop-mode-dock' ),
74 $version
75 );
76 // `filemtime`-stamped — the chromeless overrides iterate faster
77 // than the plugin-wide version bumps (per-page compat shims and
78 // page-title-action exceptions land in patches), and a stale
79 // cached copy means the user sees yesterday's rules. Without the
80 // stamp, the browser keeps `?ver=0.8.1` valid for the whole
81 // release cycle.
82 wp_register_style(
83 'desktop-mode-chromeless',
84 DESKTOP_MODE_URL . 'assets/css/chromeless.css',
85 array( 'desktop-mode' ),
86 $built_version( 'assets/css/chromeless.css' )
87 );
88
89 wp_register_style(
90 'desktop-mode-ai-assistant',
91 DESKTOP_MODE_URL . 'assets/css/ai-assistant.css',
92 array( 'desktop-mode-variables' ),
93 $version
94 );
95
96 wp_register_style(
97 'desktop-mode-bug-report',
98 DESKTOP_MODE_URL . 'assets/css/bug-report.css',
99 array( 'desktop-mode-variables' ),
100 $version
101 );
102
103 // `filemtime` instead of the plugin-wide `$version` for the
104 // recycle-bin CSS — this file iterates faster than the bundle
105 // and we never want a stale CSS cache to mask a real fix.
106 $recycle_bin_css = DESKTOP_MODE_DIR . 'assets/css/recycle-bin.css';
107 wp_register_style(
108 'desktop-mode-recycle-bin',
109 DESKTOP_MODE_URL . 'assets/css/recycle-bin.css',
110 array( 'desktop-mode-variables', 'dashicons' ),
111 file_exists( $recycle_bin_css ) ? (string) filemtime( $recycle_bin_css ) : $version
112 );
113
114 // `filemtime` for the native Posts window CSS — same rationale as
115 // the recycle-bin CSS: bundle iterates faster than the plugin
116 // version and stale caches are worse than the cost of a 304.
117 $posts_window_css = DESKTOP_MODE_DIR . 'assets/css/posts-window.css';
118 wp_register_style(
119 'desktop-mode-posts-window',
120 DESKTOP_MODE_URL . 'assets/css/posts-window.css',
121 array( 'desktop-mode-variables', 'dashicons' ),
122 file_exists( $posts_window_css ) ? (string) filemtime( $posts_window_css ) : $version
123 );
124
125 // Native Plugins window CSS — same `filemtime`-cache-bust posture
126 // as the Posts/Recycle Bin styles.
127 $plugins_window_css = DESKTOP_MODE_DIR . 'assets/css/plugins-window.css';
128 wp_register_style(
129 'desktop-mode-plugins-window',
130 DESKTOP_MODE_URL . 'assets/css/plugins-window.css',
131 array( 'desktop-mode-variables', 'dashicons' ),
132 file_exists( $plugins_window_css ) ? (string) filemtime( $plugins_window_css ) : $version
133 );
134
135 // Native Comments window CSS — same `filemtime` posture.
136 $comments_window_css = DESKTOP_MODE_DIR . 'assets/css/comments-window.css';
137 wp_register_style(
138 'desktop-mode-comments-window',
139 DESKTOP_MODE_URL . 'assets/css/comments-window.css',
140 array( 'desktop-mode-variables', 'dashicons' ),
141 file_exists( $comments_window_css ) ? (string) filemtime( $comments_window_css ) : $version
142 );
143
144 // Files-on-the-Desktop tile + layer styles. `filemtime` for the
145 // same reason as the recycle-bin / posts-window CSS: this file
146 // iterates faster than the plugin version, and a stale cache
147 // would mask a real fix.
148 $desktop_files_css = DESKTOP_MODE_DIR . 'assets/css/desktop-files.css';
149 wp_register_style(
150 'desktop-mode-files',
151 DESKTOP_MODE_URL . 'assets/css/desktop-files.css',
152 array( 'desktop-mode-variables', 'dashicons' ),
153 file_exists( $desktop_files_css ) ? (string) filemtime( $desktop_files_css ) : $version
154 );
155
156 // Scripts.
157 //
158 // `wp-hooks` — the shell exposes a WordPress-style filter/action
159 // API (`window.wp.hooks`) to third-party plugins.
160 // `wp-i18n` — the TS `__()` / `_x()` / `sprintf()` wrappers in
161 // `src/i18n.ts` delegate to `window.wp.i18n` for translation
162 // lookups. Both handles are core-shipped but only pre-enqueued
163 // when Gutenberg-adjacent deps pull them in, so we list them
164 // explicitly to guarantee load order.
165 wp_register_script(
166 'desktop-mode',
167 DESKTOP_MODE_URL . 'assets/js/desktop' . $suffix . '.js',
168 // `heartbeat` + `jquery` — the recycle-bin badge module
169 // (loaded as part of this bundle) opts into the WordPress
170 // Heartbeat API so the count tile / desktop-icon badge
171 // stays in sync even when the bin window is closed.
172 array( 'wp-hooks', 'wp-i18n', 'heartbeat', 'jquery' ),
173 $built_version( 'assets/js/desktop' . $suffix . '.js' ),
174 true
175 );
176
177 // `desktop-mode-iframe-bridge` — opt-in iframe-side bridge that
178 // provides `wp.desktop.iframe.publish/subscribe/onConnection/
179 // requestConnection` to any same-origin iframe that enqueues it.
180 // Same code is also injected inline by the chromeless bridge
181 // (so chromeless wp-admin pages don't need a separate enqueue)
182 // and auto-injected when a native window opts in via
183 // `iframeContent: { bridge: true }`. Plugins targeting their
184 // own iframe pages just enqueue this handle.
185 wp_register_script(
186 'desktop-mode-iframe-bridge',
187 DESKTOP_MODE_URL . 'assets/js/iframe-bridge' . $suffix . '.js',
188 array(),
189 $built_version( 'assets/js/iframe-bridge' . $suffix . '.js' ),
190 true
191 );
192
193 // `desktop-mode-gutenberg-drop-receiver` — iframe-side bundle
194 // enqueued only on the Block Editor screens (`post.php` /
195 // `post-new.php`) for desktop-mode users. Listens for
196 // `desktop-mode-drop` postMessages from the parent shell (see
197 // `src/drag/iframe-drop-targets.ts`) and inserts the matching
198 // Gutenberg block via `wp.data.dispatch('core/block-editor')`.
199 // Depends on `wp-blocks` + `wp-data` so the editor stores are
200 // guaranteed enqueued before the receiver runs its first message
201 // handler.
202 wp_register_script(
203 'desktop-mode-gutenberg-drop-receiver',
204 DESKTOP_MODE_URL . 'assets/js/gutenberg-drop-receiver' . $suffix . '.js',
205 array( 'wp-blocks', 'wp-data' ),
206 $built_version( 'assets/js/gutenberg-drop-receiver' . $suffix . '.js' ),
207 true
208 );
209
210 // `desktop-mode-recycle-bin` — small bundle for the Recycle Bin
211 // native window. Lazy-loaded by the native-window sync the first
212 // time the bin opens; registers a render callback on
213 // `window.desktopModeNativeWindows['desktop-mode-recycle-bin']`.
214 $recycle_bin_js = DESKTOP_MODE_DIR . 'assets/js/recycle-bin' . $suffix . '.js';
215 wp_register_script(
216 'desktop-mode-recycle-bin',
217 DESKTOP_MODE_URL . 'assets/js/recycle-bin' . $suffix . '.js',
218 // `heartbeat` + `jquery` — the bin opts in to the WordPress
219 // Heartbeat API while its window is open as the catch-all
220 // real-time channel for deletes that don't render an admin
221 // footer (REST/AJAX/other tabs/WP-CLI). See
222 // `src/recycle-bin/realtime.ts` for the subscriber.
223 array( 'wp-i18n', 'heartbeat', 'jquery' ),
224 file_exists( $recycle_bin_js ) ? (string) filemtime( $recycle_bin_js ) : $version,
225 true
226 );
227 wp_set_script_translations(
228 'desktop-mode-recycle-bin',
229 'desktop-mode',
230 DESKTOP_MODE_DIR . 'languages'
231 );
232
233 // `desktop-mode-posts-window` — small bundle for the native Posts
234 // window. Lazy-loaded by the native-window sync the first time the
235 // window opens (via the dock-click swap when the user opts in);
236 // registers a render callback on
237 // `window.desktopModeNativeWindows['desktop-mode-posts']`.
238 $posts_window_js = DESKTOP_MODE_DIR . 'assets/js/posts-window' . $suffix . '.js';
239 wp_register_script(
240 'desktop-mode-posts-window',
241 DESKTOP_MODE_URL . 'assets/js/posts-window' . $suffix . '.js',
242 array( 'wp-i18n' ),
243 file_exists( $posts_window_js ) ? (string) filemtime( $posts_window_js ) : $version,
244 true
245 );
246 wp_set_script_translations(
247 'desktop-mode-posts-window',
248 'desktop-mode',
249 DESKTOP_MODE_DIR . 'languages'
250 );
251
252 // `desktop-mode-plugins-window` — small bundle for the native
253 // Plugins window. Lazy-loaded by the native-window sync the first
254 // time the window opens (via the dock-click swap when the user
255 // opts in); registers a render callback on
256 // `window.desktopModeNativeWindows['desktop-mode-plugins']`.
257 $plugins_window_js = DESKTOP_MODE_DIR . 'assets/js/plugins-window' . $suffix . '.js';
258 wp_register_script(
259 'desktop-mode-plugins-window',
260 DESKTOP_MODE_URL . 'assets/js/plugins-window' . $suffix . '.js',
261 array( 'wp-i18n' ),
262 file_exists( $plugins_window_js ) ? (string) filemtime( $plugins_window_js ) : $version,
263 true
264 );
265 wp_set_script_translations(
266 'desktop-mode-plugins-window',
267 'desktop-mode',
268 DESKTOP_MODE_DIR . 'languages'
269 );
270
271 // `desktop-mode-comments-window` — small bundle for the native
272 // Comments window. Lazy-loaded by the native-window sync the first
273 // time the window opens (via the dock-click swap when the user
274 // opts in); registers a render callback on
275 // `window.desktopModeNativeWindows['desktop-mode-comments']`.
276 $comments_window_js = DESKTOP_MODE_DIR . 'assets/js/comments-window' . $suffix . '.js';
277 wp_register_script(
278 'desktop-mode-comments-window',
279 DESKTOP_MODE_URL . 'assets/js/comments-window' . $suffix . '.js',
280 array( 'wp-i18n' ),
281 file_exists( $comments_window_js ) ? (string) filemtime( $comments_window_js ) : $version,
282 true
283 );
284 wp_set_script_translations(
285 'desktop-mode-comments-window',
286 'desktop-mode',
287 DESKTOP_MODE_DIR . 'languages'
288 );
289
290 // `desktop-mode-animated-logo-wallpaper` — built-in PixiJS canvas
291 // wallpaper, moved out of `desktop.min.js` in 0.8.4. The wallpaper
292 // `server-sync` loads this handle when the user selects the
293 // `wp-animated-logo` wallpaper (or opens OS Settings → Wallpaper
294 // and the picker pulls every registered canvas def in). The
295 // bundle's only side effect is publishing the `WallpaperDef` on
296 // `window.desktopModeWallpapers['wp-animated-logo']`.
297 $animated_logo_js = DESKTOP_MODE_DIR . 'assets/js/animated-logo-wallpaper' . $suffix . '.js';
298 wp_register_script(
299 'desktop-mode-animated-logo-wallpaper',
300 DESKTOP_MODE_URL . 'assets/js/animated-logo-wallpaper' . $suffix . '.js',
301 array( 'wp-hooks' ),
302 file_exists( $animated_logo_js ) ? (string) filemtime( $animated_logo_js ) : $version,
303 true
304 );
305
306 // `desktop-mode-ai-assistant` — AI Copilot spotlight overlay,
307 // moved out of `desktop.min.js` in 0.8.4. The main bundle ships a
308 // stub matching the public `wp.desktop.ai` contract; the stub
309 // `<script>`-injects this handle the first time the user opens
310 // the assistant (Cmd+K or admin-bar button).
311 $ai_assistant_js = DESKTOP_MODE_DIR . 'assets/js/ai-assistant' . $suffix . '.js';
312 wp_register_script(
313 'desktop-mode-ai-assistant',
314 DESKTOP_MODE_URL . 'assets/js/ai-assistant' . $suffix . '.js',
315 array( 'wp-hooks', 'wp-i18n' ),
316 file_exists( $ai_assistant_js ) ? (string) filemtime( $ai_assistant_js ) : $version,
317 true
318 );
319 wp_set_script_translations(
320 'desktop-mode-ai-assistant',
321 'desktop-mode',
322 DESKTOP_MODE_DIR . 'languages'
323 );
324
325 // Wire the translation bundle to this script handle. WP looks
326 // for `languages/desktop-mode-{locale}-desktop-mode.json` and
327 // injects its `locale_data` into `wp.i18n` just before the
328 // script runs — so every `__()` call resolves to the right
329 // language without any runtime fetch.
330 wp_set_script_translations(
331 'desktop-mode',
332 'desktop-mode',
333 DESKTOP_MODE_DIR . 'languages'
334 );
335 }
336 add_action( 'init', 'desktop_mode_register_assets' );
337