一小波更新
							parent
							
								
									613d8070ed
								
							
						
					
					
						commit
						a08e1750e6
					
				
							
								
								
									
										46
									
								
								inject.js
								
								
								
								
							
							
						
						
									
										46
									
								
								inject.js
								
								
								
								
							|  | @ -167,7 +167,7 @@ window.native = new EventEmitter() | |||
| 
 | ||||
| Object.assign(native, { | ||||
|   quit() { | ||||
|     return handler('quit') | ||||
|     return handler('quit', {}, null) | ||||
|   }, | ||||
|   fs: { | ||||
|     read(filepath) {} | ||||
|  | @ -267,5 +267,49 @@ Object.assign(native, { | |||
|       return handler('tray', { action: 'set_status', value: status }) | ||||
|     } | ||||
|   }, | ||||
|   window: { | ||||
|     isVisible() { | ||||
|       return handler('window', { action: 'is_visible' }) | ||||
|     }, | ||||
|     toggleVisible() { | ||||
|       handler('window', { action: 'toggle_visible' }, null) | ||||
|     }, | ||||
|     hide() { | ||||
|       handler('window', { action: 'hide' }, null) | ||||
|     }, | ||||
|     show() { | ||||
|       handler('window', { action: 'show' }, null) | ||||
|     }, | ||||
|     fullscreen() { | ||||
|       handler('window', { action: 'fullscreen' }, null) | ||||
|     }, | ||||
|     unfullscreen() { | ||||
|       handler('window', { action: 'unfullscreen' }, null) | ||||
|     }, | ||||
|     maximize() { | ||||
|       handler('window', { action: 'maximize' }, null) | ||||
|     }, | ||||
|     unmaximize() { | ||||
|       handler('window', { action: 'unmaximize' }, null) | ||||
|     }, | ||||
|     setTitle(title = '') { | ||||
|       handler('window', { action: 'set_title', value: title }, null) | ||||
|     }, | ||||
|     resize(width = 0, height = 0) { | ||||
|       handler('window', { action: 'resize', value: { width, height } }, null) | ||||
|     }, | ||||
|     move(x = 0, y = 0) { | ||||
|       handler('window', { action: 'resize', value: { x, y } }, null) | ||||
|     }, | ||||
|     setOpacity(opacity = 1) { | ||||
|       handler('window', { action: 'set_opacity', value: opacity }, null) | ||||
|     }, | ||||
|     alwayOnTop(setting = true) { | ||||
|       handler('window', { action: 'set_keep_above', value: setting }, null) | ||||
|     }, | ||||
|     alwayOnBotttom(setting = true) { | ||||
|       handler('window', { action: 'set_keep_below', value: setting }, null) | ||||
|     } | ||||
|   }, | ||||
|   handler | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										110
									
								
								main.py
								
								
								
								
							
							
						
						
									
										110
									
								
								main.py
								
								
								
								
							|  | @ -84,7 +84,7 @@ class WebKitWindow(Gtk.Window): | |||
| 
 | ||||
|   def create_tray(self): | ||||
| 
 | ||||
|     if AppIndicator3 : | ||||
|     if not AppIndicator3 : | ||||
|       indicator = AppIndicator3.Indicator.new( | ||||
|         "youtube", | ||||
|         "youtube", | ||||
|  | @ -98,23 +98,29 @@ class WebKitWindow(Gtk.Window): | |||
|       # indicator.set_ordering_index(99) | ||||
|       indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) | ||||
|       # indicator.set_status(AppIndicator3.IndicatorStatus.ATTENTION) | ||||
|       menu = Gtk.Menu() | ||||
|       menu_items = Gtk.MenuItem.new_with_label("Toggle Floater") | ||||
|       menu.append(menu_items) | ||||
|       menu_items.connect("activate", self.toggle_visible) | ||||
| 
 | ||||
|       menu.show_all() | ||||
|       indicator.set_menu(menu)  | ||||
|       indicator.set_secondary_activate_target(menu_items) | ||||
|     else: | ||||
|       # windows 和 macos 必须传二进制图标, linux可传图标名称(自会去主题中找) | ||||
|       indicator = Gtk.StatusIcon.new_from_pixbuf(get_logo(32)) | ||||
|       # indicator = Gtk.StatusIcon.new_from_pixbuf(get_logo(32)) | ||||
|       # linux | ||||
|       indicator = Gtk.StatusIcon.new_from_icon_name('youtube') | ||||
|       # indicator = Gtk.StatusIcon.new_from_icon_name('youtube') | ||||
| 
 | ||||
|       # return indicator | ||||
|       indicator = Gtk.StatusIcon.new_from_icon_name('youtube') | ||||
|       indicator.connect('activate',  self.toggle_visible) | ||||
|     return indicator | ||||
|     # indicator = Gtk.StatusIcon.new_from_icon_name('youtube') | ||||
|     # indicator.connect('activate',  self.toggle_visible) | ||||
|     # return indicator | ||||
|    | ||||
| 
 | ||||
|   def toggle_visible(self, icon): | ||||
|     # trayIcon | ||||
|     print(icon) | ||||
| 
 | ||||
|     if self.is_active(): | ||||
|     if self.is_visible(): | ||||
|       self.hide() | ||||
|     else: | ||||
|       self.present() | ||||
|  | @ -138,6 +144,7 @@ class WebKitWindow(Gtk.Window): | |||
|     event = data.get('event') | ||||
|     callback = data.get('callback') | ||||
|     params = data.get('data') | ||||
|     output = None | ||||
| 
 | ||||
| 
 | ||||
|     match event: | ||||
|  | @ -145,8 +152,6 @@ class WebKitWindow(Gtk.Window): | |||
|         pass | ||||
| 
 | ||||
|       case 'clipboard': | ||||
|         output = None | ||||
| 
 | ||||
|         # 读文本 | ||||
|         if params['action'] == 'wait_for_text': | ||||
|           output = self.clipboard.wait_for_text() | ||||
|  | @ -176,9 +181,6 @@ class WebKitWindow(Gtk.Window): | |||
|         elif params['action'] == 'clear': | ||||
|           self.clipboard.clear() | ||||
| 
 | ||||
|         # 回调给前端 | ||||
|         if callback: | ||||
|           self.call_js(callback, output) | ||||
| 
 | ||||
|       # 退出app | ||||
|       case 'quit': | ||||
|  | @ -188,9 +190,7 @@ class WebKitWindow(Gtk.Window): | |||
|       case 'image': | ||||
|         filename = params['value'] | ||||
|         pixbuf = Pixbuf.new_from_file(filename) | ||||
|         image = pixbuf_to_dict(pixbuf, filename) | ||||
| 
 | ||||
|         self.call_js(callback, image) | ||||
|         output = pixbuf_to_dict(pixbuf, filename) | ||||
| 
 | ||||
| 
 | ||||
|       case 'monitor': | ||||
|  | @ -198,26 +198,20 @@ class WebKitWindow(Gtk.Window): | |||
|           display = Gdk.Display.get_default() | ||||
|           monitor_num = display.get_n_monitors() | ||||
|           monitors = [display.get_monitor(i) for i in range(monitor_num)] | ||||
|           monitors = [get_monitor_info(m) for m in monitors] | ||||
|           output = [get_monitor_info(m) for m in monitors] | ||||
|            | ||||
|           self.call_js(callback, monitors) | ||||
| 
 | ||||
|         elif params['action'] == 'get-primary': | ||||
|           display = Gdk.Display.get_default() | ||||
|           monitor = display.get_primary_monitor() | ||||
|           info = get_monitor_info(monitor) | ||||
| 
 | ||||
|           self.call_js(callback, info) | ||||
|           output = get_monitor_info(monitor) | ||||
| 
 | ||||
|       case 'keybinder': | ||||
|         output = None | ||||
|         keymap = params.get('value') | ||||
|         shortcut_callback = params.get('shortcut_callback') or '' | ||||
| 
 | ||||
|         if params['action'] == 'register': | ||||
|           # 绑定之前, 先解绑, 避免被重复绑定 | ||||
|           Keybinder.unbind(keymap) | ||||
|            | ||||
|           output = Keybinder.bind( | ||||
|             keymap, | ||||
|             lambda km : self.call_js(shortcut_callback) | ||||
|  | @ -230,10 +224,6 @@ class WebKitWindow(Gtk.Window): | |||
|         elif params['action'] == 'supported': | ||||
|           output = Keybinder.supported() | ||||
| 
 | ||||
|         # 有回调则返回结果 | ||||
|         if callback: | ||||
|           self.call_js(callback, output) | ||||
| 
 | ||||
| 
 | ||||
|       case 'tray': | ||||
|         if params['action'] == 'create': | ||||
|  | @ -242,13 +232,65 @@ class WebKitWindow(Gtk.Window): | |||
|         elif params['action'] == 'remove': | ||||
|           pass | ||||
| 
 | ||||
|         if callback : | ||||
|           self.call_js(callback, True) | ||||
| 
 | ||||
|       case 'window': | ||||
|         if params['action'] == 'fullscreen': | ||||
|           self.fullscreen() | ||||
| 
 | ||||
|         elif params['action'] == 'unfullscreen': | ||||
|           self.unfullscreen() | ||||
| 
 | ||||
|         elif params['action'] == 'maximize': | ||||
|           self.maximize() | ||||
| 
 | ||||
|         elif params['action'] == 'unmaximize': | ||||
|           self.unmaximize() | ||||
| 
 | ||||
|         elif params['action'] == 'set_title': | ||||
|           self.set_title(params['value'] or '') | ||||
| 
 | ||||
|         elif params['action'] == 'resize': | ||||
|           self.resize(params['value'].get('width'), params['value'].get('height')) | ||||
| 
 | ||||
|         elif params['action'] == 'set_opacity': | ||||
|           self.set_opacity(params['value']) | ||||
| 
 | ||||
|         elif params['action'] == 'set_keep_above': | ||||
|           self.set_keep_above(params['value']) | ||||
| 
 | ||||
|         elif params['action'] == 'set_keep_below': | ||||
|           self.set_keep_below(params['value']) | ||||
| 
 | ||||
|         elif params['action'] == 'move': | ||||
|           self.move(params['value'].get('x'), params['value'].get('y')) | ||||
| 
 | ||||
|         elif params['action'] == 'toggle_visible': | ||||
|           if self.is_visible(): | ||||
|             self.hide() | ||||
|           else: | ||||
|             self.present() | ||||
| 
 | ||||
|         elif params['action'] == 'hide': | ||||
|           self.hide() | ||||
| 
 | ||||
|         elif params['action'] == 'show': | ||||
|           self.present() | ||||
| 
 | ||||
|         elif params['action'] == 'is_visible': | ||||
|           output = self.is_visible() | ||||
|          | ||||
| 
 | ||||
| 
 | ||||
|          | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|       case _: | ||||
|         if callback : | ||||
|           res = {"foo": 123, "bar": (11,22,33)} | ||||
|           self.call_js(callback, res) | ||||
|         output = {"foo": 123, "bar": (11,22,33)} | ||||
|     # 有回调则返回结果 | ||||
|     if callback : | ||||
|       self.call_js(callback, output) | ||||
|        | ||||
| 
 | ||||
| def all_quit(win): | ||||
|  |  | |||
		Reference in New Issue