Changeset 1097:f2ac841cffec


Ignore:
Timestamp:
08/11/23 14:39:35 (17 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

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

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • locale/en/mlx.po

    r1094 r1097  
    195195msgid "menu_tools_prefs_key"
    196196msgstr "p"
     197
     198msgid "menu_tools_clear_cef_cache"
     199msgstr "C_lear browser cache"
     200
     201msgid "clear_cef_cache_confirmation"
     202msgstr ""
     203"Are you sure to clear the browser cache?\n\n"
     204"If so, the program will quit and then restart."
    197205
    198206msgid "menu_tools_bugreport"
  • locale/hu/mlx.po

    r1094 r1097  
    195195msgid "menu_tools_prefs_key"
    196196msgstr "b"
     197
     198msgid "menu_tools_clear_cef_cache"
     199msgstr "Böngésző gyorsítótár _törlése"
     200
     201msgid "clear_cef_cache_confirmation"
     202msgstr ""
     203"Biztosan törölni szeretnéd a böngésző gyorsítótárát?\n\n"
     204"Ha igen, a program újra fog indulni."
    197205
    198206msgid "menu_tools_bugreport"
  • src/mlx/config.py

    r1094 r1097  
    222222        self._rememberPassword = False
    223223
     224        self._clearBrowserCacheOnStart = False
    224225        self._language = ""
    225226        self._hideMinimizedWindow = True
     
    310311
    311312    @property
     313    def clearBrowseCacheOnStart(self):
     314        """Get whether the browser cache should be cleared on start."""
     315        return self._clearBrowserCacheOnStart
     316
     317    @clearBrowseCacheOnStart.setter
     318    def clearBrowseCacheOnStart(self, clearBrowseCacheOnStart):
     319        """Set whether the browser cache should be cleared on start."""
     320        if clearBrowseCacheOnStart!=self._clearBrowserCacheOnStart:
     321            self._clearBrowserCacheOnStart = clearBrowseCacheOnStart
     322            self._modified = True
     323
     324    @property
    312325    def language(self):
    313326        """Get the language to use."""
     
    753766        self._rememberPassword = self._getBoolean(config, "login",
    754767                                                  "rememberPassword", False)
     768
     769        self._clearBrowserCacheOnStart = \
     770            self._getBoolean(config, "general",
     771                             "clearBrowseCacheOnStart", False)
    755772
    756773        self._language = self._get(config, "general", "language", "")
     
    863880
    864881        config.add_section("general")
     882        config.set("general", "clearBrowseCacheOnStart",
     883                   "yes" if self._clearBrowserCacheOnStart else "no")
    865884        if self._language:
    866885            config.set("general", "language", self._language)
     
    10341053        print("  rememberPassword:", self._rememberPassword)
    10351054
     1055        print("  clearBrowseCacheOnStart:", self._clearBrowserCacheOnStart)
    10361056        print("  language:", self._language)
    10371057
  • 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.