1+ import GObject from 'gi://GObject' ;
2+ import St from 'gi://St' ;
3+ import Gio from 'gi://Gio' ;
4+ import GLib from 'gi://GLib' ;
5+
6+ import { Extension , gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js' ;
7+ import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js' ;
8+ import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js' ;
9+ import * as Main from 'resource:///org/gnome/shell/ui/main.js' ;
10+
11+
12+ class StreamControllerExtension extends Extension {
13+ enable ( ) {
14+ console . error ( 'Extension enabled 889900' ) ;
15+ this . _focusChangedSignalId = global . display . connect ( 'notify::focus-window' , this . _onFocusWindowChanged . bind ( this ) ) ;
16+
17+ this . _dbusImpl = Gio . DBusExportedObject . wrapJSObject ( `
18+ <node>
19+ <interface name='org.gnome.Shell.Extensions.StreamController'>
20+ <method name='GetFocusedWindow'>
21+ <arg type='s' name='window' direction='out'/>
22+ </method>
23+ <method name='GetAllWindows'>
24+ <arg type='s' name='window' direction='out'/>
25+ </method>
26+ <signal name='FocusedWindowChanged'>
27+ <arg type='s' name='new_window_name'/>
28+ </signal>
29+ <!-- Other methods and signals -->
30+ </interface>
31+ </node>` , this ) ;
32+ this . _dbusImpl . export ( Gio . DBus . session , '/org/gnome/Shell/Extensions/StreamController' ) ;
33+ console . error ( 'Extension enabled 889900' ) ;
34+ this . _currentTitle = null ;
35+ this . _currentWMClass = null ;
36+ }
37+
38+ disable ( ) {
39+ if ( this . _focusChangedSignalId ) {
40+ global . display . disconnect ( this . _focusChangedSignalId ) ;
41+ this . _focusChangedSignalId = null ;
42+ }
43+
44+ if ( this . _dbusImpl ) {
45+ this . _dbusImpl . unexport ( ) ;
46+ this . _dbusImpl = null ;
47+ }
48+
49+ this . handlerId = null ;
50+ }
51+
52+ GetFocusedWindow ( ) {
53+ var result = {
54+ wm_class : this . _currentWMClass ,
55+ title : this . _currentTitle
56+ }
57+ return JSON . stringify ( result ) ;
58+ }
59+
60+ GetAllWindows ( ) {
61+ const windows = global . get_window_actors ( ) ;
62+
63+ let window_list = [ ] ;
64+ for ( const window of windows ) {
65+ window_list . push ( {
66+ wm_class : window . meta_window . get_wm_class ( ) ,
67+ title : window . meta_window . get_title ( )
68+ } ) ;
69+ }
70+
71+ return JSON . stringify ( window_list ) ;
72+ }
73+
74+ _onFocusWindowChanged ( ) {
75+ let focusedWindow = global . display . focus_window ;
76+ let title = focusedWindow ? focusedWindow . get_title ( ) : null ;
77+ let wmClass = focusedWindow ? focusedWindow . get_wm_class ( ) : null ;
78+ // Main.notify("changed", "changed");
79+ // this._dbusImpl.emit_signal('FocusedWindowChanged', new GLib.Variant('(s)', [wmClass, title]));
80+ let result = {
81+ wm_class : wmClass ,
82+ title : title
83+ }
84+ this . _dbusImpl . emit_signal ( 'FocusedWindowChanged' , new GLib . Variant ( '(s)' , [ JSON . stringify ( result ) ] ) ) ;
85+ Main . notify ( "before emmit" , "before emmit" ) ;
86+ // Main.notify(wmClass, title);
87+ this . _currentTitle = title ;
88+ this . _currentWMClass = wmClass ;
89+
90+ }
91+ }
92+
93+ export default StreamControllerExtension ;
0 commit comments