PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.9
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 0.8.6 All 33 releases
desktop-mode / includes / widgets / widget-focus-timer.php

widget-focus-timer.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.9, at includes/widgets/widget-focus-timer.php

91 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Focus Timer widget PHP registration.
4 *
5 * Registers the widget's JS bundle + CSS, enqueues the CSS eagerly on
6 * shell pages, and announces the widget to OpenStation so it appears in
7 * the widget picker. All behaviour lives in the JS
8 * (src/plugins/focus-timer-widget/); this file only declares the widget.
9 *
10 * The timer runs entirely in the browser — no REST routes, no server
11 * state, no external services — so the script declares no dependencies.
12 *
13 * @package OpenStation
14 */
15
16 defined( 'ABSPATH' ) || exit;
17
18 /**
19 * Register the Focus Timer widget's script + style handles.
20 *
21 * @return void
22 */
23 function openstation_register_focus_timer_widget_assets() {
24 $suffix = openstation_asset_suffix();
25 $version = defined( 'OPENSTATION_VERSION' ) ? OPENSTATION_VERSION : '0';
26
27 $js_path = OPENSTATION_DIR . 'assets/js/widget-focus-timer' . $suffix . '.js';
28 $css_path = OPENSTATION_DIR . 'assets/js/widget-focus-timer' . $suffix . '.css';
29
30 wp_register_style(
31 'os-focus-timer-widget',
32 OPENSTATION_URL . 'assets/js/widget-focus-timer' . $suffix . '.css',
33 array(),
34 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
35 );
36
37 wp_register_script(
38 'os-focus-timer-widget',
39 OPENSTATION_URL . 'assets/js/widget-focus-timer' . $suffix . '.js',
40 array(),
41 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
42 true
43 );
44 }
45 add_action( 'init', 'openstation_register_focus_timer_widget_assets', 5 );
46
47 /**
48 * Eagerly enqueue the CSS on OpenStation shell pages (avoids a flash of
49 * unstyled content before the lazy JS mounts).
50 *
51 * @return void
52 */
53 function openstation_enqueue_focus_timer_widget_styles() {
54 if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled() ) {
55 return;
56 }
57 if ( function_exists( 'openstation_is_chromeless_request' ) && openstation_is_chromeless_request() ) {
58 return;
59 }
60 wp_enqueue_style( 'os-focus-timer-widget' );
61 }
62 add_action( 'admin_enqueue_scripts', 'openstation_enqueue_focus_timer_widget_styles', 20 );
63
64 /**
65 * Announce the widget to OpenStation.
66 *
67 * @return void
68 */
69 function openstation_register_focus_timer_widget() {
70 if ( ! function_exists( 'openstation_register_widget' ) ) {
71 return;
72 }
73
74 openstation_register_widget(
75 'desktop-mode/focus-timer',
76 array(
77 'label' => __( 'Focus Timer', 'desktop-mode' ),
78 'description' => __( 'A focus countdown. Link it to a window and get a shake + alarm when time is up.', 'desktop-mode' ),
79 'icon' => 'dashicons-clock',
80 'script' => 'os-focus-timer-widget',
81 'movable' => true,
82 'resizable' => true,
83 'min_width' => 240,
84 'min_height' => 200,
85 'default_width' => 300,
86 'default_height' => 300,
87 )
88 );
89 }
90 add_action( 'init', 'openstation_register_focus_timer_widget', 6 );
91