mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
console: observe state objects for changes, fire event to update status bar.
This commit is contained in:
parent
200498e7aa
commit
c9a0975446
@ -33,6 +33,10 @@ class ConsoleState(flow.State):
|
||||
|
||||
self.flowsettings = weakref.WeakKeyDictionary()
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
self.__dict__[name] = value
|
||||
signals.update_settings.send(self)
|
||||
|
||||
def add_flow_setting(self, flow, key, value):
|
||||
d = self.flowsettings.setdefault(flow, {})
|
||||
d[key] = value
|
||||
@ -212,6 +216,10 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.start_app(self.options.app_host, self.options.app_port)
|
||||
signals.call_in.connect(self.sig_call_in)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
self.__dict__[name] = value
|
||||
signals.update_settings.send(self)
|
||||
|
||||
def sig_call_in(self, sender, seconds, callback, args=()):
|
||||
def cb(*_):
|
||||
return callback(*args)
|
||||
@ -598,6 +606,7 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
elif a == "u":
|
||||
self.server.config.no_upstream_cert =\
|
||||
not self.server.config.no_upstream_cert
|
||||
signals.update_settings.send(self)
|
||||
|
||||
def shutdown(self):
|
||||
self.state.killall(self)
|
||||
|
@ -17,3 +17,6 @@ call_in = blinker.Signal()
|
||||
|
||||
# Focus the body, footer or header of the main window
|
||||
focus = blinker.Signal()
|
||||
|
||||
# Fired when settings change
|
||||
update_settings = blinker.Signal()
|
||||
|
@ -113,6 +113,10 @@ class StatusBar(urwid.WidgetWrap):
|
||||
self.ab = ActionBar()
|
||||
self.ib = urwid.WidgetWrap(urwid.Text(""))
|
||||
self._w = urwid.Pile([self.ib, self.ab])
|
||||
signals.update_settings.connect(self.sig_update_settings)
|
||||
|
||||
def sig_update_settings(self, sender):
|
||||
self.redraw()
|
||||
|
||||
def keypress(self, *args, **kwargs):
|
||||
return self.ab.keypress(*args, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user