diff --git a/sleex-user-config/src/.config/hypr/hyprland/keybinds_fr.conf b/sleex-user-config/src/.config/hypr/hyprland/keybinds_fr.conf index a1a5aa0..2bd6d9c 100644 --- a/sleex-user-config/src/.config/hypr/hyprland/keybinds_fr.conf +++ b/sleex-user-config/src/.config/hypr/hyprland/keybinds_fr.conf @@ -73,6 +73,7 @@ bind = Super+Shift+Alt, R, exec, /usr/share/sleex/scripts/record-script.sh --ful ##! Session # bind = Super, L, exec, hyprlock # Lock session bind = Super, L, global, quickshell:lockScreen # Lock session +bind = Super, M, exec, ~/.config/hypr/custom/scripts/Insomnia.sh # Toggle Insomnia Mode #! ##! Window management diff --git a/src/share/sleex/modules/common/Config.qml b/src/share/sleex/modules/common/Config.qml index b5b1ca1..42c6f7e 100644 --- a/src/share/sleex/modules/common/Config.qml +++ b/src/share/sleex/modules/common/Config.qml @@ -132,7 +132,8 @@ Singleton { property string avatarPath: "file:///usr/share/sleex/assets/logo/1024px/white.png" property string userDesc: "Today is a good day to have a good day!" property bool enableWeather: false - property string weatherLocation: "" // :) + property string weatherLocation: "" + property string customDNS: "" } property JsonObject dock: JsonObject { diff --git a/src/share/sleex/modules/settings/Privacy.qml b/src/share/sleex/modules/settings/Privacy.qml index 07d7475..a64aff3 100644 --- a/src/share/sleex/modules/settings/Privacy.qml +++ b/src/share/sleex/modules/settings/Privacy.qml @@ -10,40 +10,37 @@ ContentPage { ContentSection { title: "Policies" + ContentSubsectionLabel { text: "AI" } + ConfigSelectionArray { currentValue: Config.options.policies.ai onSelected: newValue => { Config.options.policies.ai = newValue; } options: [ - { - displayName: "No", - value: 0 - }, - { - displayName: "Yes", - value: 1 - }, - { - displayName: "Local only", - value: 2 - } + { displayName: "No", value: 0 }, + { displayName: "Yes", value: 1 }, + { displayName: "Local only", value: 2 } ] } + } + + ContentSection { + title: "Weather" - ContentSubsectionLabel { - text: "Weather" - } ConfigSwitch { id: weatherSwitch text: "Enabled" checked: Config.options.dashboard.enableWeather onClicked: checked = !checked; onCheckedChanged: Config.options.dashboard.enableWeather = checked - StyledToolTip { content: "The weather module uses your approximate location based on your local IP. It uses the https://wttr.in provider." } + + StyledToolTip { + content: "The weather module uses your approximate location based on your local IP. It uses the https://wttr.in provider." + } } MaterialTextField { @@ -59,4 +56,27 @@ ContentPage { } } } + + ContentSection { + title: "DNS" + + + MaterialTextField { + id: customDNS + Layout.fillWidth: true + placeholderText: "DNS Server" + text: Config.options.dashboard.customDNS + wrapMode: TextEdit.Wrap + + onEditingFinished: { + // Save the value + Config.options.dashboard.customDNS = text + + // Run the Python script + Quickshell.execDetached(["python", "/usr/share/sleex/scripts/set-dns.py"]) + + } + } + + } } diff --git a/src/share/sleex/scripts/set-dns.py b/src/share/sleex/scripts/set-dns.py new file mode 100644 index 0000000..3fb4109 --- /dev/null +++ b/src/share/sleex/scripts/set-dns.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +import subprocess +import json +import os +import getpass + +# Path to the settings JSON +CONFIG_FILE = os.path.expanduser("~/.sleex/settings.json") + +def run_cmd(cmd, capture_output=True): + """Run a shell command and return its output.""" + result = subprocess.run(cmd, shell=True, text=True, + capture_output=capture_output) + if result.returncode != 0: + return None + return result.stdout.strip() + +def get_custom_dns(): + """Read customDNS from settings.json.""" + if not os.path.exists(CONFIG_FILE): + print(f"Settings file not found: {CONFIG_FILE}") + return None + try: + with open(CONFIG_FILE, "r") as f: + config = json.load(f) + # Navigate to dashboard.customDNS + dns = config.get("dashboard", {}).get("customDNS", "").strip() + if dns: + return dns + else: + print("customDNS is empty in settings.json") + return None + except Exception as e: + print(f"Failed to read settings.json: {e}") + return None + +def main(): + dns_server = get_custom_dns() + if not dns_server: + print("Please set a custom DNS in ~/.sleex/settings.json under dashboard.customDNS") + return + + # Detect the active connection + active_conn_cmd = "nmcli -t -f NAME,DEVICE connection show --active | head -n1 | cut -d: -f1" + active_conn = run_cmd(active_conn_cmd) + if not active_conn: + print("No active network connection found.") + return + + print(f"Setting DNS {dns_server} for connection '{active_conn}'...") + + # Check connection type + con_type_cmd = f"nmcli -g connection.type connection show '{active_conn}'" + con_type = run_cmd(con_type_cmd) + + # If Wi-Fi, check for PSK + if con_type == "wifi": + psk_cmd = f"nmcli -g 802-11-wireless-security.psk connection show '{active_conn}'" + psk = run_cmd(psk_cmd) + if not psk: + psk = getpass.getpass("Wi-Fi password not found. Please enter it: ") + subprocess.run(f"nmcli connection modify '{active_conn}' wifi-sec.psk '{psk}'", shell=True) + + # Set the DNS and ignore auto DNS + set_dns_cmd = f"nmcli connection modify '{active_conn}' ipv4.dns '{dns_server}' ipv4.ignore-auto-dns yes" + if run_cmd(set_dns_cmd) is None: + print(f"Failed to set DNS {dns_server} for connection '{active_conn}'.") + return + + # Reactivate the connection + subprocess.run(f"nmcli connection down '{active_conn}'", shell=True) + subprocess.run(f"nmcli connection up '{active_conn}'", shell=True) + + print("DNS updated successfully.") + subprocess.run("nmcli dev show | grep DNS", shell=True) + +if __name__ == "__main__": + main()