Ignore:
Timestamp:
08/11/23 14:39:35 (9 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The browser cache can be cleared from the menu (re #368)

Location:
src/mlx/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/acars.py

    r1083 r1097  
    2727        super(ACARS, self).__init__()
    2828        self._gui = gui
     29        self._container = None
    2930        self._browser = None
    3031
    3132    def start(self):
    3233        """Start the browser."""
    33         container = cef.getContainer()
     34        self._container = cef.getContainer()
     35        self.pack_start(self._container, True, True, 0)
    3436
    35         self.pack_start(container, True, True, 0)
    36 
    37         self._browser = cef.startInContainer(container, ACARS.URL)
     37        self._browser = cef.startInContainer(self._container, ACARS.URL)
    3838
    3939    def stop(self):
    4040        """Close the browser."""
    4141        if self._browser is not None:
    42             self._browser.CloseBrowser(False)
     42            self._browser.CloseBrowser(True)
    4343            self._browser = None
     44
     45        if self._container is not None:
     46            self.remove(self._container)
     47            self._container = None
  • src/mlx/gui/cef.py

    r1096 r1097  
    3434# The SimBrief handler
    3535_simBriefHandler = None
     36
     37# The cache directory
     38cacheDir = os.path.join(GLib.get_user_cache_dir(), "mlxcef")
    3639
    3740#------------------------------------------------------------------------------
     
    222225    print("Initializing CEF with args:", args)
    223226
    224     cacheDir = os.path.join(GLib.get_user_cache_dir(), "mlxcef")
    225 
    226     try:
    227         shutil.rmtree(cacheDir)
    228         print("gui.cef._initializeCEF1: the cache directory is removed")
    229     except Exception as e:
    230         print("gui.cef._initializeCEF1: cache directory removal failed:", e)
    231 
    232227    settings = {
    233228        "debug": True, # cefpython debug messages in console and in log_file
     
    241236            (cefpython.GetModuleDirectory(), "subprocess"),
    242237        "windowless_rendering_enabled": True,
    243         "cache_path": cacheDir
     238        "cache_path": cacheDir,
     239        "persist_session_cookies": True,
     240        "persist_user_preferences": True
    244241    }
    245242
     
    378375#------------------------------------------------------------------------------
    379376
     377def finalizeSimBrief():
     378    """Finallize the (hidden) browser window for SimBrief."""
     379    if _simBriefHandler is not None:
     380        _simBriefHandler.finalize()
     381
     382#------------------------------------------------------------------------------
     383
    380384def finalize():
    381385    """Finalize the Chrome Embedded Framework."""
     
    383387    _toQuit = True
    384388
    385     _simBriefHandler.finalize()
    386 
    387     cefpython.Shutdown()
     389    if os.name!="nt":
     390        cefpython.Shutdown()
     391
     392#------------------------------------------------------------------------------
     393
     394def clearCache():
     395    """Clear the CEF cache directory."""
     396    try:
     397        shutil.rmtree(cacheDir)
     398        print("gui.cef.clearCache: the cache directory is removed")
     399    except Exception as e:
     400        print("gui.cef.clearCache: cache directory removal failed:", e)
    388401
    389402#------------------------------------------------------------------------------
  • src/mlx/gui/flight.py

    r1087 r1097  
    40014001        self._container.hide()
    40024002        self._browser = None
     4003
     4004    def finalizeCEF(self):
     4005        """Close the CEF browser."""
     4006        if self._browser is not None:
     4007            self._container.hide()
     4008            self._browser.CloseBrowser(True)
     4009            self._browser = None
    40034010
    40044011#-----------------------------------------------------------------------------
     
    67396746        self.gui.rtoToggled(indicated)
    67406747
     6748    def finalizeCEF(self):
     6749        """Called when any CEF browsers should be finalized."""
     6750        self._simBriefingPage.finalizeCEF()
     6751
    67416752    def _connectSimulator(self, simulatorType):
    67426753        """Connect to the simulator."""
  • src/mlx/gui/gui.py

    r1083 r1097  
    480480            self.updateDone()
    481481
     482        if self.config.clearBrowseCacheOnStart:
     483            cef.clearCache()
     484            self.config.clearBrowseCacheOnStart = False
     485
    482486        singleton.raiseCallback = self.raiseCallback
    483487        Gtk.main()
    484488        singleton.raiseCallback = None
    485489
     490        self._wizard.finalizeCEF()
     491        cef.finalizeSimBrief()
    486492        self._acars.stop()
    487493
     
    855861            self.showMonitorWindow()
    856862
    857     def restart(self):
     863    def restart(self, clearCEFCache = False):
    858864        """Quit and restart the application."""
    859865        self.toRestart = True
     866        self.config.clearBrowseCacheOnStart = clearCEFCache
    860867        self._quit(force = True)
    861868
     
    11771184        toolsMenu.append(Gtk.SeparatorMenuItem())
    11781185
     1186        clearCEFCacheMenuItem = Gtk.ImageMenuItem(Gtk.STOCK_DISCARD)
     1187        clearCEFCacheMenuItem.set_use_stock(True)
     1188        clearCEFCacheMenuItem.set_label(xstr("menu_tools_clear_cef_cache"))
     1189        clearCEFCacheMenuItem.connect("activate", self._clearCEFCache)
     1190        toolsMenu.append(clearCEFCacheMenuItem)
     1191
     1192        toolsMenu.append(Gtk.SeparatorMenuItem())
     1193
    11791194        bugReportMenuItem = Gtk.ImageMenuItem(Gtk.STOCK_PASTE)
    11801195        bugReportMenuItem.set_use_stock(True)
     
    14191434        self._setupTimeSync()
    14201435        self._listenHotkeys()
     1436
     1437    def _clearCEFCache(self, menuItem):
     1438        """Callback for clearing the CEF cache."""
     1439        if askYesNo(xstr("clear_cef_cache_confirmation"),
     1440                    parent = self._mainWindow):
     1441            self.restart(clearCEFCache = True)
    14211442
    14221443    def _reportBug(self, menuItem):
Note: See TracChangeset for help on using the changeset viewer.