diff --git a/PKGBUILD b/PKGBUILD index 35e8978..af6854d 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -7,6 +7,7 @@ arch=('x86_64') url="https://git.trom.tf/TROMjaro/layout-switcher-package" license=(unknown) depends=('xfce4-panel-profiles' + 'vala-panel-appmenu-registrar' 'util-linux' 'xfconf' 'polkit' @@ -28,6 +29,7 @@ source=("layoutSwitcher.nim" "sharedModule.nim" "tromjaro-layout-switcher.desktop" "com.tromjaro.LayoutSwitcher.policy" + "disable-global-menu.hook" "tromjaro-layout-switcher.svg" "icons.zip::https://www.drive.tromsite.com/s/SWmAcokLcxLB3gM/download" "profiles.zip::https://www.drive.tromsite.com/s/6dHoNjar9wJzeLd/download") @@ -38,6 +40,7 @@ sha256sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' +'SKIP' 'SKIP') prepare() { # Disable telemetry in choosenim if user is running it for the first time @@ -69,6 +72,9 @@ package() { install -d ${pkgdir}/usr/share/tromjaro-layout-switcher/profiles install -Dm644 ${srcdir}/profiles/* ${pkgdir}/usr/share/tromjaro-layout-switcher/profiles + # copy pacman hook file + install -Dm644 ${srcdir}/disable-global-menu.hook ${pkgdir}/usr/share/tromjaro-layout-switcher + # copy executables install -d ${pkgdir}/usr/share/applications install -Dm644 ${srcdir}/tromjaro-layout-switcher.desktop ${pkgdir}/usr/share/applications diff --git a/com.tromjaro.LayoutSwitcher.policy b/com.tromjaro.LayoutSwitcher.policy index a5124ca..26350d4 100644 --- a/com.tromjaro.LayoutSwitcher.policy +++ b/com.tromjaro.LayoutSwitcher.policy @@ -7,8 +7,8 @@ https://www.tromjaro.com/ tromjaro-layout-switcher - Install or remove global menu - Authentication is required to install/remove global menu + Enable or disable global menu + Authentication is required to enable/disable global menu auth_admin auth_admin diff --git a/disable-global-menu.hook b/disable-global-menu.hook new file mode 100644 index 0000000..41cb1ec --- /dev/null +++ b/disable-global-menu.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Upgrade +Operation = Install +Type = Package +Target = vala-panel-appmenu-registrar + +[Action] +Description = Disabling global menu... +When = PostTransaction +Exec = /usr/bin/toggle-global-menu disable diff --git a/layoutSwitcher.nim b/layoutSwitcher.nim index 0c6c8ba..c8bfab1 100644 --- a/layoutSwitcher.nim +++ b/layoutSwitcher.nim @@ -37,7 +37,7 @@ proc enableTopBarIntegration(): bool = sendNotification(appID, "Layout Switcher", "Authentication failed!") return false else: - sendNotification(appID, "Failed installing global menu!", "Make sure that you are not currently installing any apps or updating the system.\nEnabling internet connection might solve the issue.") + sendNotification(appID, "Layout Switcher", "Failed to enable global menu!") return false # Hide window borders when maximized discard runCommand("/usr/bin/xfconf-query", @@ -62,7 +62,7 @@ proc disableTopBarIntegration(): bool = of 127: sendNotification(appID, "Layout Switcher", "Authentication failed!") else: - sendNotification(appID, "Failed removing global menu!", "Make sure that you are not currently installing any apps or updating the system.") + sendNotification(appID, "Layout Switcher", "Failed to disable global menu!") return false # Hide window borders when maximized discard runCommand("/usr/bin/xfconf-query", diff --git a/sharedModule.nim b/sharedModule.nim index 6c079ec..c64f90f 100644 --- a/sharedModule.nim +++ b/sharedModule.nim @@ -1,4 +1,5 @@ from std/osproc import startProcess, ProcessOption, waitForExit, close +from std/os import fileExists proc runCommand*(command: string, args: openArray[string]): int = ## This will run a command with the given args and return its exit code upon completion @@ -7,4 +8,4 @@ proc runCommand*(command: string, args: openArray[string]): int = process.close() proc isGlobalMenuEnabled*(): bool = - return runCommand("/usr/bin/pacman", ["-Qq", "vala-panel-appmenu-registrar"]) == 0 + return fileExists("/usr/lib/vala-panel/appmenu-registrar") diff --git a/toggleGlobalMenu.nim b/toggleGlobalMenu.nim index 33cd91c..43605ef 100644 --- a/toggleGlobalMenu.nim +++ b/toggleGlobalMenu.nim @@ -1,22 +1,36 @@ -from std/os import paramCount, paramStr, extractFilename +from std/osproc import execProcess from std/strformat import fmt -import sharedModule +import sharedModule, std/os proc enableGlobalMenus(): int = - return runCommand("/usr/bin/env", ["SKIP_AUTOSNAP=", "/usr/bin/pacman", "-S", "--noconfirm", "vala-panel-appmenu-registrar"]) + try: + moveFile("/usr/lib/vala-panel/appmenu-registrar.disabled", "/usr/lib/vala-panel/appmenu-registrar") + removeFile("/usr/share/libalpm/hooks/disable-global-menu.hook") + except: + return 1 proc disableGlobalMenus(): int = - result = runCommand("/usr/bin/env", ["SKIP_AUTOSNAP=", "/usr/bin/pacman", "-R", "--noconfirm", "vala-panel-appmenu-registrar"]) - if result == 0: + try: + moveFile("/usr/lib/vala-panel/appmenu-registrar", "/usr/lib/vala-panel/appmenu-registrar.disabled") + if not fileExists("/usr/share/libalpm/hooks/disable-global-menu.hook"): + createDir("/usr/share/libalpm/hooks") + copyFileWithPermissions("/usr/share/tromjaro-layout-switcher/disable-global-menu.hook", + "/usr/share/libalpm/hooks/disable-global-menu.hook") discard runCommand("/usr/bin/killall", ["appmenu-registrar"]) + except: + return 1 proc showHelp() = let executableName = paramStr(0).extractFilename() echo fmt""" Usage: {executableName}