From 33d15f289db2b460254a01b06c147983f49e745b Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 14:41:17 +0000
Subject: [PATCH 1/8] Update sharedModule.nim

---
 sharedModule.nim | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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")
-- 
2.39.5


From f22786607219edf328156c5c6932a6dbced6576c Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:09:38 +0000
Subject: [PATCH 2/8] Update toggleGlobalMenu.nim

---
 toggleGlobalMenu.nim | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/toggleGlobalMenu.nim b/toggleGlobalMenu.nim
index 33cd91c..e75d60b 100644
--- a/toggleGlobalMenu.nim
+++ b/toggleGlobalMenu.nim
@@ -1,14 +1,24 @@
-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()
@@ -18,6 +28,10 @@ Options:
     enable      install global menus
     disable     remove global menus"""
 
+if execProcess("/usr/bin/id", args=["--user"], options={}) != "0\n":
+  echo "Run this program as root."
+  quit(1)
+
 var exitCode: int
 if paramCount() < 1:
   if isGlobalMenuEnabled():
-- 
2.39.5


From e85eb98980896f98757fafe3de24be9720033bc4 Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:10:56 +0000
Subject: [PATCH 3/8] Add disable-global-menu.hook

---
 disable-global-menu.hook | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 disable-global-menu.hook

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
-- 
2.39.5


From 25c571dc13c8246531e57eef7403e1375a5d99b0 Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:12:06 +0000
Subject: [PATCH 4/8] Update PKGBUILD

---
 PKGBUILD | 6 ++++++
 1 file changed, 6 insertions(+)

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
-- 
2.39.5


From 65b882b0d6d7762000bf479aca626f2cf21dd6f7 Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:21:06 +0000
Subject: [PATCH 5/8] Update layoutSwitcher.nim

---
 layoutSwitcher.nim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layoutSwitcher.nim b/layoutSwitcher.nim
index 0c6c8ba..7987f8a 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 installing 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 removing global menu!")
       return false
   # Hide window borders when maximized
   discard runCommand("/usr/bin/xfconf-query",
-- 
2.39.5


From 582743d1f80de3fe46f48125c1b190a9fa42f83a Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:29:01 +0000
Subject: [PATCH 6/8] Update layoutSwitcher.nim

---
 layoutSwitcher.nim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layoutSwitcher.nim b/layoutSwitcher.nim
index 7987f8a..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, "Layout Switcher", "Failed installing global menu!")
+      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, "Layout Switcher", "Failed removing global menu!")
+      sendNotification(appID, "Layout Switcher", "Failed to disable global menu!")
       return false
   # Hide window borders when maximized
   discard runCommand("/usr/bin/xfconf-query",
-- 
2.39.5


From 2e5694bc794c7b80842dee0d0d17ee4d959f552c Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:32:33 +0000
Subject: [PATCH 7/8] Update com.tromjaro.LayoutSwitcher.policy

---
 com.tromjaro.LayoutSwitcher.policy | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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 @@
 	<vendor_url>https://www.tromjaro.com/</vendor_url>
 	<icon_name>tromjaro-layout-switcher</icon_name>
 	<action id="com.tromjaro.LayoutSwitcher.toggleGlobalMenu">
-		<description gettext-domain="LayoutSwitcher">Install or remove global menu</description>
-		<message gettext-domain="LayoutSwitcher">Authentication is required to install/remove global menu</message>
+		<description gettext-domain="LayoutSwitcher">Enable or disable global menu</description>
+		<message gettext-domain="LayoutSwitcher">Authentication is required to enable/disable global menu</message>
 		<defaults>
 			<allow_any>auth_admin</allow_any>
 			<allow_inactive>auth_admin</allow_inactive>
-- 
2.39.5


From a1e5a7fde982bef60c6802ab8c105747bae70d9b Mon Sep 17 00:00:00 2001
From: rokosun <rokosun@noreply.git.trom.tf>
Date: Mon, 1 Jan 2024 15:34:09 +0000
Subject: [PATCH 8/8] Update toggleGlobalMenu.nim

---
 toggleGlobalMenu.nim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/toggleGlobalMenu.nim b/toggleGlobalMenu.nim
index e75d60b..43605ef 100644
--- a/toggleGlobalMenu.nim
+++ b/toggleGlobalMenu.nim
@@ -25,8 +25,8 @@ proc showHelp() =
   echo fmt"""
 Usage: {executableName} <option>
 Options:
-    enable      install global menus
-    disable     remove global menus"""
+    enable      enable global menus
+    disable     disable global menus"""
 
 if execProcess("/usr/bin/id", args=["--user"], options={}) != "0\n":
   echo "Run this program as root."
-- 
2.39.5