Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximperconf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximperconf
Commits
d661cf1a
Verified
Commit
d661cf1a
authored
Jan 10, 2026
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hyprland/plugins: use HyprlandManager
parent
632abb4d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
147 deletions
+50
-147
plugin-actions.go
hyprland/plugin-actions.go
+50
-147
No files found.
hyprland/plugin-actions.go
View file @
d661cf1a
package
hyprland
package
hyprland
import
(
import
(
"ximperconf/config"
"ximperconf/ui"
"ximperconf/ui"
"ximperconf/utils"
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"strings"
"time"
"github.com/fatih/color"
"github.com/urfave/cli/v3"
"github.com/urfave/cli/v3"
)
)
type
HyprlandPlugin
struct
{
func
hyprlandPluginStatusStruct
(
status
string
)
ui
.
ItemStatus
{
Name
string
`json:"name"`
Author
string
`json:"author"`
Handle
string
`json:"handle"`
Version
string
`json:"version"`
Description
string
`json:"description"`
}
func
preparePlugin
(
cmd
*
cli
.
Command
)
(
string
,
string
,
error
)
{
name
:=
cmd
.
Args
()
.
Get
(
0
)
if
name
==
""
{
return
""
,
""
,
fmt
.
Errorf
(
"плагин не указан"
)
}
path
:=
filepath
.
Join
(
config
.
Env
.
Hyprland
.
PluginsDir
,
name
+
".so"
)
if
!
utils
.
FileExists
(
path
)
{
return
""
,
""
,
fmt
.
Errorf
(
"плагин не найден"
)
}
status
:=
hyprlandPluginStatus
(
name
)
return
path
,
status
,
nil
}
func
fetchLoadedPlugins
()
([]
HyprlandPlugin
,
error
)
{
out
,
err
:=
exec
.
Command
(
"hyprctl"
,
"plugin"
,
"list"
,
"-j"
)
.
Output
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"hyprctl error: %w"
,
err
)
}
var
plugins
[]
HyprlandPlugin
if
err
:=
json
.
Unmarshal
(
out
,
&
plugins
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid JSON: %w"
,
err
)
}
return
plugins
,
nil
}
func
hyprlandPluginStatus
(
plugin
string
)
string
{
loaded
,
err
:=
fetchLoadedPlugins
()
if
err
!=
nil
{
return
"error"
}
for
_
,
p
:=
range
loaded
{
if
p
.
Name
==
plugin
{
return
"loaded"
}
}
return
"unloaded"
}
func
hyprlandPluginStatusStruct
(
plugin
string
)
ui
.
ItemStatus
{
status
:=
hyprlandPluginStatus
(
plugin
)
switch
status
{
switch
status
{
case
"loaded"
:
case
"loaded"
:
return
ui
.
StatusLoaded
return
ui
.
StatusLoaded
...
@@ -82,62 +20,52 @@ func hyprlandPluginStatusStruct(plugin string) ui.ItemStatus {
...
@@ -82,62 +20,52 @@ func hyprlandPluginStatusStruct(plugin string) ui.ItemStatus {
return
ui
.
StatusUnknown
return
ui
.
StatusUnknown
}
}
func
hyprlandPluginList
(
filter
string
)
[]
string
{
func
HyprlandPluginListCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
entries
,
err
:=
os
.
ReadDir
(
config
.
Env
.
Hyprland
.
PluginsDir
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
err
}
var
list
[]
string
for
_
,
e
:=
range
entries
{
if
e
.
IsDir
()
||
!
strings
.
HasSuffix
(
e
.
Name
(),
".so"
)
{
continue
}
name
:=
strings
.
TrimSuffix
(
e
.
Name
(),
".so"
)
status
:=
hyprlandPluginStatus
(
name
)
if
filter
==
""
||
filter
==
"all"
||
filter
==
status
{
list
=
append
(
list
,
name
)
}
}
return
list
}
func
hyprlandPluginLoad
(
path
string
)
error
{
time
.
Sleep
(
1
*
time
.
Second
)
cmd
:=
exec
.
Command
(
"hyprctl"
,
"plugin"
,
"load"
,
path
)
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
return
fmt
.
Errorf
(
"%v (%s)"
,
err
,
out
)
}
}
list
:=
manager
.
GetPluginsList
(
cmd
.
String
(
"filter"
))
fmt
.
Println
(
strings
.
Join
(
list
,
"
\n
"
))
return
nil
return
nil
}
}
func
hyprlandPluginUnload
(
path
string
)
error
{
func
HyprlandPluginStatusCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
time
.
Sleep
(
1
*
time
.
Second
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
cmd
:=
exec
.
Command
(
"hyprctl"
,
"plugin"
,
"unload"
,
path
)
if
err
!=
nil
{
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
return
err
return
fmt
.
Errorf
(
"%v (%s)"
,
err
,
out
)
}
}
fmt
.
Println
(
manager
.
GetPluginStatus
(
cmd
.
Args
()
.
Get
(
0
)))
return
nil
return
nil
}
}
func
hyprlandPluginInfo
(
filter
string
)
{
func
HyprlandPluginInfoCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
plugins
:=
hyprlandPluginList
(
filter
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
if
err
!=
nil
{
return
err
}
plugins
:=
manager
.
GetPluginsList
(
cmd
.
String
(
"filter"
))
if
len
(
plugins
)
==
0
{
if
len
(
plugins
)
==
0
{
color
.
Red
(
"Нет доступных плагинов."
)
return
fmt
.
Errorf
(
"нет доступных плагинов"
)
return
}
}
items
:=
make
([]
ui
.
TreeItem
,
0
,
len
(
plugins
))
items
:=
make
([]
ui
.
TreeItem
,
0
,
len
(
plugins
))
for
_
,
plugin
:=
range
plugins
{
for
_
,
plugin
:=
range
plugins
{
status
:=
hyprlandPluginStatusStruct
(
plugin
)
_status
:=
manager
.
GetPluginStatus
(
plugin
)
status
:=
hyprlandPluginStatusStruct
(
_status
)
desc
:=
""
if
_status
==
"loaded"
{
for
_
,
plug
:=
range
manager
.
LoadedPlugins
{
if
plug
.
Name
==
plugin
{
desc
=
plug
.
Description
}
}
}
items
=
append
(
items
,
ui
.
TreeItem
{
items
=
append
(
items
,
ui
.
TreeItem
{
Name
:
plugin
,
Name
:
plugin
,
Status
:
status
,
Status
:
status
,
Description
:
""
,
Description
:
desc
,
})
})
}
}
...
@@ -148,86 +76,61 @@ func hyprlandPluginInfo(filter string) {
...
@@ -148,86 +76,61 @@ func hyprlandPluginInfo(filter string) {
StatusMap
:
ui
.
ColorStatusMap
,
StatusMap
:
ui
.
ColorStatusMap
,
Sort
:
true
,
Sort
:
true
,
})
})
}
func
HyprlandPluginListCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
fmt
.
Println
(
strings
.
Join
(
hyprlandPluginList
(
cmd
.
String
(
"filter"
)),
"
\n
"
))
return
nil
}
func
HyprlandPluginStatusCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
fmt
.
Println
(
hyprlandPluginStatus
(
cmd
.
Args
()
.
Get
(
0
)))
return
nil
}
func
HyprlandPluginInfoCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
hyprlandPluginInfo
(
cmd
.
String
(
"filter"
))
return
nil
return
nil
}
}
func
HyprlandPluginLoadCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
func
HyprlandPluginLoadCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
path
,
status
,
err
:=
preparePlugin
(
cmd
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
color
.
Red
(
err
.
Error
())
return
err
return
nil
}
if
status
==
"loaded"
{
color
.
Red
(
"плагин уже загружен"
)
return
nil
}
}
if
err
:=
hyprlandPluginLoad
(
path
);
err
!=
nil
{
msg
,
err
:=
manager
.
SetPlugin
(
"load"
,
cmd
.
Args
()
.
Get
(
0
))
color
.
Red
(
err
.
Error
())
if
err
!=
nil
{
return
err
return
err
}
}
fmt
.
Println
(
"OK"
)
fmt
.
Println
(
msg
)
return
nil
return
nil
}
}
func
HyprlandPluginUnloadCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
func
HyprlandPluginUnloadCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
path
,
status
,
err
:=
preparePlugin
(
cmd
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
color
.
Red
(
err
.
Error
())
return
err
return
nil
}
if
status
==
"unloaded"
{
color
.
Red
(
"плагин не загружен"
)
return
nil
}
}
if
err
:=
hyprlandPluginUnload
(
path
);
err
!=
nil
{
msg
,
err
:=
manager
.
SetPlugin
(
"unload"
,
cmd
.
Args
()
.
Get
(
0
))
color
.
Red
(
err
.
Error
())
if
err
!=
nil
{
return
err
return
err
}
}
fmt
.
Println
(
"OK"
)
fmt
.
Println
(
msg
)
return
nil
return
nil
}
}
func
HyprlandPluginToggleCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
func
HyprlandPluginToggleCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
path
,
status
,
err
:=
preparePlugin
(
cmd
)
manager
,
err
:=
GetHyprlandManager
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
color
.
Red
(
err
.
Error
())
return
err
return
nil
}
}
var
execErr
error
var
msg
string
path
:=
cmd
.
Args
()
.
Get
(
0
)
status
:=
manager
.
GetPluginStatus
(
path
)
switch
status
{
switch
status
{
case
"loaded"
:
case
"loaded"
:
execErr
=
hyprlandPluginUnload
(
path
)
msg
,
err
=
manager
.
SetPlugin
(
"unload"
,
path
)
case
"unloaded"
:
case
"unloaded"
:
execErr
=
hyprlandPluginLoad
(
path
)
msg
,
err
=
manager
.
SetPlugin
(
"load"
,
path
)
}
}
if
execErr
!=
nil
{
if
err
!=
nil
{
color
.
Red
(
execErr
.
Error
())
return
err
return
execErr
}
}
fmt
.
Println
(
"OK"
)
fmt
.
Println
(
msg
)
return
nil
return
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment