PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.7
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 / widgets / widget-focus-timer.php

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

98 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — 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 Desktop Mode 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 WPDesktopMode
14 * @since 0.26.0
15 */
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Register the Focus Timer widget's script + style handles.
21 *
22 * @since 0.26.0
23 *
24 * @return void
25 */
26 function desktop_mode_register_focus_timer_widget_assets() {
27 $suffix = desktop_mode_asset_suffix();
28 $version = defined( 'DESKTOP_MODE_VERSION' ) ? DESKTOP_MODE_VERSION : '0';
29
30 $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-focus-timer' . $suffix . '.js';
31 $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-focus-timer' . $suffix . '.css';
32
33 wp_register_style(
34 'desktop-mode-focus-timer-widget',
35 DESKTOP_MODE_URL . 'assets/js/widget-focus-timer' . $suffix . '.css',
36 array(),
37 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
38 );
39
40 wp_register_script(
41 'desktop-mode-focus-timer-widget',
42 DESKTOP_MODE_URL . 'assets/js/widget-focus-timer' . $suffix . '.js',
43 array(),
44 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
45 true
46 );
47 }
48 add_action( 'init', 'desktop_mode_register_focus_timer_widget_assets', 5 );
49
50 /**
51 * Eagerly enqueue the CSS on Desktop Mode shell pages (avoids a flash of
52 * unstyled content before the lazy JS mounts).
53 *
54 * @since 0.26.0
55 *
56 * @return void
57 */
58 function desktop_mode_enqueue_focus_timer_widget_styles() {
59 if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
60 return;
61 }
62 if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) {
63 return;
64 }
65 wp_enqueue_style( 'desktop-mode-focus-timer-widget' );
66 }
67 add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_focus_timer_widget_styles', 20 );
68
69 /**
70 * Announce the widget to Desktop Mode.
71 *
72 * @since 0.26.0
73 *
74 * @return void
75 */
76 function desktop_mode_register_focus_timer_widget() {
77 if ( ! function_exists( 'desktop_mode_register_widget' ) ) {
78 return;
79 }
80
81 desktop_mode_register_widget(
82 'desktop-mode/focus-timer',
83 array(
84 'label' => __( 'Focus Timer', 'desktop-mode' ),
85 'description' => __( 'A focus countdown. Link it to a window and get a shake + alarm when time is up.', 'desktop-mode' ),
86 'icon' => 'dashicons-clock',
87 'script' => 'desktop-mode-focus-timer-widget',
88 'movable' => true,
89 'resizable' => true,
90 'min_width' => 240,
91 'min_height' => 200,
92 'default_width' => 300,
93 'default_height' => 300,
94 )
95 );
96 }
97 add_action( 'init', 'desktop_mode_register_focus_timer_widget', 6 );
98