Files
meta-gnome-forks/recipes-cinnamon/cinnamon/cinnamon/okaestne-settings-performance/0002-cs_privacy-defer-init-of-NM.Client.patch
Andreas Müller 41880e3a91 cinnamon: Add patches to accelerate settings
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
2022-05-05 23:40:54 +02:00

98 lines
3.9 KiB
Diff

From b20036b87aa78242e11b4e5f023b4f8586cfe1d9 Mon Sep 17 00:00:00 2001
From: okaestne <git@oliver-kaestner.de>
Date: Sun, 3 Apr 2022 17:49:43 +0200
Subject: [PATCH 2/6] cs_privacy: defer init of NM.Client
saves ~10ms import time
also fix some imports
---
.../cinnamon-settings/modules/cs_privacy.py | 43 +++++++++++--------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/files/usr/share/cinnamon/cinnamon-settings/modules/cs_privacy.py b/files/usr/share/cinnamon/cinnamon-settings/modules/cs_privacy.py
index a726b0776..26693b230 100755
--- a/files/usr/share/cinnamon/cinnamon-settings/modules/cs_privacy.py
+++ b/files/usr/share/cinnamon/cinnamon-settings/modules/cs_privacy.py
@@ -1,26 +1,16 @@
#!/usr/bin/python3
-
-nm_client = None
-try:
- import gi
- gi.require_version('NM', '1.0')
- from gi.repository import NM
- nm_client = NM.Client.new(None)
- # call connectivity_check_get_available to make
- # sure it's available (it's new in libnm 1.10)
- # if it's not, we catch the exception and set
- # the client to None
- nm_client.connectivity_check_get_available()
-except:
- nm_client = None
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gio, Gtk
from SettingsWidgets import SidePage
-from xapp.GSettingsWidgets import *
+from xapp.GSettingsWidgets import GSettingsSwitch, SettingsLabel, SettingsPage, SettingsRevealer, SettingsWidget, Switch
PRIVACY_SCHEMA = "org.cinnamon.desktop.privacy"
GTK_RECENT_ENABLE_KEY = "remember-recent-files"
GTK_RECENT_MAX_AGE = "recent-files-max-age"
+
class Module:
name = "privacy"
comment = _("Cinnamon privacy settings")
@@ -31,6 +21,19 @@ class Module:
sidePage = SidePage(_("Privacy"), "cs-privacy", keywords, content_box, module=self)
self.sidePage = sidePage
self.settings = Gio.Settings(schema=PRIVACY_SCHEMA)
+ self.nm_client = None
+
+ def _init_nm_client(self):
+ try:
+ gi.require_version('NM', '1.0')
+ from gi.repository import NM
+ nm_client = NM.Client.new()
+
+ # we need libnm >=1.10
+ if hasattr(nm_client, 'connectivity_check_get_available'):
+ self.nm_client = nm_client
+ except ValueError:
+ pass
def on_module_selected(self):
if not self.loaded:
@@ -77,14 +80,16 @@ class Module:
else:
self.indefinite_switch.content_widget.set_active(False)
self.revealer.set_reveal_child(True)
- if start_age == 0: # Shouldn't happen, unless someone manually sets the value
+ if start_age == 0: # Shouldn't happen, unless someone manually sets the value
self.settings.set_int(GTK_RECENT_MAX_AGE, 30)
self.bind_spinner()
- if nm_client is not None and nm_client.connectivity_check_get_available():
+ self._init_nm_client()
+
+ if self.nm_client is not None and self.nm_client.connectivity_check_get_available():
section = page.add_section(_("Internet connectivity"))
connectivity_switch = Switch(_("Check connectivity"))
- connectivity_switch.content_widget.set_active(nm_client.connectivity_check_get_enabled())
+ connectivity_switch.content_widget.set_active(self.nm_client.connectivity_check_get_enabled())
connectivity_switch.content_widget.connect("notify::active", self.on_connectivity_toggled)
section.add_row(connectivity_switch)
section.add_note(_("Check that network connections can reach the Internet. This makes it possible to detect captive portals, but also generates periodic network traffic."))
@@ -117,4 +122,4 @@ class Module:
def on_connectivity_toggled(self, widget, gparam):
active = widget.get_active()
- nm_client.connectivity_check_set_enabled(active)
+ self.nm_client.connectivity_check_set_enabled(active)
--
2.34.1