fix restarting after refresh
This commit is contained in:
parent
f5f8a8a75c
commit
f6757af8d1
|
@ -122,13 +122,7 @@ class Application:
|
|||
|
||||
# EventLoop -------------------------------------------------------------------
|
||||
|
||||
def _remove_last_screen(self):
|
||||
last_screen = self.state_path('last-screen')
|
||||
if os.path.exists(last_screen):
|
||||
os.unlink(last_screen)
|
||||
|
||||
def exit(self):
|
||||
self._remove_last_screen()
|
||||
self.aio_loop.stop()
|
||||
|
||||
def start_controllers(self):
|
||||
|
@ -145,24 +139,11 @@ class Application:
|
|||
with open(state_path) as fp:
|
||||
controller.deserialize(json.load(fp))
|
||||
|
||||
last_screen = None
|
||||
state_path = self.state_path('last-screen')
|
||||
if os.path.exists(state_path):
|
||||
with open(state_path) as fp:
|
||||
last_screen = fp.read().strip()
|
||||
controller_index = 0
|
||||
for i, controller in enumerate(self.controllers.instances):
|
||||
if controller.name == last_screen:
|
||||
controller_index = i
|
||||
# Screens that have already been seen should be marked as configured.
|
||||
for controller in self.controllers.instances[:controller_index]:
|
||||
controller.configured()
|
||||
return controller_index
|
||||
|
||||
def run(self):
|
||||
self.base_model = self.make_model()
|
||||
try:
|
||||
self.controllers.load_all()
|
||||
self.load_serialized_state()
|
||||
self._connect_base_signals()
|
||||
self.start_controllers()
|
||||
self.aio_loop.run_forever()
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import yaml
|
||||
|
||||
import urwid
|
||||
|
@ -68,6 +69,15 @@ class TuiApplication(Application):
|
|||
|
||||
self.urwid_loop = None
|
||||
|
||||
def _remove_last_screen(self):
|
||||
last_screen = self.state_path('last-screen')
|
||||
if os.path.exists(last_screen):
|
||||
os.unlink(last_screen)
|
||||
|
||||
def exit(self):
|
||||
self._remove_last_screen()
|
||||
super().exit()
|
||||
|
||||
def run_command_in_foreground(self, cmd, before_hook=None, after_hook=None,
|
||||
**kw):
|
||||
screen = self.urwid_loop.screen
|
||||
|
@ -129,6 +139,8 @@ class TuiApplication(Application):
|
|||
self._move_screen(-1)
|
||||
|
||||
def select_initial_screen(self, controller_index):
|
||||
for controller in self.controllers.instances[:controller_index]:
|
||||
controller.configured()
|
||||
self.controllers.index = controller_index - 1
|
||||
self.next_screen()
|
||||
|
||||
|
@ -237,17 +249,27 @@ class TuiApplication(Application):
|
|||
self.toggle_rich()
|
||||
self.urwid_loop.start()
|
||||
|
||||
def initial_controller_index(self):
|
||||
if not self.updated:
|
||||
return 0
|
||||
state_path = self.state_path('last-screen')
|
||||
if not os.path.exists(state_path):
|
||||
return 0
|
||||
with open(state_path) as fp:
|
||||
last_screen = fp.read().strip()
|
||||
controller_index = 0
|
||||
for i, controller in enumerate(self.controllers.instances):
|
||||
if controller.name == last_screen:
|
||||
controller_index = i
|
||||
return controller_index
|
||||
|
||||
def run(self):
|
||||
if self.opts.scripts:
|
||||
self.run_scripts(self.opts.scripts)
|
||||
self.aio_loop.call_soon(self.start_urwid)
|
||||
|
||||
initial_controller_index = 0
|
||||
if self.updated:
|
||||
initial_controller_index = self.load_serialized_state()
|
||||
self.aio_loop.call_soon(
|
||||
self.select_initial_screen, initial_controller_index)
|
||||
|
||||
lambda: self.select_initial_screen(
|
||||
self.initial_controller_index()))
|
||||
try:
|
||||
super().run()
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue