better-manage-global-menu #4

Merged
rokosun merged 8 commits from better-manage-global-menu into master 2024-01-01 15:38:54 +00:00
6 changed files with 43 additions and 12 deletions

View File

@ -7,6 +7,7 @@ arch=('x86_64')
url="https://git.trom.tf/TROMjaro/layout-switcher-package" url="https://git.trom.tf/TROMjaro/layout-switcher-package"
license=(unknown) license=(unknown)
depends=('xfce4-panel-profiles' depends=('xfce4-panel-profiles'
'vala-panel-appmenu-registrar'
'util-linux' 'util-linux'
'xfconf' 'xfconf'
'polkit' 'polkit'
@ -28,6 +29,7 @@ source=("layoutSwitcher.nim"
"sharedModule.nim" "sharedModule.nim"
"tromjaro-layout-switcher.desktop" "tromjaro-layout-switcher.desktop"
"com.tromjaro.LayoutSwitcher.policy" "com.tromjaro.LayoutSwitcher.policy"
"disable-global-menu.hook"
"tromjaro-layout-switcher.svg" "tromjaro-layout-switcher.svg"
"icons.zip::https://www.drive.tromsite.com/s/SWmAcokLcxLB3gM/download" "icons.zip::https://www.drive.tromsite.com/s/SWmAcokLcxLB3gM/download"
"profiles.zip::https://www.drive.tromsite.com/s/6dHoNjar9wJzeLd/download") "profiles.zip::https://www.drive.tromsite.com/s/6dHoNjar9wJzeLd/download")
@ -38,6 +40,7 @@ sha256sums=('SKIP'
'SKIP' 'SKIP'
'SKIP' 'SKIP'
'SKIP' 'SKIP'
'SKIP'
'SKIP') 'SKIP')
prepare() { prepare() {
# Disable telemetry in choosenim if user is running it for the first time # 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 -d ${pkgdir}/usr/share/tromjaro-layout-switcher/profiles
install -Dm644 ${srcdir}/profiles/* ${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 # copy executables
install -d ${pkgdir}/usr/share/applications install -d ${pkgdir}/usr/share/applications
install -Dm644 ${srcdir}/tromjaro-layout-switcher.desktop ${pkgdir}/usr/share/applications install -Dm644 ${srcdir}/tromjaro-layout-switcher.desktop ${pkgdir}/usr/share/applications

View File

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

10
disable-global-menu.hook Normal file
View File

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

View File

@ -37,7 +37,7 @@ proc enableTopBarIntegration(): bool =
sendNotification(appID, "Layout Switcher", "Authentication failed!") sendNotification(appID, "Layout Switcher", "Authentication failed!")
return false return false
else: 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 return false
# Hide window borders when maximized # Hide window borders when maximized
discard runCommand("/usr/bin/xfconf-query", discard runCommand("/usr/bin/xfconf-query",
@ -62,7 +62,7 @@ proc disableTopBarIntegration(): bool =
of 127: of 127:
sendNotification(appID, "Layout Switcher", "Authentication failed!") sendNotification(appID, "Layout Switcher", "Authentication failed!")
else: 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 return false
# Hide window borders when maximized # Hide window borders when maximized
discard runCommand("/usr/bin/xfconf-query", discard runCommand("/usr/bin/xfconf-query",

View File

@ -1,4 +1,5 @@
from std/osproc import startProcess, ProcessOption, waitForExit, close from std/osproc import startProcess, ProcessOption, waitForExit, close
from std/os import fileExists
proc runCommand*(command: string, args: openArray[string]): int = proc runCommand*(command: string, args: openArray[string]): int =
## This will run a command with the given args and return its exit code upon completion ## 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() process.close()
proc isGlobalMenuEnabled*(): bool = proc isGlobalMenuEnabled*(): bool =
return runCommand("/usr/bin/pacman", ["-Qq", "vala-panel-appmenu-registrar"]) == 0 return fileExists("/usr/lib/vala-panel/appmenu-registrar")

View File

@ -1,22 +1,36 @@
from std/os import paramCount, paramStr, extractFilename from std/osproc import execProcess
from std/strformat import fmt from std/strformat import fmt
import sharedModule import sharedModule, std/os
proc enableGlobalMenus(): int = 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 = proc disableGlobalMenus(): int =
result = runCommand("/usr/bin/env", ["SKIP_AUTOSNAP=", "/usr/bin/pacman", "-R", "--noconfirm", "vala-panel-appmenu-registrar"]) try:
if result == 0: 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"]) discard runCommand("/usr/bin/killall", ["appmenu-registrar"])
except:
return 1
proc showHelp() = proc showHelp() =
let executableName = paramStr(0).extractFilename() let executableName = paramStr(0).extractFilename()
echo fmt""" echo fmt"""
Usage: {executableName} <option> Usage: {executableName} <option>
Options: Options:
enable install global menus enable enable global menus
disable remove global menus""" disable disable global menus"""
if execProcess("/usr/bin/id", args=["--user"], options={}) != "0\n":
echo "Run this program as root."
quit(1)
var exitCode: int var exitCode: int
if paramCount() < 1: if paramCount() < 1: