mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-07 14:08:29 -04:00
Compare commits
58 Commits
c67b185076
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 40a9ca348c | |||
| a1ba5cf9ad | |||
| 915db2dce7 | |||
| 1dc0ceea1f | |||
| 1a621c3f88 | |||
| b7ec57a534 | |||
| a575363f89 | |||
| 3f6cd0b579 | |||
| 630e9bd3cd | |||
| 9013464312 | |||
| dade416ca0 | |||
| 401872881e | |||
| 7cb97f4462 | |||
| 82b1b36b1a | |||
| e203e76ccc | |||
| adcafbcc8e | |||
| 9981fcf529 | |||
| 2baf048293 | |||
| cffc33e14a | |||
| 0c811e3417 | |||
| 6ad46cf2c2 | |||
| 34626070af | |||
| 80b27b9a6a | |||
| 49f968d26b | |||
| 99b0dc596d | |||
| 158c0c12d8 | |||
| e089948225 | |||
| 7f2ba56e06 | |||
| 6de5593216 | |||
| 365474b0d9 | |||
| dc8a47644a | |||
| 27483e68dc | |||
| 400a18a8ed | |||
| 32ddf614c3 | |||
| 19d919ed5c | |||
| 594a2cde19 | |||
| 11287459c3 | |||
| ef191babb7 | |||
| fe64a342f9 | |||
| e54be7d12d | |||
| 81c886784b | |||
| 6682bb120c | |||
| 5c02ec4789 | |||
| de1e1757c3 | |||
| 43d331d6cf | |||
| 01832856d4 | |||
| 0033e3f0e0 | |||
| 2d3706321a | |||
| 5bb884db57 | |||
| b42763ccbf | |||
| f2a6d62d65 | |||
| f66693df6b | |||
| a710d6d7cc | |||
| 64461c534f | |||
| 73da4879f6 | |||
| 8594a414ec | |||
| df396bfa43 | |||
| 33677150b1 |
@@ -101,7 +101,9 @@ MPRIS player controls, calendar sync, weather widgets, and clipboard history wit
|
|||||||
Lock screen, idle detection, auto-lock/suspend with separate AC/battery settings, and a settings front-end for [dank-greeter](https://github.com/AvengeMedia/dank-greeter).
|
Lock screen, idle detection, auto-lock/suspend with separate AC/battery settings, and a settings front-end for [dank-greeter](https://github.com/AvengeMedia/dank-greeter).
|
||||||
|
|
||||||
**Plugin System**
|
**Plugin System**
|
||||||
Extend functionality with the [plugin registry](https://plugins.danklinux.com).
|
Extend functionality with the [plugin registry](https://plugins.danklinux.com). DMS keeps
|
||||||
|
`~/.config/DankMaterialShell/plugins.lock.json` synchronized with managed plugin installs and
|
||||||
|
their exact Git commits, so the same plugins can be reproduced on another machine.
|
||||||
|
|
||||||
## Supported Compositors
|
## Supported Compositors
|
||||||
|
|
||||||
@@ -120,6 +122,8 @@ dms ipc call audio setvolume 50
|
|||||||
dms ipc call wallpaper set /path/to/image.jpg
|
dms ipc call wallpaper set /path/to/image.jpg
|
||||||
dms brightness list # List available displays
|
dms brightness list # List available displays
|
||||||
dms plugins search # Browse plugin registry
|
dms plugins search # Browse plugin registry
|
||||||
|
dms plugins lock # Refresh the portable plugin lockfile
|
||||||
|
dms plugins restore ~/plugins.lock.json
|
||||||
```
|
```
|
||||||
|
|
||||||
[Full CLI and IPC documentation](https://danklinux.com/docs/dankmaterialshell/keybinds-ipc)
|
[Full CLI and IPC documentation](https://danklinux.com/docs/dankmaterialshell/keybinds-ipc)
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ Custom IPC via unix socket (JSON API) for shell communication.
|
|||||||
- `dms run [-d]` - Start shell (optionally as daemon)
|
- `dms run [-d]` - Start shell (optionally as daemon)
|
||||||
- `dms restart` / `dms kill` - Manage running processes
|
- `dms restart` / `dms kill` - Manage running processes
|
||||||
- `dms ipc <command>` - Send IPC commands (toggle launcher, notifications, etc.)
|
- `dms ipc <command>` - Send IPC commands (toggle launcher, notifications, etc.)
|
||||||
- `dms plugins [install|browse|search]` - Plugin management
|
- `dms plugins [install|browse|search|lock|restore]` - Plugin management and portable exact-revision lockfiles
|
||||||
- `dms brightness [list|set]` - Control display/monitor brightness
|
- `dms brightness [list|set]` - Control display/monitor brightness
|
||||||
- `dms color pick` - Native color picker (see below)
|
- `dms color pick` - Native color picker (see below)
|
||||||
- `dms update` - Update DMS and dependencies (disabled in distro packages)
|
- `dms update` - Update DMS and dependencies (disabled in distro packages)
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ func init() {
|
|||||||
})
|
})
|
||||||
pluginsUpdateCmd.Flags().BoolP("all", "a", false, "Update all installed plugins")
|
pluginsUpdateCmd.Flags().BoolP("all", "a", false, "Update all installed plugins")
|
||||||
pluginsUpdateCmd.Flags().Bool("check", false, "Check for available updates without applying them")
|
pluginsUpdateCmd.Flags().Bool("check", false, "Check for available updates without applying them")
|
||||||
|
pluginsLockCmd.Flags().StringP("output", "o", "", "Also write the lockfile to this path")
|
||||||
|
pluginsRestoreCmd.Flags().Bool("prune", false, "Remove managed plugins that are not in the lockfile")
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugSrvCmd = &cobra.Command{
|
var debugSrvCmd = &cobra.Command{
|
||||||
@@ -178,6 +180,36 @@ var pluginsUpdateCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pluginsLockCmd = &cobra.Command{
|
||||||
|
Use: "lock",
|
||||||
|
Short: "Record installed plugins and their exact revisions",
|
||||||
|
Long: "Write a portable plugins.lock.json containing every managed user plugin and its current Git commit.",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
if err := lockPluginsCLI(output); err != nil {
|
||||||
|
log.Fatalf("Error writing plugin lockfile: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var pluginsRestoreCmd = &cobra.Command{
|
||||||
|
Use: "restore [lockfile]",
|
||||||
|
Short: "Restore plugins from exact revisions in a lockfile",
|
||||||
|
Long: "Install or reset all plugins in a portable plugins.lock.json. Existing managed plugins are retained unless --prune is specified.",
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
path := ""
|
||||||
|
if len(args) == 1 {
|
||||||
|
path = args[0]
|
||||||
|
}
|
||||||
|
prune, _ := cmd.Flags().GetBool("prune")
|
||||||
|
if err := restorePluginsCLI(path, prune); err != nil {
|
||||||
|
log.Fatalf("Error restoring plugins: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func runVersion(cmd *cobra.Command, args []string) {
|
func runVersion(cmd *cobra.Command, args []string) {
|
||||||
fmt.Printf("%s\n", formatVersion(Version))
|
fmt.Printf("%s\n", formatVersion(Version))
|
||||||
}
|
}
|
||||||
@@ -433,6 +465,40 @@ func installPluginCLI(idOrName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lockPluginsCLI(outputPath string) error {
|
||||||
|
manager, err := plugins.NewManager()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create manager: %w", err)
|
||||||
|
}
|
||||||
|
warnings, err := manager.WriteCurrentLockfile(outputPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, warning := range warnings {
|
||||||
|
fmt.Fprintf(os.Stderr, "Warning: %s\n", warning)
|
||||||
|
}
|
||||||
|
fmt.Printf("Plugin lockfile written: %s\n", manager.GetLockfilePath())
|
||||||
|
if outputPath != "" && outputPath != manager.GetLockfilePath() {
|
||||||
|
fmt.Printf("Plugin lockfile exported: %s\n", outputPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func restorePluginsCLI(path string, prune bool) error {
|
||||||
|
manager, err := plugins.NewManager()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create manager: %w", err)
|
||||||
|
}
|
||||||
|
if err := manager.RestoreFromLockfile(path, prune); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if path == "" {
|
||||||
|
path = manager.GetLockfilePath()
|
||||||
|
}
|
||||||
|
fmt.Printf("Plugins restored from lockfile: %s\n", path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getAvailablePluginIDs() []string {
|
func getAvailablePluginIDs() []string {
|
||||||
registry, err := plugins.NewRegistry()
|
registry, err := plugins.NewRegistry()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -704,6 +770,7 @@ func getCommonCommands() []*cobra.Command {
|
|||||||
ipcCmd,
|
ipcCmd,
|
||||||
debugSrvCmd,
|
debugSrvCmd,
|
||||||
pluginsCmd,
|
pluginsCmd,
|
||||||
|
registryCmd,
|
||||||
dank16Cmd,
|
dank16Cmd,
|
||||||
brightnessCmd,
|
brightnessCmd,
|
||||||
dpmsCmd,
|
dpmsCmd,
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var registryCmd = &cobra.Command{
|
||||||
|
Use: "registry",
|
||||||
|
Short: "Manage plugin and theme registries",
|
||||||
|
Long: "Manage the registries DMS fetches plugins and themes from. The official registry is always active; additional registries can be added by name and git URL.",
|
||||||
|
}
|
||||||
|
|
||||||
|
var registryListCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "List configured registries",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
for _, s := range registries.Load(afero.NewOsFs()) {
|
||||||
|
suffix := ""
|
||||||
|
if s.Official() {
|
||||||
|
suffix = " (official)"
|
||||||
|
}
|
||||||
|
fmt.Printf("%s%s\n %s\n", s.Name, suffix, s.URL)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var registryAddCmd = &cobra.Command{
|
||||||
|
Use: "add <name> <url>",
|
||||||
|
Short: "Add a registry",
|
||||||
|
Long: "Add a registry by name and git URL. The repository must contain a plugins/ or themes/ directory in the registry format.",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if err := registries.Add(afero.NewOsFs(), args[0], args[1]); err != nil {
|
||||||
|
log.Fatalf("Error adding registry: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Registry added: %s\n", args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var registryRemoveCmd = &cobra.Command{
|
||||||
|
Use: "remove <name>",
|
||||||
|
Short: "Remove a registry",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
var names []string
|
||||||
|
for _, s := range registries.Load(afero.NewOsFs()) {
|
||||||
|
if !s.Official() {
|
||||||
|
names = append(names, s.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if err := registries.Remove(afero.NewOsFs(), args[0]); err != nil {
|
||||||
|
log.Fatalf("Error removing registry: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Registry removed: %s\n", args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ func init() {
|
|||||||
authCmd.AddCommand(authSyncCmd, authResolveLockCmd, authListServicesCmd, authValidateCmd)
|
authCmd.AddCommand(authSyncCmd, authResolveLockCmd, authListServicesCmd, authValidateCmd)
|
||||||
setupCmd.AddCommand(setupBindsCmd, setupLayoutCmd, setupColorsCmd, setupAlttabCmd, setupOutputsCmd, setupCursorCmd, setupWindowrulesCmd)
|
setupCmd.AddCommand(setupBindsCmd, setupLayoutCmd, setupColorsCmd, setupAlttabCmd, setupOutputsCmd, setupCursorCmd, setupWindowrulesCmd)
|
||||||
updateCmd.AddCommand(updateCheckCmd)
|
updateCmd.AddCommand(updateCheckCmd)
|
||||||
pluginsCmd.AddCommand(pluginsBrowseCmd, pluginsListCmd, pluginsInstallCmd, pluginsUninstallCmd, pluginsUpdateCmd)
|
pluginsCmd.AddCommand(pluginsBrowseCmd, pluginsListCmd, pluginsInstallCmd, pluginsUninstallCmd, pluginsUpdateCmd, pluginsLockCmd, pluginsRestoreCmd)
|
||||||
|
registryCmd.AddCommand(registryListCmd, registryAddCmd, registryRemoveCmd)
|
||||||
rootCmd.AddCommand(getCommonCommands()...)
|
rootCmd.AddCommand(getCommonCommands()...)
|
||||||
|
|
||||||
rootCmd.AddCommand(authCmd)
|
rootCmd.AddCommand(authCmd)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var Version = "dev"
|
|||||||
func init() {
|
func init() {
|
||||||
authCmd.AddCommand(authSyncCmd, authResolveLockCmd, authListServicesCmd, authValidateCmd)
|
authCmd.AddCommand(authSyncCmd, authResolveLockCmd, authListServicesCmd, authValidateCmd)
|
||||||
setupCmd.AddCommand(setupBindsCmd, setupLayoutCmd, setupColorsCmd, setupAlttabCmd, setupOutputsCmd, setupCursorCmd, setupWindowrulesCmd)
|
setupCmd.AddCommand(setupBindsCmd, setupLayoutCmd, setupColorsCmd, setupAlttabCmd, setupOutputsCmd, setupCursorCmd, setupWindowrulesCmd)
|
||||||
pluginsCmd.AddCommand(pluginsBrowseCmd, pluginsListCmd, pluginsInstallCmd, pluginsUninstallCmd, pluginsUpdateCmd)
|
pluginsCmd.AddCommand(pluginsBrowseCmd, pluginsListCmd, pluginsInstallCmd, pluginsUninstallCmd, pluginsUpdateCmd, pluginsLockCmd, pluginsRestoreCmd)
|
||||||
rootCmd.AddCommand(getCommonCommands()...)
|
rootCmd.AddCommand(getCommonCommands()...)
|
||||||
rootCmd.AddCommand(authCmd)
|
rootCmd.AddCommand(authCmd)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/AvengeMedia/dankgo v0.0.0-20260724133713-a4ef23371e05
|
github.com/AvengeMedia/dankgo v0.0.0-20260730184236-239485829b0b
|
||||||
github.com/atotto/clipboard v0.1.4 // indirect
|
github.com/atotto/clipboard v0.1.4 // indirect
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
||||||
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
||||||
github.com/AvengeMedia/dankgo v0.0.0-20260724133713-a4ef23371e05 h1:Ij/yzOT8y2HL7V5Rkec1GxJV0rUvhKqfAzyGxVRTk1o=
|
github.com/AvengeMedia/dankgo v0.0.0-20260730184236-239485829b0b h1:UwX1H4BkzazL7ips9ljnHzBXGttYARcIi5Njj9aqIt4=
|
||||||
github.com/AvengeMedia/dankgo v0.0.0-20260724133713-a4ef23371e05/go.mod h1:xt8RldAfti0QCWidwYIzsSSoJWsE61WgEhTu2H9UpD4=
|
github.com/AvengeMedia/dankgo v0.0.0-20260730184236-239485829b0b/go.mod h1:xt8RldAfti0QCWidwYIzsSSoJWsE61WgEhTu2H9UpD4=
|
||||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||||
github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM=
|
github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM=
|
||||||
|
|||||||
@@ -313,6 +313,7 @@ func EnsureContrastDPSLstar(hexColor, hexBg string, minLc float64, isLightMode b
|
|||||||
fg := HexToRGB(hexColor)
|
fg := HexToRGB(hexColor)
|
||||||
cf := colorful.Color{R: fg.R, G: fg.G, B: fg.B}
|
cf := colorful.Color{R: fg.R, G: fg.G, B: fg.B}
|
||||||
Lf, af, bf := cf.Lab()
|
Lf, af, bf := cf.Lab()
|
||||||
|
Lf *= 100.0
|
||||||
|
|
||||||
dir := 1.0
|
dir := 1.0
|
||||||
if isLightMode {
|
if isLightMode {
|
||||||
@@ -341,6 +342,7 @@ func EnsureContrastDPSBidirectional(hexColor, hexBg string, minLc float64, isLig
|
|||||||
fg := HexToRGB(hexColor)
|
fg := HexToRGB(hexColor)
|
||||||
cf := colorful.Color{R: fg.R, G: fg.G, B: fg.B}
|
cf := colorful.Color{R: fg.R, G: fg.G, B: fg.B}
|
||||||
origL, af, bf := cf.Lab()
|
origL, af, bf := cf.Lab()
|
||||||
|
origL *= 100.0
|
||||||
|
|
||||||
var darkerResult, lighterResult string
|
var darkerResult, lighterResult string
|
||||||
darkerL, lighterL := origL, origL
|
darkerL, lighterL := origL, origL
|
||||||
@@ -420,6 +422,24 @@ func blendHue(base, target, factor float64) float64 {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// color8 sits a fixed L* offset from the background so it keeps its dim role
|
||||||
|
// regardless of primary brightness (conventional palettes put ANSI bright
|
||||||
|
// black ~2-2.5:1 from the background, e.g. catppuccin-mocha #585b70 on #1e1e2e)
|
||||||
|
func DeriveDim(bgHex string, hue, sat float64, isLight bool) string {
|
||||||
|
offset := 22.0
|
||||||
|
if isLight {
|
||||||
|
offset = -offset
|
||||||
|
}
|
||||||
|
|
||||||
|
bgL := getLstar(bgHex)
|
||||||
|
targetL := math.Max(0, math.Min(100, bgL+offset))
|
||||||
|
|
||||||
|
tint := HSVToRGB(HSV{H: hue, S: sat, V: 0.5})
|
||||||
|
c := colorful.Color{R: tint.R, G: tint.G, B: tint.B}
|
||||||
|
_, af, bf := c.Lab()
|
||||||
|
return labToHex(targetL, af, bf)
|
||||||
|
}
|
||||||
|
|
||||||
func DeriveContainer(primary string, isLight bool) string {
|
func DeriveContainer(primary string, isLight bool) string {
|
||||||
rgb := HexToRGB(primary)
|
rgb := HexToRGB(primary)
|
||||||
hsv := RGBToHSV(rgb)
|
hsv := RGBToHSV(rgb)
|
||||||
@@ -500,10 +520,7 @@ func GeneratePalette(primaryColor string, opts PaletteOptions) Palette {
|
|||||||
gray7V := baseVal * 0.28
|
gray7V := baseVal * 0.28
|
||||||
palette.Color7 = NewColorInfo(ensureContrastAuto(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray7S, V: gray7V})), bgColor, normalTextTarget, opts))
|
palette.Color7 = NewColorInfo(ensureContrastAuto(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray7S, V: gray7V})), bgColor, normalTextTarget, opts))
|
||||||
|
|
||||||
gray8S := baseSat * 0.05
|
palette.Color8 = NewColorInfo(DeriveDim(bgColor, hsv.H, baseSat*0.05, true))
|
||||||
gray8V := baseVal * 0.85
|
|
||||||
dimTarget := secondaryTarget * 0.5
|
|
||||||
palette.Color8 = NewColorInfo(ensureContrastBidirectional(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray8S, V: gray8V})), bgColor, dimTarget, opts))
|
|
||||||
|
|
||||||
brightRedS := math.Min(baseSat*1.0, 1.0)
|
brightRedS := math.Min(baseSat*1.0, 1.0)
|
||||||
brightRedV := math.Min(baseVal*1.2, 1.0)
|
brightRedV := math.Min(baseVal*1.2, 1.0)
|
||||||
@@ -559,9 +576,7 @@ func GeneratePalette(primaryColor string, opts PaletteOptions) Palette {
|
|||||||
gray7V := math.Min(baseVal*1.05, 1.0)
|
gray7V := math.Min(baseVal*1.05, 1.0)
|
||||||
palette.Color7 = NewColorInfo(ensureContrastAuto(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray7S, V: gray7V})), bgColor, normalTextTarget, opts))
|
palette.Color7 = NewColorInfo(ensureContrastAuto(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray7S, V: gray7V})), bgColor, normalTextTarget, opts))
|
||||||
|
|
||||||
gray8S := baseSat * 0.15
|
palette.Color8 = NewColorInfo(DeriveDim(bgColor, hsv.H, baseSat*0.15, false))
|
||||||
gray8V := baseVal * 0.65
|
|
||||||
palette.Color8 = NewColorInfo(ensureContrastAuto(RGBToHex(HSVToRGB(HSV{H: hsv.H, S: gray8S, V: gray8V})), bgColor, secondaryTarget, opts))
|
|
||||||
|
|
||||||
brightRedS := math.Min(baseSat*0.75, 1.0)
|
brightRedS := math.Min(baseSat*0.75, 1.0)
|
||||||
brightRedV := math.Min(baseVal*1.35, 1.0)
|
brightRedV := math.Min(baseVal*1.35, 1.0)
|
||||||
|
|||||||
@@ -679,3 +679,73 @@ func TestContrastAlgorithmComparison(t *testing.T) {
|
|||||||
|
|
||||||
t.Logf("WCAG and DPS palettes differ in %d/16 colors", differentCount)
|
t.Logf("WCAG and DPS palettes differ in %d/16 colors", differentCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnsureContrastDPSLightModeStaysLight(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result string
|
||||||
|
bg string
|
||||||
|
minLstar float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "bidirectional adjustment",
|
||||||
|
result: EnsureContrastDPSBidirectional("#d0ccc6", "#f8f8f8", 17.5, true),
|
||||||
|
bg: "#f8f8f8",
|
||||||
|
minLstar: 20.0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lstar adjustment",
|
||||||
|
result: EnsureContrastDPSLstar("#c0c0c0", "#f8f8f8", 30.0, true),
|
||||||
|
bg: "#f8f8f8",
|
||||||
|
minLstar: 20.0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
lstar := getLstar(tt.result)
|
||||||
|
if lstar < tt.minLstar {
|
||||||
|
t.Errorf("result %s has L* %.2f on light bg %s, expected >= %.2f (collapsed to near-black)",
|
||||||
|
tt.result, lstar, tt.bg, tt.minLstar)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGeneratePaletteColor8Dim(t *testing.T) {
|
||||||
|
hues := []string{"#e91e63", "#f59e0b", "#22c55e", "#06b6d4", "#8b5cf6", "#ef4444"}
|
||||||
|
|
||||||
|
for _, base := range hues {
|
||||||
|
t.Run(base, func(t *testing.T) {
|
||||||
|
palette := GeneratePalette(base, PaletteOptions{IsLight: false, UseDPS: true})
|
||||||
|
|
||||||
|
bgRatio := ContrastRatio(palette.Color8.Hex, palette.Color0.Hex)
|
||||||
|
if bgRatio < 1.5 || bgRatio > 3.0 {
|
||||||
|
t.Errorf("Color8 %s vs bg %s ratio %.2f, expected 1.5-3.0 (bright black stays near bg)",
|
||||||
|
palette.Color8.Hex, palette.Color0.Hex, bgRatio)
|
||||||
|
}
|
||||||
|
|
||||||
|
sepRatio := ContrastRatio(palette.Color4.Hex, palette.Color8.Hex)
|
||||||
|
if sepRatio < 2.0 {
|
||||||
|
t.Errorf("Color4 %s vs Color8 %s ratio %.2f, expected >= 2.0 (blue must not collide with bright black)",
|
||||||
|
palette.Color4.Hex, palette.Color8.Hex, sepRatio)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGeneratePaletteLightColor8StaysLight(t *testing.T) {
|
||||||
|
palette := GeneratePalette("#f59e0b", PaletteOptions{IsLight: true, UseDPS: true})
|
||||||
|
|
||||||
|
lstar := getLstar(palette.Color8.Hex)
|
||||||
|
if lstar < 60.0 {
|
||||||
|
t.Errorf("light mode Color8 %s has L* %.2f, expected >= 60 (dim grey, not near-black)",
|
||||||
|
palette.Color8.Hex, lstar)
|
||||||
|
}
|
||||||
|
|
||||||
|
bgRatio := ContrastRatio(palette.Color8.Hex, palette.Color0.Hex)
|
||||||
|
if bgRatio > 3.0 {
|
||||||
|
t.Errorf("light mode Color8 %s vs bg %s ratio %.2f, expected <= 3.0",
|
||||||
|
palette.Color8.Hex, palette.Color0.Hex, bgRatio)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ func NewGentooDistribution(config DistroConfig, logChan chan<- string) *GentooDi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func emergeInstallArgs(packages []string) []string {
|
||||||
|
args := []string{"emerge", "--ask=n", "--quiet", "--autounmask-continue=y", "--autounmask-keep-keywords=y", "--autounmask-keep-masks=y"}
|
||||||
|
return append(args, packages...)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GentooDistribution) getArchKeyword() string {
|
func (g *GentooDistribution) getArchKeyword() string {
|
||||||
arch := runtime.GOARCH
|
arch := runtime.GOARCH
|
||||||
switch arch {
|
switch arch {
|
||||||
@@ -319,6 +324,7 @@ func (g *GentooDistribution) InstallPrerequisites(ctx context.Context, sudoPassw
|
|||||||
}
|
}
|
||||||
g.log("Portage tree synced successfully")
|
g.log("Portage tree synced successfully")
|
||||||
|
|
||||||
|
args := emergeInstallArgs(missingPkgs)
|
||||||
g.log(fmt.Sprintf("Installing prerequisites: %s", strings.Join(missingPkgs, ", ")))
|
g.log(fmt.Sprintf("Installing prerequisites: %s", strings.Join(missingPkgs, ", ")))
|
||||||
progressChan <- InstallProgressMsg{
|
progressChan <- InstallProgressMsg{
|
||||||
Phase: PhasePrerequisites,
|
Phase: PhasePrerequisites,
|
||||||
@@ -326,12 +332,10 @@ func (g *GentooDistribution) InstallPrerequisites(ctx context.Context, sudoPassw
|
|||||||
Step: fmt.Sprintf("Installing %d prerequisites...", len(missingPkgs)),
|
Step: fmt.Sprintf("Installing %d prerequisites...", len(missingPkgs)),
|
||||||
IsComplete: false,
|
IsComplete: false,
|
||||||
NeedsSudo: true,
|
NeedsSudo: true,
|
||||||
CommandInfo: fmt.Sprintf("sudo emerge --ask=n %s", strings.Join(missingPkgs, " ")),
|
CommandInfo: fmt.Sprintf("sudo %s", strings.Join(args, " ")),
|
||||||
LogOutput: fmt.Sprintf("Installing prerequisites: %s", strings.Join(missingPkgs, ", ")),
|
LogOutput: fmt.Sprintf("Installing prerequisites: %s", strings.Join(missingPkgs, ", ")),
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"emerge", "--ask=n", "--quiet"}
|
|
||||||
args = append(args, missingPkgs...)
|
|
||||||
cmd := privesc.ExecCommand(ctx, sudoPassword, strings.Join(args, " "))
|
cmd := privesc.ExecCommand(ctx, sudoPassword, strings.Join(args, " "))
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -521,8 +525,7 @@ func (g *GentooDistribution) installPortagePackages(ctx context.Context, package
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"emerge", "--ask=n", "--quiet"}
|
args := emergeInstallArgs(packageNames)
|
||||||
args = append(args, packageNames...)
|
|
||||||
|
|
||||||
progressChan <- InstallProgressMsg{
|
progressChan <- InstallProgressMsg{
|
||||||
Phase: PhaseSystemPackages,
|
Phase: PhaseSystemPackages,
|
||||||
@@ -713,8 +716,7 @@ func (g *GentooDistribution) installGURUPackages(ctx context.Context, packages [
|
|||||||
guruPackages[i] = pkg + "::guru"
|
guruPackages[i] = pkg + "::guru"
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"emerge", "--ask=n", "--quiet"}
|
args := emergeInstallArgs(guruPackages)
|
||||||
args = append(args, guruPackages...)
|
|
||||||
|
|
||||||
progressChan <- InstallProgressMsg{
|
progressChan <- InstallProgressMsg{
|
||||||
Phase: PhaseAURPackages,
|
Phase: PhaseAURPackages,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -224,6 +225,44 @@ func (h *HyprlandProvider) validateAction(action string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var luaExprActionPattern = regexp.MustCompile(`^(function\s*\(|hl\.)`)
|
||||||
|
|
||||||
|
// isRawLuaActionText reports that action is a Lua expression to re-emit
|
||||||
|
// verbatim rather than freeform dispatcher text to wrap for hyprctl. The
|
||||||
|
// balance check keeps malformed input from corrupting the generated file.
|
||||||
|
func isRawLuaActionText(action string) bool {
|
||||||
|
if !luaExprActionPattern.MatchString(action) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
depth := 0
|
||||||
|
var quote byte
|
||||||
|
escaped := false
|
||||||
|
for i := 0; i < len(action); i++ {
|
||||||
|
c := action[i]
|
||||||
|
switch {
|
||||||
|
case escaped:
|
||||||
|
escaped = false
|
||||||
|
case quote != 0:
|
||||||
|
switch c {
|
||||||
|
case '\\':
|
||||||
|
escaped = true
|
||||||
|
case quote:
|
||||||
|
quote = 0
|
||||||
|
}
|
||||||
|
case c == '"' || c == '\'':
|
||||||
|
quote = c
|
||||||
|
case c == '(':
|
||||||
|
depth++
|
||||||
|
case c == ')':
|
||||||
|
depth--
|
||||||
|
if depth < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return depth == 0 && quote == 0 && !escaped
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HyprlandProvider) SetBind(key, action, description string, options map[string]any) error {
|
func (h *HyprlandProvider) SetBind(key, action, description string, options map[string]any) error {
|
||||||
if err := h.ensureWritableConfig(); err != nil {
|
if err := h.ensureWritableConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -254,11 +293,12 @@ func (h *HyprlandProvider) SetBind(key, action, description string, options map[
|
|||||||
canonicalKey := canonicalHyprlandOverrideKey(key)
|
canonicalKey := canonicalHyprlandOverrideKey(key)
|
||||||
normalizedKey := hyprlandOverrideMapKey(canonicalKey)
|
normalizedKey := hyprlandOverrideMapKey(canonicalKey)
|
||||||
existingBinds[normalizedKey] = &hyprlandOverrideBind{
|
existingBinds[normalizedKey] = &hyprlandOverrideBind{
|
||||||
Key: canonicalKey,
|
Key: canonicalKey,
|
||||||
Action: action,
|
Action: action,
|
||||||
Description: description,
|
Description: description,
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
Options: options,
|
Options: options,
|
||||||
|
RawLuaAction: isRawLuaActionText(action),
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.writeOverrideBinds(existingBinds)
|
return h.writeOverrideBinds(existingBinds)
|
||||||
|
|||||||
@@ -463,6 +463,56 @@ func TestHyprlandSetBindLeavesConfOnlyInstallReadOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsRawLuaActionText(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
action string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{`function() hl.plugin.scrolloverview.overview("toggle") end`, true},
|
||||||
|
{`hl.dsp.exec_cmd("foo")`, true},
|
||||||
|
{`hl.dsp.no_op()`, true},
|
||||||
|
{"workspace 3", false},
|
||||||
|
{"exec zeditor", false},
|
||||||
|
{`function() hl.foo( end`, false},
|
||||||
|
{`function() hl.foo("a) end`, false},
|
||||||
|
{`hl.foo()) hl.bar((`, false},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
if got := isRawLuaActionText(tc.action); got != tc.want {
|
||||||
|
t.Errorf("isRawLuaActionText(%q) = %v, want %v", tc.action, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHyprlandSetBindPreservesRawLuaAction(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
dmsDir := filepath.Join(tmpDir, "dms")
|
||||||
|
if err := os.MkdirAll(dmsDir, 0o755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dmsDir, "binds-user.lua"), []byte("-- DMS user keybind overrides\n"), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
provider := NewHyprlandProvider(tmpDir)
|
||||||
|
rawAction := `function() hl.plugin.scrolloverview.overview("toggle") end`
|
||||||
|
if err := provider.SetBind("SUPER + G", rawAction, "Toggle overview", nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(filepath.Join(dmsDir, "binds-user.lua"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got := string(data)
|
||||||
|
if !strings.Contains(got, `hl.bind("SUPER + G", `+rawAction) {
|
||||||
|
t.Fatalf("expected raw Lua action to be written verbatim, got:\n%s", got)
|
||||||
|
}
|
||||||
|
if strings.Contains(got, "hyprctl dispatch function") {
|
||||||
|
t.Fatalf("expected raw Lua action to not be wrapped in hyprctl dispatch, got:\n%s", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestHyprlandSetBindUpdatesSpacedLuaOverrideWithoutDuplicates(t *testing.T) {
|
func TestHyprlandSetBindUpdatesSpacedLuaOverrideWithoutDuplicates(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
dmsDir := filepath.Join(tmpDir, "dms")
|
dmsDir := filepath.Join(tmpDir, "dms")
|
||||||
|
|||||||
@@ -471,12 +471,9 @@ output_path = '%s'
|
|||||||
case TemplateKindTerminal:
|
case TemplateKindTerminal:
|
||||||
appendTerminalConfig(opts, cfgFile, tmpDir, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigFile)
|
appendTerminalConfig(opts, cfgFile, tmpDir, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigFile)
|
||||||
case TemplateKindVSCode:
|
case TemplateKindVSCode:
|
||||||
appendVSCodeConfig(cfgFile, "vscode", filepath.Join(homeDir, ".vscode/extensions"), opts.ShellDir)
|
for _, editor := range vscodeEditors {
|
||||||
appendVSCodeConfig(cfgFile, "codium", filepath.Join(homeDir, ".vscode-oss/extensions"), opts.ShellDir)
|
appendVSCodeConfig(cfgFile, editor.name, editor.extensionsDir(homeDir), opts.ShellDir)
|
||||||
appendVSCodeConfig(cfgFile, "codeoss", filepath.Join(homeDir, ".config/Code - OSS/extensions"), opts.ShellDir)
|
}
|
||||||
appendVSCodeConfig(cfgFile, "cursor", filepath.Join(homeDir, ".cursor/extensions"), opts.ShellDir)
|
|
||||||
appendVSCodeConfig(cfgFile, "windsurf", filepath.Join(homeDir, ".windsurf/extensions"), opts.ShellDir)
|
|
||||||
appendVSCodeConfig(cfgFile, "vscode-insiders", filepath.Join(homeDir, ".vscode-insiders/extensions"), opts.ShellDir)
|
|
||||||
case TemplateKindEmacs:
|
case TemplateKindEmacs:
|
||||||
if utils.EmacsConfigDir() != "" {
|
if utils.EmacsConfigDir() != "" {
|
||||||
appendConfig(opts, cfgFile, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigDirs, tmpl.ConfigFile)
|
appendConfig(opts, cfgFile, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigDirs, tmpl.ConfigFile)
|
||||||
@@ -633,6 +630,23 @@ func appExists(checker utils.AppChecker, checkCmd []string, checkFlatpaks []stri
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type vscodeEditor struct {
|
||||||
|
name string
|
||||||
|
dataDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
var vscodeEditors = []vscodeEditor{
|
||||||
|
{"vscode", ".vscode"},
|
||||||
|
{"codium", ".vscode-oss"},
|
||||||
|
{"cursor", ".cursor"},
|
||||||
|
{"windsurf", ".windsurf"},
|
||||||
|
{"vscode-insiders", ".vscode-insiders"},
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e vscodeEditor) extensionsDir(homeDir string) string {
|
||||||
|
return filepath.Join(homeDir, e.dataDir, "extensions")
|
||||||
|
}
|
||||||
|
|
||||||
func appendVSCodeConfig(cfgFile *os.File, name, extBaseDir, shellDir string) {
|
func appendVSCodeConfig(cfgFile *os.File, name, extBaseDir, shellDir string) {
|
||||||
pattern := filepath.Join(extBaseDir, "danklinux.dms-theme-*")
|
pattern := filepath.Join(extBaseDir, "danklinux.dms-theme-*")
|
||||||
matches, err := filepath.Glob(pattern)
|
matches, err := filepath.Glob(pattern)
|
||||||
@@ -1168,16 +1182,8 @@ func CheckTemplates(checker utils.AppChecker) []TemplateCheck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkVSCodeExtension(homeDir string) bool {
|
func checkVSCodeExtension(homeDir string) bool {
|
||||||
extDirs := []string{
|
for _, editor := range vscodeEditors {
|
||||||
filepath.Join(homeDir, ".vscode/extensions"),
|
pattern := filepath.Join(editor.extensionsDir(homeDir), "danklinux.dms-theme-*")
|
||||||
filepath.Join(homeDir, ".vscode-oss/extensions"),
|
|
||||||
filepath.Join(homeDir, ".config/Code - OSS/extensions"),
|
|
||||||
filepath.Join(homeDir, ".cursor/extensions"),
|
|
||||||
filepath.Join(homeDir, ".windsurf/extensions"),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, extDir := range extDirs {
|
|
||||||
pattern := filepath.Join(extDir, "danklinux.dms-theme-*")
|
|
||||||
if matches, err := filepath.Glob(pattern); err == nil && len(matches) > 0 {
|
if matches, err := filepath.Glob(pattern); err == nil && len(matches) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
package plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
const pluginLockfileVersion = 1
|
||||||
|
|
||||||
|
var gitCommitPattern = regexp.MustCompile(`^[0-9a-fA-F]{40}$`)
|
||||||
|
|
||||||
|
var scpLikeRepoPattern = regexp.MustCompile(`^[^@:/\s]+@[^@:/\s]+:\S+$`)
|
||||||
|
|
||||||
|
type PluginLockfile struct {
|
||||||
|
LockfileVersion int `json:"lockfileVersion"`
|
||||||
|
Plugins map[string]LockedPlugin `json:"plugins"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LockedPlugin struct {
|
||||||
|
Repo string `json:"repo"`
|
||||||
|
Path string `json:"path,omitempty"`
|
||||||
|
Commit string `json:"commit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LockStore struct {
|
||||||
|
fs afero.Fs
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLockStore(fs afero.Fs, path string) *LockStore {
|
||||||
|
return &LockStore{fs: fs, path: path}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPluginLockfile() PluginLockfile {
|
||||||
|
return PluginLockfile{
|
||||||
|
LockfileVersion: pluginLockfileVersion,
|
||||||
|
Plugins: make(map[string]LockedPlugin),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LockStore) Path() string {
|
||||||
|
return s.path
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LockStore) Exists() (bool, error) {
|
||||||
|
return afero.Exists(s.fs, s.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LockStore) Load() (PluginLockfile, error) {
|
||||||
|
data, err := afero.ReadFile(s.fs, s.path)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return NewPluginLockfile(), nil
|
||||||
|
}
|
||||||
|
return PluginLockfile{}, fmt.Errorf("failed to read plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParsePluginLockfile(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParsePluginLockfile(data []byte) (PluginLockfile, error) {
|
||||||
|
var lock PluginLockfile
|
||||||
|
if err := json.Unmarshal(data, &lock); err != nil {
|
||||||
|
return PluginLockfile{}, fmt.Errorf("failed to parse plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
if lock.Plugins == nil {
|
||||||
|
lock.Plugins = make(map[string]LockedPlugin)
|
||||||
|
}
|
||||||
|
if err := lock.Validate(); err != nil {
|
||||||
|
return PluginLockfile{}, err
|
||||||
|
}
|
||||||
|
return lock, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LockStore) Write(lock PluginLockfile) error {
|
||||||
|
if err := lock.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.MarshalIndent(lock, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to encode plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
data = append(data, '\n')
|
||||||
|
|
||||||
|
if err := s.fs.MkdirAll(filepath.Dir(s.path), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create plugin lockfile directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpPath := s.path + ".tmp"
|
||||||
|
if err := afero.WriteFile(s.fs, tmpPath, data, 0o644); err != nil {
|
||||||
|
return fmt.Errorf("failed to write temporary plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
defer s.fs.Remove(tmpPath) //nolint:errcheck
|
||||||
|
|
||||||
|
if err := s.fs.Rename(tmpPath, s.path); err != nil {
|
||||||
|
return fmt.Errorf("failed to replace plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lock PluginLockfile) Validate() error {
|
||||||
|
if lock.LockfileVersion != pluginLockfileVersion {
|
||||||
|
return fmt.Errorf("unsupported plugin lockfile version %d (expected %d)", lock.LockfileVersion, pluginLockfileVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
repoCommits := make(map[string]string)
|
||||||
|
for id, plugin := range lock.Plugins {
|
||||||
|
if !isSafePluginPathComponent(id) {
|
||||||
|
return fmt.Errorf("invalid locked plugin id: %q", id)
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(plugin.Repo) == "" {
|
||||||
|
return fmt.Errorf("locked plugin %q has no repository", id)
|
||||||
|
}
|
||||||
|
if err := validatePluginRepo(plugin.Repo); err != nil {
|
||||||
|
return fmt.Errorf("locked plugin %q: %w", id, err)
|
||||||
|
}
|
||||||
|
if !gitCommitPattern.MatchString(plugin.Commit) {
|
||||||
|
return fmt.Errorf("locked plugin %q has invalid commit %q", id, plugin.Commit)
|
||||||
|
}
|
||||||
|
if err := validatePluginRepoPath(plugin.Path); err != nil {
|
||||||
|
return fmt.Errorf("locked plugin %q: %w", id, err)
|
||||||
|
}
|
||||||
|
if commit, ok := repoCommits[plugin.Repo]; ok && !strings.EqualFold(commit, plugin.Commit) {
|
||||||
|
return fmt.Errorf("plugins from repository %q must use the same commit", plugin.Repo)
|
||||||
|
}
|
||||||
|
repoCommits[plugin.Repo] = plugin.Commit
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validatePluginRepo(repo string) error {
|
||||||
|
parsed, err := url.Parse(repo)
|
||||||
|
if err != nil {
|
||||||
|
if scpLikeRepoPattern.MatchString(repo) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid repository URL %q", repo)
|
||||||
|
}
|
||||||
|
if parsed.User == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, hasPassword := parsed.User.Password(); hasPassword {
|
||||||
|
return fmt.Errorf("repository URL must not contain credentials")
|
||||||
|
}
|
||||||
|
switch parsed.Scheme {
|
||||||
|
case "http", "https":
|
||||||
|
return fmt.Errorf("repository URL must not contain credentials")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validatePluginRepoPath(path string) error {
|
||||||
|
if path == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
clean := filepath.Clean(path)
|
||||||
|
if filepath.IsAbs(clean) || clean == ".." || strings.HasPrefix(clean, ".."+string(filepath.Separator)) {
|
||||||
|
return fmt.Errorf("invalid repository path %q", path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lock PluginLockfile) IDs() []string {
|
||||||
|
ids := make([]string, 0, len(lock.Plugins))
|
||||||
|
for id := range lock.Plugins {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
sort.Strings(ids)
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lock *PluginLockfile) SetRepositoryCommit(repo, commit string) {
|
||||||
|
for id, plugin := range lock.Plugins {
|
||||||
|
if plugin.Repo != repo {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
plugin.Commit = commit
|
||||||
|
lock.Plugins[id] = plugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lock PluginLockfile) Clone() PluginLockfile {
|
||||||
|
cloned := NewPluginLockfile()
|
||||||
|
for id, plugin := range lock.Plugins {
|
||||||
|
cloned.Plugins[id] = plugin
|
||||||
|
}
|
||||||
|
return cloned
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testCommit = "0123456789abcdef0123456789abcdef01234567"
|
||||||
|
|
||||||
|
func TestPluginLockfileRoundTrip(t *testing.T) {
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
store := NewLockStore(fs, "/config/plugins.lock.json")
|
||||||
|
lock := NewPluginLockfile()
|
||||||
|
lock.Plugins["weather"] = LockedPlugin{
|
||||||
|
Repo: "https://github.com/example/plugins.git",
|
||||||
|
Path: "plugins/weather",
|
||||||
|
Commit: testCommit,
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, store.Write(lock))
|
||||||
|
loaded, err := store.Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, lock, loaded)
|
||||||
|
|
||||||
|
data, err := afero.ReadFile(fs, store.Path())
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "{\n \"lockfileVersion\": 1,\n \"plugins\": {\n \"weather\": {\n \"repo\": \"https://github.com/example/plugins.git\",\n \"path\": \"plugins/weather\",\n \"commit\": \"0123456789abcdef0123456789abcdef01234567\"\n }\n }\n}\n", string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginLockfileValidation(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
lock PluginLockfile
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "rejects unsupported version",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 2, Plugins: map[string]LockedPlugin{}},
|
||||||
|
want: "unsupported plugin lockfile version",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects unsafe id",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{"../bad": {Repo: "repo", Commit: testCommit}}},
|
||||||
|
want: "invalid locked plugin id",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects unsafe repository path",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{"bad": {Repo: "repo", Path: "../bad", Commit: testCommit}}},
|
||||||
|
want: "invalid repository path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects abbreviated commit",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{"bad": {Repo: "repo", Commit: "abc123"}}},
|
||||||
|
want: "invalid commit",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects repository credentials",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{"bad": {Repo: "https://token@example.com/plugin.git", Commit: testCommit}}},
|
||||||
|
want: "must not contain credentials",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects ssh password",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{"bad": {Repo: "ssh://git:secret@example.com/plugin.git", Commit: testCommit}}},
|
||||||
|
want: "must not contain credentials",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rejects conflicting monorepo commits",
|
||||||
|
lock: PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{
|
||||||
|
"one": {Repo: "repo", Commit: testCommit},
|
||||||
|
"two": {Repo: "repo", Commit: "1123456789abcdef0123456789abcdef01234567"},
|
||||||
|
}},
|
||||||
|
want: "must use the same commit",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := tt.lock.Validate()
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), tt.want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginLockfileAcceptsSSHRemotes(t *testing.T) {
|
||||||
|
repos := []string{
|
||||||
|
"https://github.com/user/plugin.git",
|
||||||
|
"ssh://git@github.com/user/plugin.git",
|
||||||
|
"git@github.com:user/plugin.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, repo := range repos {
|
||||||
|
t.Run(repo, func(t *testing.T) {
|
||||||
|
lock := PluginLockfile{LockfileVersion: 1, Plugins: map[string]LockedPlugin{
|
||||||
|
"plugin": {Repo: repo, Commit: testCommit},
|
||||||
|
}}
|
||||||
|
assert.NoError(t, lock.Validate())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMissingPluginLockfileIsEmpty(t *testing.T) {
|
||||||
|
store := NewLockStore(afero.NewMemMapFs(), "/config/plugins.lock.json")
|
||||||
|
lock, err := store.Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, pluginLockfileVersion, lock.LockfileVersion)
|
||||||
|
assert.Empty(t, lock.Plugins)
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
type Manager struct {
|
type Manager struct {
|
||||||
fs afero.Fs
|
fs afero.Fs
|
||||||
pluginsDir string
|
pluginsDir string
|
||||||
|
lockPath string
|
||||||
gitClient GitClient
|
gitClient GitClient
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ func NewManagerWithFs(fs afero.Fs) (*Manager, error) {
|
|||||||
return &Manager{
|
return &Manager{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
pluginsDir: pluginsDir,
|
pluginsDir: pluginsDir,
|
||||||
|
lockPath: getPluginLockPath(),
|
||||||
gitClient: &realGitClient{},
|
gitClient: &realGitClient{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -41,6 +43,15 @@ func getPluginsDir() string {
|
|||||||
return filepath.Join(configDir, "DankMaterialShell", "plugins")
|
return filepath.Join(configDir, "DankMaterialShell", "plugins")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPluginLockPath() string {
|
||||||
|
configDir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to get user config dir", "err", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return filepath.Join(configDir, "DankMaterialShell", "plugins.lock.json")
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) IsInstalled(plugin Plugin) (bool, error) {
|
func (m *Manager) IsInstalled(plugin Plugin) (bool, error) {
|
||||||
path, err := m.findInstalledPath(plugin.ID)
|
path, err := m.findInstalledPath(plugin.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +129,12 @@ func (m *Manager) findInDir(dir, pluginID string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Install(plugin Plugin) error {
|
func (m *Manager) Install(plugin Plugin) error {
|
||||||
|
if !isSafePluginPathComponent(plugin.ID) {
|
||||||
|
return fmt.Errorf("invalid plugin id: %q", plugin.ID)
|
||||||
|
}
|
||||||
|
|
||||||
pluginPath := filepath.Join(m.pluginsDir, plugin.ID)
|
pluginPath := filepath.Join(m.pluginsDir, plugin.ID)
|
||||||
|
repoPath := pluginPath
|
||||||
|
|
||||||
exists, err := afero.DirExists(m.fs, pluginPath)
|
exists, err := afero.DirExists(m.fs, pluginPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,6 +144,18 @@ func (m *Manager) Install(plugin Plugin) error {
|
|||||||
if exists {
|
if exists {
|
||||||
return fmt.Errorf("plugin already installed: %s", plugin.Name)
|
return fmt.Errorf("plugin already installed: %s", plugin.Name)
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(plugin.Repo) == "" {
|
||||||
|
return fmt.Errorf("plugin repository is required")
|
||||||
|
}
|
||||||
|
if err := validatePluginRepo(plugin.Repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := validatePluginRepoPath(plugin.Path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := m.ensureLockfile(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.fs.MkdirAll(m.pluginsDir, 0o755); err != nil {
|
if err := m.fs.MkdirAll(m.pluginsDir, 0o755); err != nil {
|
||||||
return fmt.Errorf("failed to create plugins directory: %w", err)
|
return fmt.Errorf("failed to create plugins directory: %w", err)
|
||||||
@@ -140,7 +168,7 @@ func (m *Manager) Install(plugin Plugin) error {
|
|||||||
|
|
||||||
if plugin.Path != "" {
|
if plugin.Path != "" {
|
||||||
repoName := m.getRepoName(plugin.Repo)
|
repoName := m.getRepoName(plugin.Repo)
|
||||||
repoPath := filepath.Join(reposDir, repoName)
|
repoPath = filepath.Join(reposDir, repoName)
|
||||||
|
|
||||||
repoExists, err := afero.DirExists(m.fs, repoPath)
|
repoExists, err := afero.DirExists(m.fs, repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -178,12 +206,13 @@ func (m *Manager) Install(plugin Plugin) error {
|
|||||||
if err := m.createSymlink(sourcePath, pluginPath); err != nil {
|
if err := m.createSymlink(sourcePath, pluginPath); err != nil {
|
||||||
return fmt.Errorf("failed to create symlink: %w", err)
|
return fmt.Errorf("failed to create symlink: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
metaPath := pluginPath + ".meta"
|
metaPath := pluginPath + ".meta"
|
||||||
metaContent := fmt.Sprintf("repo=%s\npath=%s\nrepodir=%s", plugin.Repo, plugin.Path, repoName)
|
metaContent := fmt.Sprintf("repo=%s\npath=%s\nrepodir=%s", plugin.Repo, plugin.Path, repoName)
|
||||||
if err := afero.WriteFile(m.fs, metaPath, []byte(metaContent), 0o644); err != nil {
|
if err := afero.WriteFile(m.fs, metaPath, []byte(metaContent), 0o644); err != nil {
|
||||||
return fmt.Errorf("failed to write metadata: %w", err)
|
m.fs.Remove(pluginPath) //nolint:errcheck
|
||||||
|
return fmt.Errorf("failed to write plugin repository metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if err := m.gitClient.PlainClone(pluginPath, plugin.Repo); err != nil {
|
if err := m.gitClient.PlainClone(pluginPath, plugin.Repo); err != nil {
|
||||||
m.fs.RemoveAll(pluginPath) //nolint:errcheck
|
m.fs.RemoveAll(pluginPath) //nolint:errcheck
|
||||||
@@ -191,6 +220,16 @@ func (m *Manager) Install(plugin Plugin) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := m.recordInstalledPlugin(plugin, repoPath); err != nil {
|
||||||
|
if plugin.Path != "" {
|
||||||
|
m.fs.Remove(pluginPath) //nolint:errcheck
|
||||||
|
m.fs.Remove(pluginPath + ".meta") //nolint:errcheck
|
||||||
|
} else {
|
||||||
|
m.fs.RemoveAll(pluginPath) //nolint:errcheck
|
||||||
|
}
|
||||||
|
return fmt.Errorf("failed to update plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +246,15 @@ func (m *Manager) createSymlink(source, dest string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Update(plugin Plugin) error {
|
func (m *Manager) Update(plugin Plugin) error {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if locked, ok := lock.Plugins[plugin.ID]; ok {
|
||||||
|
plugin.Repo = locked.Repo
|
||||||
|
plugin.Path = locked.Path
|
||||||
|
}
|
||||||
|
|
||||||
pluginPath, err := m.findInstalledPath(plugin.ID)
|
pluginPath, err := m.findInstalledPath(plugin.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find plugin: %w", err)
|
return fmt.Errorf("failed to find plugin: %w", err)
|
||||||
@@ -219,46 +267,42 @@ func (m *Manager) Update(plugin Plugin) error {
|
|||||||
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
||||||
return fmt.Errorf("cannot update system plugin: %s", plugin.Name)
|
return fmt.Errorf("cannot update system plugin: %s", plugin.Name)
|
||||||
}
|
}
|
||||||
|
if plugin.Repo == "" {
|
||||||
metaPath := pluginPath + ".meta"
|
plugin.Repo, err = m.gitClient.OriginURL(pluginPath)
|
||||||
metaExists, err := afero.Exists(m.fs, metaPath)
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("failed to read plugin origin: %w", err)
|
||||||
return fmt.Errorf("failed to check metadata: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if metaExists {
|
|
||||||
reposDir := filepath.Join(m.pluginsDir, ".repos")
|
|
||||||
repoName := m.getRepoName(plugin.Repo)
|
|
||||||
repoPath := filepath.Join(reposDir, repoName)
|
|
||||||
|
|
||||||
// Try to pull, if it fails (e.g., shallow clone corruption), delete and re-clone
|
|
||||||
if err := m.gitClient.Pull(repoPath); err != nil {
|
|
||||||
// Repository is likely corrupted or has issues, delete and re-clone
|
|
||||||
if err := m.fs.RemoveAll(repoPath); err != nil {
|
|
||||||
return fmt.Errorf("failed to remove corrupted repository: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.gitClient.PlainClone(repoPath, plugin.Repo); err != nil {
|
|
||||||
return fmt.Errorf("failed to re-clone repository: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Try to pull, if it fails, delete and re-clone
|
|
||||||
if err := m.gitClient.Pull(pluginPath); err != nil {
|
|
||||||
if err := m.fs.RemoveAll(pluginPath); err != nil {
|
|
||||||
return fmt.Errorf("failed to remove corrupted plugin: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.gitClient.PlainClone(pluginPath, plugin.Repo); err != nil {
|
|
||||||
return fmt.Errorf("failed to re-clone plugin: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repoPath := m.repositoryPath(plugin.ID, LockedPlugin{Repo: plugin.Repo, Path: plugin.Path})
|
||||||
|
if err := m.gitClient.Pull(repoPath); err != nil {
|
||||||
|
if err := m.fs.RemoveAll(repoPath); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove corrupted plugin repository: %w", err)
|
||||||
|
}
|
||||||
|
if err := m.gitClient.PlainClone(repoPath, plugin.Repo); err != nil {
|
||||||
|
return fmt.Errorf("failed to re-clone plugin repository: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.recordInstalledPlugin(plugin, repoPath); err != nil {
|
||||||
|
if locked, ok := lock.Plugins[plugin.ID]; ok {
|
||||||
|
m.gitClient.CheckoutRevision(repoPath, locked.Commit) //nolint:errcheck
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Uninstall(plugin Plugin) error {
|
func (m *Manager) Uninstall(plugin Plugin) error {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if locked, ok := lock.Plugins[plugin.ID]; ok {
|
||||||
|
plugin.Repo = locked.Repo
|
||||||
|
plugin.Path = locked.Path
|
||||||
|
}
|
||||||
|
|
||||||
pluginPath, err := m.findInstalledPath(plugin.ID)
|
pluginPath, err := m.findInstalledPath(plugin.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find plugin: %w", err)
|
return fmt.Errorf("failed to find plugin: %w", err)
|
||||||
@@ -271,70 +315,64 @@ func (m *Manager) Uninstall(plugin Plugin) error {
|
|||||||
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
||||||
return fmt.Errorf("cannot uninstall system plugin: %s", plugin.Name)
|
return fmt.Errorf("cannot uninstall system plugin: %s", plugin.Name)
|
||||||
}
|
}
|
||||||
|
updatedLock := lock.Clone()
|
||||||
metaPath := pluginPath + ".meta"
|
delete(updatedLock.Plugins, plugin.ID)
|
||||||
metaExists, err := afero.Exists(m.fs, metaPath)
|
if err := m.lockStore().Write(updatedLock); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return fmt.Errorf("failed to check metadata: %w", err)
|
}
|
||||||
|
rollbackLock := func(err error) error {
|
||||||
|
if rollbackErr := m.lockStore().Write(lock); rollbackErr != nil {
|
||||||
|
return fmt.Errorf("%w (also failed to restore plugin lockfile: %v)", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if metaExists {
|
metaPath := pluginPath + ".meta"
|
||||||
|
if plugin.Path != "" {
|
||||||
reposDir := filepath.Join(m.pluginsDir, ".repos")
|
reposDir := filepath.Join(m.pluginsDir, ".repos")
|
||||||
repoName := m.getRepoName(plugin.Repo)
|
repoName := m.getRepoName(plugin.Repo)
|
||||||
repoPath := filepath.Join(reposDir, repoName)
|
repoPath := filepath.Join(reposDir, repoName)
|
||||||
|
|
||||||
shouldCleanup, err := m.shouldCleanupRepo(repoPath, plugin.Repo, plugin.ID)
|
shouldCleanup, err := m.shouldCleanupRepo(plugin.Repo, plugin.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to check repo cleanup: %w", err)
|
return rollbackLock(fmt.Errorf("failed to check repo cleanup: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.fs.Remove(pluginPath); err != nil {
|
if err := m.fs.Remove(pluginPath); err != nil {
|
||||||
return fmt.Errorf("failed to remove symlink: %w", err)
|
return rollbackLock(fmt.Errorf("failed to remove symlink: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.fs.Remove(metaPath); err != nil {
|
if metaExists, _ := afero.Exists(m.fs, metaPath); metaExists {
|
||||||
return fmt.Errorf("failed to remove metadata: %w", err)
|
if err := m.fs.Remove(metaPath); err != nil {
|
||||||
|
return rollbackLock(fmt.Errorf("failed to remove metadata: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldCleanup {
|
if shouldCleanup {
|
||||||
if err := m.fs.RemoveAll(repoPath); err != nil {
|
if err := m.fs.RemoveAll(repoPath); err != nil {
|
||||||
return fmt.Errorf("failed to cleanup repository: %w", err)
|
return rollbackLock(fmt.Errorf("failed to cleanup repository: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := m.fs.RemoveAll(pluginPath); err != nil {
|
if err := m.fs.RemoveAll(pluginPath); err != nil {
|
||||||
return fmt.Errorf("failed to remove plugin: %w", err)
|
return rollbackLock(fmt.Errorf("failed to remove plugin: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) shouldCleanupRepo(repoPath, repoURL, excludePlugin string) (bool, error) {
|
func (m *Manager) shouldCleanupRepo(repoURL, excludePlugin string) (bool, error) {
|
||||||
installed, err := m.ListInstalled()
|
lock, err := m.ensureLockfile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
for id, plugin := range lock.Plugins {
|
||||||
registry, err := NewRegistry()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
allPlugins, err := registry.List()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, id := range installed {
|
|
||||||
if id == excludePlugin {
|
if id == excludePlugin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if plugin.Repo == repoURL && plugin.Path != "" {
|
||||||
for _, p := range allPlugins {
|
return false, nil
|
||||||
if p.ID == id && p.Repo == repoURL && p.Path != "" {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,6 +494,16 @@ func (m *Manager) UninstallByIDOrName(idOrName string) error {
|
|||||||
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
||||||
return fmt.Errorf("cannot uninstall system plugin: %s", idOrName)
|
return fmt.Errorf("cannot uninstall system plugin: %s", idOrName)
|
||||||
}
|
}
|
||||||
|
manifest := m.getPluginManifest(pluginPath)
|
||||||
|
if manifest != nil {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if locked, ok := lock.Plugins[manifest.ID]; ok {
|
||||||
|
return m.Uninstall(Plugin{ID: manifest.ID, Name: manifest.Name, Repo: locked.Repo, Path: locked.Path})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
metaPath := pluginPath + ".meta"
|
metaPath := pluginPath + ".meta"
|
||||||
metaExists, _ := afero.Exists(m.fs, metaPath)
|
metaExists, _ := afero.Exists(m.fs, metaPath)
|
||||||
@@ -488,6 +536,16 @@ func (m *Manager) UpdateByIDOrName(idOrName string) error {
|
|||||||
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
if strings.HasPrefix(pluginPath, "/etc/xdg/quickshell/dms-plugins") {
|
||||||
return fmt.Errorf("cannot update system plugin: %s", idOrName)
|
return fmt.Errorf("cannot update system plugin: %s", idOrName)
|
||||||
}
|
}
|
||||||
|
manifest := m.getPluginManifest(pluginPath)
|
||||||
|
if manifest != nil {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if locked, ok := lock.Plugins[manifest.ID]; ok {
|
||||||
|
return m.Update(Plugin{ID: manifest.ID, Name: manifest.Name, Repo: locked.Repo, Path: locked.Path})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
metaPath := pluginPath + ".meta"
|
metaPath := pluginPath + ".meta"
|
||||||
metaExists, _ := afero.Exists(m.fs, metaPath)
|
metaExists, _ := afero.Exists(m.fs, metaPath)
|
||||||
@@ -502,8 +560,14 @@ func (m *Manager) UpdateByIDOrName(idOrName string) error {
|
|||||||
if err := m.gitClient.Pull(pluginPath); err != nil {
|
if err := m.gitClient.Pull(pluginPath); err != nil {
|
||||||
return fmt.Errorf("failed to update plugin: %w", err)
|
return fmt.Errorf("failed to update plugin: %w", err)
|
||||||
}
|
}
|
||||||
|
if manifest == nil {
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
repo, err := m.gitClient.OriginURL(pluginPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read plugin origin: %w", err)
|
||||||
|
}
|
||||||
|
return m.recordInstalledPlugin(Plugin{ID: manifest.ID, Name: manifest.Name, Repo: repo}, pluginPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) findInstalledPathByIDOrName(idOrName string) (string, error) {
|
func (m *Manager) findInstalledPathByIDOrName(idOrName string) (string, error) {
|
||||||
@@ -572,6 +636,15 @@ func (m *Manager) findInDirByIDOrName(dir, idOrName string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) HasUpdates(pluginID string, plugin Plugin) (hasUpdates bool, diffURL string, err error) {
|
func (m *Manager) HasUpdates(pluginID string, plugin Plugin) (hasUpdates bool, diffURL string, err error) {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return false, "", err
|
||||||
|
}
|
||||||
|
if locked, ok := lock.Plugins[pluginID]; ok {
|
||||||
|
plugin.Repo = locked.Repo
|
||||||
|
plugin.Path = locked.Path
|
||||||
|
}
|
||||||
|
|
||||||
pluginPath, err := m.findInstalledPath(pluginID)
|
pluginPath, err := m.findInstalledPath(pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", fmt.Errorf("failed to find plugin: %w", err)
|
return false, "", fmt.Errorf("failed to find plugin: %w", err)
|
||||||
@@ -585,25 +658,11 @@ func (m *Manager) HasUpdates(pluginID string, plugin Plugin) (hasUpdates bool, d
|
|||||||
return false, "", nil
|
return false, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
metaPath := pluginPath + ".meta"
|
repoPath := pluginPath
|
||||||
metaExists, err := afero.Exists(m.fs, metaPath)
|
if plugin.Path != "" {
|
||||||
if err != nil {
|
repoPath = m.repositoryPath(pluginID, LockedPlugin{Repo: plugin.Repo, Path: plugin.Path})
|
||||||
return false, "", fmt.Errorf("failed to check metadata: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var hasUp bool
|
|
||||||
var localHash, remoteHash string
|
|
||||||
if metaExists {
|
|
||||||
// Plugin is from a monorepo, check the repo directory
|
|
||||||
reposDir := filepath.Join(m.pluginsDir, ".repos")
|
|
||||||
repoName := m.getRepoName(plugin.Repo)
|
|
||||||
repoPath := filepath.Join(reposDir, repoName)
|
|
||||||
|
|
||||||
hasUp, localHash, remoteHash, err = m.gitClient.HasUpdates(repoPath)
|
|
||||||
} else {
|
|
||||||
// Plugin is a standalone repo
|
|
||||||
hasUp, localHash, remoteHash, err = m.gitClient.HasUpdates(pluginPath)
|
|
||||||
}
|
}
|
||||||
|
hasUp, localHash, remoteHash, err := m.gitClient.HasUpdates(repoPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", err
|
return false, "", err
|
||||||
|
|||||||
@@ -0,0 +1,299 @@
|
|||||||
|
package plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *Manager) lockStore() *LockStore {
|
||||||
|
lockPath := m.lockPath
|
||||||
|
if lockPath == "" {
|
||||||
|
lockPath = filepath.Join(filepath.Dir(m.pluginsDir), "plugins.lock.json")
|
||||||
|
}
|
||||||
|
return NewLockStore(m.fs, lockPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) GetLockfilePath() string {
|
||||||
|
return m.lockStore().Path()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) ensureLockfile() (PluginLockfile, error) {
|
||||||
|
store := m.lockStore()
|
||||||
|
exists, err := store.Exists()
|
||||||
|
if err != nil {
|
||||||
|
return PluginLockfile{}, fmt.Errorf("failed to check plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return store.Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
lock, _, err := m.SnapshotLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return PluginLockfile{}, err
|
||||||
|
}
|
||||||
|
if err := store.Write(lock); err != nil {
|
||||||
|
return PluginLockfile{}, err
|
||||||
|
}
|
||||||
|
return lock, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) SnapshotLockfile() (PluginLockfile, []string, error) {
|
||||||
|
lock := NewPluginLockfile()
|
||||||
|
warnings := []string{}
|
||||||
|
|
||||||
|
exists, err := afero.DirExists(m.fs, m.pluginsDir)
|
||||||
|
if err != nil {
|
||||||
|
return PluginLockfile{}, nil, fmt.Errorf("failed to check plugins directory: %w", err)
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return lock, warnings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := afero.ReadDir(m.fs, m.pluginsDir)
|
||||||
|
if err != nil {
|
||||||
|
return PluginLockfile{}, nil, fmt.Errorf("failed to read plugins directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
name := entry.Name()
|
||||||
|
if name == ".repos" || strings.HasSuffix(name, ".meta") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginPath := filepath.Join(m.pluginsDir, name)
|
||||||
|
manifest := m.getPluginManifest(pluginPath)
|
||||||
|
if manifest == nil || manifest.ID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
locked, repoPath, err := m.lockedPluginFromInstall(pluginPath)
|
||||||
|
if err != nil {
|
||||||
|
warnings = append(warnings, fmt.Sprintf("%s: %v", manifest.ID, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
commit, err := m.gitClient.CurrentRevision(repoPath)
|
||||||
|
if err != nil {
|
||||||
|
warnings = append(warnings, fmt.Sprintf("%s: cannot read git revision: %v", manifest.ID, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
locked.Commit = commit
|
||||||
|
lock.SetRepositoryCommit(locked.Repo, commit)
|
||||||
|
lock.Plugins[manifest.ID] = locked
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := lock.Validate(); err != nil {
|
||||||
|
return PluginLockfile{}, warnings, err
|
||||||
|
}
|
||||||
|
return lock, warnings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) lockedPluginFromInstall(pluginPath string) (LockedPlugin, string, error) {
|
||||||
|
metaPath := pluginPath + ".meta"
|
||||||
|
if metaExists, _ := afero.Exists(m.fs, metaPath); metaExists {
|
||||||
|
data, err := afero.ReadFile(m.fs, metaPath)
|
||||||
|
if err != nil {
|
||||||
|
return LockedPlugin{}, "", fmt.Errorf("failed to read legacy metadata: %w", err)
|
||||||
|
}
|
||||||
|
metadata := parseLegacyPluginMetadata(string(data))
|
||||||
|
repo := metadata["repo"]
|
||||||
|
path := metadata["path"]
|
||||||
|
repoDir := metadata["repodir"]
|
||||||
|
if repo == "" || repoDir == "" {
|
||||||
|
return LockedPlugin{}, "", fmt.Errorf("legacy metadata is incomplete")
|
||||||
|
}
|
||||||
|
if err := validatePluginRepo(repo); err != nil {
|
||||||
|
return LockedPlugin{}, "", err
|
||||||
|
}
|
||||||
|
if !isSafePluginPathComponent(repoDir) {
|
||||||
|
return LockedPlugin{}, "", fmt.Errorf("legacy repository directory is invalid")
|
||||||
|
}
|
||||||
|
if err := validatePluginRepoPath(path); err != nil {
|
||||||
|
return LockedPlugin{}, "", err
|
||||||
|
}
|
||||||
|
return LockedPlugin{Repo: repo, Path: path}, filepath.Join(m.pluginsDir, ".repos", repoDir), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := m.gitClient.OriginURL(pluginPath)
|
||||||
|
if err != nil {
|
||||||
|
return LockedPlugin{}, "", fmt.Errorf("plugin is not a managed git checkout")
|
||||||
|
}
|
||||||
|
if err := validatePluginRepo(repo); err != nil {
|
||||||
|
return LockedPlugin{}, "", err
|
||||||
|
}
|
||||||
|
return LockedPlugin{Repo: repo}, pluginPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseLegacyPluginMetadata(data string) map[string]string {
|
||||||
|
metadata := make(map[string]string)
|
||||||
|
for _, line := range strings.Split(data, "\n") {
|
||||||
|
key, value, ok := strings.Cut(line, "=")
|
||||||
|
if ok {
|
||||||
|
metadata[strings.TrimSpace(key)] = strings.TrimSpace(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) recordInstalledPlugin(plugin Plugin, repoPath string) error {
|
||||||
|
lock, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
commit, err := m.gitClient.CurrentRevision(repoPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read installed plugin revision: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
lock.SetRepositoryCommit(plugin.Repo, commit)
|
||||||
|
lock.Plugins[plugin.ID] = LockedPlugin{
|
||||||
|
Repo: plugin.Repo,
|
||||||
|
Path: plugin.Path,
|
||||||
|
Commit: commit,
|
||||||
|
}
|
||||||
|
return m.lockStore().Write(lock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) WriteCurrentLockfile(outputPath string) ([]string, error) {
|
||||||
|
lock, warnings, err := m.SnapshotLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return warnings, err
|
||||||
|
}
|
||||||
|
if err := m.lockStore().Write(lock); err != nil {
|
||||||
|
return warnings, err
|
||||||
|
}
|
||||||
|
if outputPath != "" && outputPath != m.GetLockfilePath() {
|
||||||
|
if err := NewLockStore(m.fs, outputPath).Write(lock); err != nil {
|
||||||
|
return warnings, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return warnings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) RestoreFromLockfile(sourcePath string, prune bool) error {
|
||||||
|
if sourcePath == "" {
|
||||||
|
sourcePath = m.GetLockfilePath()
|
||||||
|
}
|
||||||
|
sourceStore := NewLockStore(m.fs, sourcePath)
|
||||||
|
exists, err := sourceStore.Exists()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to check plugin lockfile: %w", err)
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("plugin lockfile not found: %s", sourcePath)
|
||||||
|
}
|
||||||
|
target, err := sourceStore.Load()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
current, err := m.ensureLockfile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range target.IDs() {
|
||||||
|
wanted := target.Plugins[id]
|
||||||
|
installedPath, err := m.findInstalledPath(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if installedPath != "" {
|
||||||
|
existing, managed := current.Plugins[id]
|
||||||
|
if !managed {
|
||||||
|
return fmt.Errorf("plugin %q is already installed but is not managed by the lockfile", id)
|
||||||
|
}
|
||||||
|
if existing.Repo != wanted.Repo || existing.Path != wanted.Path {
|
||||||
|
if err := m.UninstallByIDOrName(id); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
installedPath = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin := Plugin{ID: id, Name: id, Repo: wanted.Repo, Path: wanted.Path}
|
||||||
|
newlyInstalled := installedPath == ""
|
||||||
|
if installedPath == "" {
|
||||||
|
if err := m.Install(plugin); err != nil {
|
||||||
|
return fmt.Errorf("failed to restore plugin %q: %w", id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repoPath := m.repositoryPath(id, wanted)
|
||||||
|
previousCommit, err := m.gitClient.CurrentRevision(repoPath)
|
||||||
|
if err != nil {
|
||||||
|
if newlyInstalled {
|
||||||
|
m.UninstallByIDOrName(id) //nolint:errcheck
|
||||||
|
}
|
||||||
|
return fmt.Errorf("failed to read current revision for plugin %q: %w", id, err)
|
||||||
|
}
|
||||||
|
if err := m.gitClient.CheckoutRevision(repoPath, wanted.Commit); err != nil {
|
||||||
|
if newlyInstalled {
|
||||||
|
if rollbackErr := m.UninstallByIDOrName(id); rollbackErr != nil {
|
||||||
|
return fmt.Errorf("failed to restore plugin %q at %s: %w (also failed to remove the partial install: %v)", id, wanted.Commit, err, rollbackErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("failed to restore plugin %q at %s: %w", id, wanted.Commit, err)
|
||||||
|
}
|
||||||
|
rollback := func(restoreErr error) error {
|
||||||
|
if newlyInstalled {
|
||||||
|
if rollbackErr := m.UninstallByIDOrName(id); rollbackErr != nil {
|
||||||
|
return fmt.Errorf("%w (also failed to remove the partial install: %v)", restoreErr, rollbackErr)
|
||||||
|
}
|
||||||
|
return restoreErr
|
||||||
|
}
|
||||||
|
if rollbackErr := m.gitClient.CheckoutRevision(repoPath, previousCommit); rollbackErr != nil {
|
||||||
|
return fmt.Errorf("%w (also failed to restore revision %s: %v)", restoreErr, previousCommit, rollbackErr)
|
||||||
|
}
|
||||||
|
return restoreErr
|
||||||
|
}
|
||||||
|
pluginPath := installedPath
|
||||||
|
if pluginPath == "" {
|
||||||
|
pluginPath = filepath.Join(m.pluginsDir, id)
|
||||||
|
}
|
||||||
|
if actualID := m.getPluginID(pluginPath); actualID != id {
|
||||||
|
return rollback(fmt.Errorf("restored plugin %q has manifest id %q", id, actualID))
|
||||||
|
}
|
||||||
|
if err := m.recordInstalledPlugin(plugin, repoPath); err != nil {
|
||||||
|
return rollback(err)
|
||||||
|
}
|
||||||
|
current, err = m.lockStore().Load()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if prune {
|
||||||
|
for _, id := range current.IDs() {
|
||||||
|
if _, wanted := target.Plugins[id]; wanted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := m.UninstallByIDOrName(id); err != nil {
|
||||||
|
return fmt.Errorf("failed to prune plugin %q: %w", id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m.lockStore().Write(target)
|
||||||
|
}
|
||||||
|
|
||||||
|
merged, err := m.lockStore().Load()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for id, plugin := range target.Plugins {
|
||||||
|
merged.SetRepositoryCommit(plugin.Repo, plugin.Commit)
|
||||||
|
merged.Plugins[id] = plugin
|
||||||
|
}
|
||||||
|
return m.lockStore().Write(merged)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) repositoryPath(pluginID string, plugin LockedPlugin) string {
|
||||||
|
if plugin.Path != "" {
|
||||||
|
return filepath.Join(m.pluginsDir, ".repos", m.getRepoName(plugin.Repo))
|
||||||
|
}
|
||||||
|
if installedPath, err := m.findInDir(m.pluginsDir, pluginID); err == nil && installedPath != "" {
|
||||||
|
return installedPath
|
||||||
|
}
|
||||||
|
return filepath.Join(m.pluginsDir, pluginID)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -16,6 +17,7 @@ func setupTestManager(t *testing.T) (*Manager, afero.Fs, string) {
|
|||||||
manager := &Manager{
|
manager := &Manager{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
pluginsDir: pluginsDir,
|
pluginsDir: pluginsDir,
|
||||||
|
lockPath: "/config/plugins.lock.json",
|
||||||
gitClient: &mockGitClient{},
|
gitClient: &mockGitClient{},
|
||||||
}
|
}
|
||||||
return manager, fs, pluginsDir
|
return manager, fs, pluginsDir
|
||||||
@@ -245,3 +247,244 @@ func TestManagerGetPluginsDir(t *testing.T) {
|
|||||||
manager, _, pluginsDir := setupTestManager(t)
|
manager, _, pluginsDir := setupTestManager(t)
|
||||||
assert.Equal(t, pluginsDir, manager.GetPluginsDir())
|
assert.Equal(t, pluginsDir, manager.GetPluginsDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInstallUpdatesLockfile(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
plugin := Plugin{ID: "test-plugin", Name: "Test Plugin", Repo: "https://github.com/test/plugin.git"}
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
cloneFunc: func(path, _ string) error {
|
||||||
|
require.NoError(t, fs.MkdirAll(path, 0o755))
|
||||||
|
return afero.WriteFile(fs, filepath.Join(path, "plugin.json"), []byte(`{"id":"test-plugin"}`), 0o644)
|
||||||
|
},
|
||||||
|
revisionFunc: func(string) (string, error) { return testCommit, nil },
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, manager.Install(plugin))
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, LockedPlugin{Repo: plugin.Repo, Commit: testCommit}, lock.Plugins[plugin.ID])
|
||||||
|
exists, err := afero.Exists(fs, filepath.Join(pluginsDir, plugin.ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.True(t, exists)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateRefreshesLockedCommit(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
plugin := Plugin{ID: "test-plugin", Name: "Test Plugin", Repo: "https://github.com/test/plugin.git"}
|
||||||
|
pluginPath := filepath.Join(pluginsDir, plugin.ID)
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"test-plugin"}`), 0o644))
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
plugin.ID: {Repo: plugin.Repo, Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
newCommit := "1123456789abcdef0123456789abcdef01234567"
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
pullFunc: func(string) error { return nil },
|
||||||
|
revisionFunc: func(string) (string, error) { return newCommit, nil },
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, manager.Update(plugin))
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, newCommit, lock.Plugins[plugin.ID].Commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateResolvesRenamedPluginDirectory(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
plugin := Plugin{ID: "test-plugin", Name: "Test Plugin", Repo: "https://github.com/test/plugin.git"}
|
||||||
|
pluginPath := filepath.Join(pluginsDir, "renamed-dir")
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"test-plugin"}`), 0o644))
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
plugin.ID: {Repo: plugin.Repo, Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
var pulledPath string
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
pullFunc: func(path string) error {
|
||||||
|
pulledPath = path
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
cloneFunc: func(path, _ string) error {
|
||||||
|
t.Fatalf("unexpected clone to %s", path)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
revisionFunc: func(string) (string, error) { return testCommit, nil },
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, manager.Update(plugin))
|
||||||
|
assert.Equal(t, pluginPath, pulledPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUninstallRemovesLockedPlugin(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
plugin := Plugin{ID: "test-plugin", Name: "Test Plugin", Repo: "https://github.com/test/plugin.git"}
|
||||||
|
pluginPath := filepath.Join(pluginsDir, plugin.ID)
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"test-plugin"}`), 0o644))
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
plugin.ID: {Repo: plugin.Repo, Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
require.NoError(t, manager.Uninstall(plugin))
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotContains(t, lock.Plugins, plugin.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRestoreFromLockfileInstallsExactCommit(t *testing.T) {
|
||||||
|
manager, fs, _ := setupTestManager(t)
|
||||||
|
wantedCommit := "2123456789abcdef0123456789abcdef01234567"
|
||||||
|
incoming := PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
"restored": {Repo: "https://github.com/test/restored.git", Commit: wantedCommit},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.NoError(t, NewLockStore(fs, "/incoming.lock.json").Write(incoming))
|
||||||
|
currentCommit := testCommit
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
cloneFunc: func(path, _ string) error {
|
||||||
|
require.NoError(t, fs.MkdirAll(path, 0o755))
|
||||||
|
return afero.WriteFile(fs, filepath.Join(path, "plugin.json"), []byte(`{"id":"restored"}`), 0o644)
|
||||||
|
},
|
||||||
|
revisionFunc: func(string) (string, error) { return currentCommit, nil },
|
||||||
|
checkoutFunc: func(_ string, revision string) error {
|
||||||
|
currentCommit = revision
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, manager.RestoreFromLockfile("/incoming.lock.json", false))
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, wantedCommit, lock.Plugins["restored"].Commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSnapshotLockfileMigratesLegacyMonorepoMetadata(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
pluginPath := filepath.Join(pluginsDir, "legacy")
|
||||||
|
repoPath := filepath.Join(pluginsDir, ".repos", "legacy-repo")
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, fs.MkdirAll(repoPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"legacy"}`), 0o644))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, pluginPath+".meta", []byte("repo=https://github.com/test/suite.git\npath=plugins/legacy\nrepodir=legacy-repo"), 0o644))
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
revisionFunc: func(path string) (string, error) {
|
||||||
|
assert.Equal(t, repoPath, path)
|
||||||
|
return testCommit, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
lock, warnings, err := manager.SnapshotLockfile()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Empty(t, warnings)
|
||||||
|
assert.Equal(t, LockedPlugin{
|
||||||
|
Repo: "https://github.com/test/suite.git",
|
||||||
|
Path: "plugins/legacy",
|
||||||
|
Commit: testCommit,
|
||||||
|
}, lock.Plugins["legacy"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecordInstalledPluginUpdatesSharedRepositoryCommit(t *testing.T) {
|
||||||
|
manager, _, _ := setupTestManager(t)
|
||||||
|
repo := "https://github.com/test/suite.git"
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
"one": {Repo: repo, Path: "plugins/one", Commit: testCommit},
|
||||||
|
"two": {Repo: repo, Path: "plugins/two", Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
newCommit := "3123456789abcdef0123456789abcdef01234567"
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
revisionFunc: func(string) (string, error) { return newCommit, nil },
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, manager.recordInstalledPlugin(Plugin{ID: "one", Repo: repo, Path: "plugins/one"}, "/repo"))
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, newCommit, lock.Plugins["one"].Commit)
|
||||||
|
assert.Equal(t, newCommit, lock.Plugins["two"].Commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRestoreFromLockfilePrunesManagedPlugins(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
pluginPath := filepath.Join(pluginsDir, "old")
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"old","name":"Old"}`), 0o644))
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
"old": {Repo: "https://github.com/test/old.git", Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
require.NoError(t, NewLockStore(fs, "/empty.lock.json").Write(NewPluginLockfile()))
|
||||||
|
|
||||||
|
require.NoError(t, manager.RestoreFromLockfile("/empty.lock.json", true))
|
||||||
|
exists, err := afero.Exists(fs, pluginPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.False(t, exists)
|
||||||
|
lock, err := manager.lockStore().Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Empty(t, lock.Plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRestoreMissingLockfileDoesNotPrune(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
pluginPath := filepath.Join(pluginsDir, "kept")
|
||||||
|
require.NoError(t, fs.MkdirAll(pluginPath, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(pluginPath, "plugin.json"), []byte(`{"id":"kept"}`), 0o644))
|
||||||
|
require.NoError(t, manager.lockStore().Write(PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
"kept": {Repo: "https://github.com/test/kept.git", Commit: testCommit},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
err := manager.RestoreFromLockfile("/missing.lock.json", true)
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "not found")
|
||||||
|
exists, statErr := afero.Exists(fs, pluginPath)
|
||||||
|
require.NoError(t, statErr)
|
||||||
|
assert.True(t, exists)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRestoreFailedRevisionRemovesPartialInstall(t *testing.T) {
|
||||||
|
manager, fs, pluginsDir := setupTestManager(t)
|
||||||
|
incoming := PluginLockfile{
|
||||||
|
LockfileVersion: 1,
|
||||||
|
Plugins: map[string]LockedPlugin{
|
||||||
|
"broken": {Repo: "https://github.com/test/broken.git", Commit: testCommit},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.NoError(t, NewLockStore(fs, "/incoming.lock.json").Write(incoming))
|
||||||
|
manager.gitClient = &mockGitClient{
|
||||||
|
cloneFunc: func(path, _ string) error {
|
||||||
|
require.NoError(t, fs.MkdirAll(path, 0o755))
|
||||||
|
return afero.WriteFile(fs, filepath.Join(path, "plugin.json"), []byte(`{"id":"broken"}`), 0o644)
|
||||||
|
},
|
||||||
|
revisionFunc: func(string) (string, error) { return testCommit, nil },
|
||||||
|
checkoutFunc: func(string, string) error {
|
||||||
|
return errors.New("revision unavailable")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := manager.RestoreFromLockfile("/incoming.lock.json", false)
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "revision unavailable")
|
||||||
|
exists, statErr := afero.Exists(fs, filepath.Join(pluginsDir, "broken"))
|
||||||
|
require.NoError(t, statErr)
|
||||||
|
assert.False(t, exists)
|
||||||
|
lock, loadErr := manager.lockStore().Load()
|
||||||
|
require.NoError(t, loadErr)
|
||||||
|
assert.NotContains(t, lock.Plugins, "broken")
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ package plugins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
"github.com/go-git/go-git/v6"
|
"github.com/go-git/go-git/v6"
|
||||||
|
"github.com/go-git/go-git/v6/plumbing"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
const registryRepo = "https://github.com/AvengeMedia/dms-plugin-registry.git"
|
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -33,7 +34,10 @@ type Plugin struct {
|
|||||||
type GitClient interface {
|
type GitClient interface {
|
||||||
PlainClone(path string, url string) error
|
PlainClone(path string, url string) error
|
||||||
Pull(path string) error
|
Pull(path string) error
|
||||||
|
OriginURL(path string) (string, error)
|
||||||
HasUpdates(path string) (hasUpdates bool, localHash string, remoteHash string, err error)
|
HasUpdates(path string) (hasUpdates bool, localHash string, remoteHash string, err error)
|
||||||
|
CurrentRevision(path string) (string, error)
|
||||||
|
CheckoutRevision(path string, revision string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type realGitClient struct{}
|
type realGitClient struct{}
|
||||||
@@ -65,6 +69,22 @@ func (g *realGitClient) Pull(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *realGitClient) OriginURL(path string) (string, error) {
|
||||||
|
repo, err := git.PlainOpen(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
remote, err := repo.Remote("origin")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
urls := remote.Config().URLs
|
||||||
|
if len(urls) == 0 {
|
||||||
|
return "", errors.New("origin remote has no URL")
|
||||||
|
}
|
||||||
|
return urls[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *realGitClient) HasUpdates(path string) (bool, string, string, error) {
|
func (g *realGitClient) HasUpdates(path string) (bool, string, string, error) {
|
||||||
repo, err := git.PlainOpen(path)
|
repo, err := git.PlainOpen(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,11 +138,53 @@ func (g *realGitClient) HasUpdates(path string) (bool, string, string, error) {
|
|||||||
return localHash != remoteHead, localHash, remoteHead, nil
|
return localHash != remoteHead, localHash, remoteHead, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *realGitClient) CurrentRevision(path string) (string, error) {
|
||||||
|
repo, err := git.PlainOpen(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
head, err := repo.Head()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return head.Hash().String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *realGitClient) CheckoutRevision(path string, revision string) error {
|
||||||
|
if !gitCommitPattern.MatchString(revision) {
|
||||||
|
return fmt.Errorf("invalid git revision %q", revision)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := git.PlainOpen(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hash := plumbing.NewHash(revision)
|
||||||
|
if _, objectErr := repo.CommitObject(hash); objectErr != nil {
|
||||||
|
if _, remoteErr := repo.Remote("origin"); remoteErr != nil {
|
||||||
|
return fmt.Errorf("revision %s is not available in repository: %w", revision, objectErr)
|
||||||
|
}
|
||||||
|
fetchErr := repo.Fetch(&git.FetchOptions{})
|
||||||
|
if fetchErr != nil && fetchErr != git.NoErrAlreadyUpToDate {
|
||||||
|
return fmt.Errorf("failed to fetch locked revision: %w", fetchErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := repo.CommitObject(hash); err != nil {
|
||||||
|
return fmt.Errorf("revision %s is not available in repository: %w", revision, err)
|
||||||
|
}
|
||||||
|
worktree, err := repo.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return worktree.Reset(&git.ResetOptions{Commit: hash, Mode: git.HardReset})
|
||||||
|
}
|
||||||
|
|
||||||
type Registry struct {
|
type Registry struct {
|
||||||
fs afero.Fs
|
fs afero.Fs
|
||||||
cacheDir string
|
cacheDir string
|
||||||
plugins []Plugin
|
registries []registries.Source
|
||||||
git GitClient
|
plugins []Plugin
|
||||||
|
git GitClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRegistry() (*Registry, error) {
|
func NewRegistry() (*Registry, error) {
|
||||||
@@ -130,63 +192,63 @@ func NewRegistry() (*Registry, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRegistryWithFs(fs afero.Fs) (*Registry, error) {
|
func NewRegistryWithFs(fs afero.Fs) (*Registry, error) {
|
||||||
cacheDir := getCacheDir()
|
|
||||||
return &Registry{
|
return &Registry{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
cacheDir: cacheDir,
|
cacheDir: getCacheDir(),
|
||||||
git: &realGitClient{},
|
registries: registries.Load(fs),
|
||||||
|
git: &realGitClient{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Registry) cacheDirFor(src registries.Source) string {
|
||||||
|
return filepath.Join(r.cacheDir, src.Name)
|
||||||
|
}
|
||||||
|
|
||||||
func getCacheDir() string {
|
func getCacheDir() string {
|
||||||
return filepath.Join(os.TempDir(), "dankdots-plugin-registry")
|
return filepath.Join(os.TempDir(), "dankdots-plugin-registry")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) Update() error {
|
// A cached clone is reused only when its origin still matches the configured
|
||||||
exists, err := afero.DirExists(r.fs, r.cacheDir)
|
// URL; renamed or re-pointed registries re-clone instead of pulling from the
|
||||||
|
// stale remote.
|
||||||
|
func (r *Registry) updateOne(src registries.Source) error {
|
||||||
|
dir := r.cacheDirFor(src)
|
||||||
|
exists, err := afero.DirExists(r.fs, dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to check cache directory: %w", err)
|
return fmt.Errorf("failed to check cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if exists {
|
||||||
if err := r.fs.MkdirAll(filepath.Dir(r.cacheDir), 0o755); err != nil {
|
origin, originErr := r.git.OriginURL(dir)
|
||||||
return fmt.Errorf("failed to create cache directory: %w", err)
|
if originErr == nil && origin == src.URL && r.git.Pull(dir) == nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
if err := r.fs.RemoveAll(dir); err != nil {
|
||||||
if err := r.git.PlainClone(r.cacheDir, registryRepo); err != nil {
|
return fmt.Errorf("failed to remove stale registry cache: %w", err)
|
||||||
return fmt.Errorf("failed to clone registry: %w", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Try to pull, if it fails (e.g., shallow clone corruption), delete and re-clone
|
|
||||||
if err := r.git.Pull(r.cacheDir); err != nil {
|
|
||||||
// Repository is likely corrupted or has issues, delete and re-clone
|
|
||||||
if err := r.fs.RemoveAll(r.cacheDir); err != nil {
|
|
||||||
return fmt.Errorf("failed to remove corrupted registry: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.fs.MkdirAll(filepath.Dir(r.cacheDir), 0o755); err != nil {
|
|
||||||
return fmt.Errorf("failed to create cache directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.git.PlainClone(r.cacheDir, registryRepo); err != nil {
|
|
||||||
return fmt.Errorf("failed to re-clone registry: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.loadPlugins()
|
if err := r.fs.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create cache directory: %w", err)
|
||||||
|
}
|
||||||
|
if err := r.git.PlainClone(dir, src.URL); err != nil {
|
||||||
|
return fmt.Errorf("failed to clone: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) loadPlugins() error {
|
// A registry without a plugins/ directory is a valid themes-only registry.
|
||||||
pluginsDir := filepath.Join(r.cacheDir, "plugins")
|
func (r *Registry) loadPluginsFrom(dir string) ([]Plugin, error) {
|
||||||
|
pluginsDir := filepath.Join(dir, "plugins")
|
||||||
entries, err := afero.ReadDir(r.fs, pluginsDir)
|
entries, err := afero.ReadDir(r.fs, pluginsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read plugins directory: %w", err)
|
if os.IsNotExist(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("failed to read plugins directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.plugins = []Plugin{}
|
var plugins []Plugin
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if entry.IsDir() || filepath.Ext(entry.Name()) != ".json" {
|
if entry.IsDir() || filepath.Ext(entry.Name()) != ".json" {
|
||||||
continue
|
continue
|
||||||
@@ -206,15 +268,51 @@ func (r *Registry) loadPlugins() error {
|
|||||||
plugin.ID = strings.TrimSuffix(entry.Name(), ".json")
|
plugin.ID = strings.TrimSuffix(entry.Name(), ".json")
|
||||||
}
|
}
|
||||||
|
|
||||||
r.plugins = append(r.plugins, plugin)
|
plugins = append(plugins, plugin)
|
||||||
}
|
}
|
||||||
|
return plugins, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
// Pre-multi-registry caches were a single clone at the base dir; the per-name
|
||||||
|
// layout nests under it, so a leftover clone is deleted wholesale first.
|
||||||
|
func (r *Registry) resetLegacyCache() {
|
||||||
|
if exists, _ := afero.DirExists(r.fs, filepath.Join(r.cacheDir, ".git")); exists {
|
||||||
|
_ = r.fs.RemoveAll(r.cacheDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update refreshes every configured registry, aggregating plugins in
|
||||||
|
// declaration order (first occurrence of an ID wins). A failing registry is
|
||||||
|
// reported in the joined error but does not block the others.
|
||||||
|
func (r *Registry) Update() error {
|
||||||
|
r.resetLegacyCache()
|
||||||
|
r.plugins = []Plugin{}
|
||||||
|
seen := make(map[string]struct{})
|
||||||
|
var errs []error
|
||||||
|
for _, src := range r.registries {
|
||||||
|
if err := r.updateOne(src); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("registry %s: %w", src.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
plugins, err := r.loadPluginsFrom(r.cacheDirFor(src))
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("registry %s: %w", src.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, p := range plugins {
|
||||||
|
if _, dup := seen[p.ID]; dup {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[p.ID] = struct{}{}
|
||||||
|
r.plugins = append(r.plugins, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) List() ([]Plugin, error) {
|
func (r *Registry) List() ([]Plugin, error) {
|
||||||
if len(r.plugins) == 0 {
|
if len(r.plugins) == 0 {
|
||||||
if err := r.Update(); err != nil {
|
if err := r.Update(); err != nil && len(r.plugins) == 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,29 @@ package plugins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
|
"github.com/go-git/go-git/v6"
|
||||||
|
"github.com/go-git/go-git/v6/plumbing/object"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testRegistryURL = "https://example.com/test-registry.git"
|
||||||
|
|
||||||
type mockGitClient struct {
|
type mockGitClient struct {
|
||||||
cloneFunc func(path string, url string) error
|
cloneFunc func(path string, url string) error
|
||||||
pullFunc func(path string) error
|
pullFunc func(path string) error
|
||||||
|
originFunc func(path string) (string, error)
|
||||||
hasUpdatesFunc func(path string) (bool, string, string, error)
|
hasUpdatesFunc func(path string) (bool, string, string, error)
|
||||||
|
revisionFunc func(path string) (string, error)
|
||||||
|
checkoutFunc func(path string, revision string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockGitClient) PlainClone(path string, url string) error {
|
func (m *mockGitClient) PlainClone(path string, url string) error {
|
||||||
@@ -30,6 +41,13 @@ func (m *mockGitClient) Pull(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockGitClient) OriginURL(path string) (string, error) {
|
||||||
|
if m.originFunc != nil {
|
||||||
|
return m.originFunc(path)
|
||||||
|
}
|
||||||
|
return "https://github.com/test/plugin.git", nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mockGitClient) HasUpdates(path string) (bool, string, string, error) {
|
func (m *mockGitClient) HasUpdates(path string) (bool, string, string, error) {
|
||||||
if m.hasUpdatesFunc != nil {
|
if m.hasUpdatesFunc != nil {
|
||||||
return m.hasUpdatesFunc(path)
|
return m.hasUpdatesFunc(path)
|
||||||
@@ -37,11 +55,27 @@ func (m *mockGitClient) HasUpdates(path string) (bool, string, string, error) {
|
|||||||
return false, "", "", nil
|
return false, "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockGitClient) CurrentRevision(path string) (string, error) {
|
||||||
|
if m.revisionFunc != nil {
|
||||||
|
return m.revisionFunc(path)
|
||||||
|
}
|
||||||
|
return "0123456789abcdef0123456789abcdef01234567", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockGitClient) CheckoutRevision(path string, revision string) error {
|
||||||
|
if m.checkoutFunc != nil {
|
||||||
|
return m.checkoutFunc(path, revision)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewRegistry(t *testing.T) {
|
func TestNewRegistry(t *testing.T) {
|
||||||
registry, err := NewRegistry()
|
registry, err := NewRegistry()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, registry)
|
assert.NotNil(t, registry)
|
||||||
assert.NotEmpty(t, registry.cacheDir)
|
assert.NotEmpty(t, registry.cacheDir)
|
||||||
|
require.NotEmpty(t, registry.registries)
|
||||||
|
assert.Equal(t, registries.OfficialName, registry.registries[0].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetCacheDir(t *testing.T) {
|
func TestGetCacheDir(t *testing.T) {
|
||||||
@@ -49,14 +83,50 @@ func TestGetCacheDir(t *testing.T) {
|
|||||||
assert.Contains(t, cacheDir, "/tmp/dankdots-plugin-registry")
|
assert.Contains(t, cacheDir, "/tmp/dankdots-plugin-registry")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRealGitClientRevisionCheckout(t *testing.T) {
|
||||||
|
repoPath := t.TempDir()
|
||||||
|
repo, err := git.PlainInit(repoPath, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
worktree, err := repo.Worktree()
|
||||||
|
require.NoError(t, err)
|
||||||
|
filePath := filepath.Join(repoPath, "value.txt")
|
||||||
|
signature := &object.Signature{Name: "DMS Test", Email: "test@example.com", When: time.Unix(1, 0)}
|
||||||
|
|
||||||
|
require.NoError(t, os.WriteFile(filePath, []byte("one"), 0o644))
|
||||||
|
_, err = worktree.Add("value.txt")
|
||||||
|
require.NoError(t, err)
|
||||||
|
first, err := worktree.Commit("first", &git.CommitOptions{Author: signature})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NoError(t, os.WriteFile(filePath, []byte("two"), 0o644))
|
||||||
|
_, err = worktree.Add("value.txt")
|
||||||
|
require.NoError(t, err)
|
||||||
|
second, err := worktree.Commit("second", &git.CommitOptions{Author: signature})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
client := &realGitClient{}
|
||||||
|
revision, err := client.CurrentRevision(repoPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, second.String(), revision)
|
||||||
|
require.NoError(t, client.CheckoutRevision(repoPath, first.String()))
|
||||||
|
|
||||||
|
revision, err = client.CurrentRevision(repoPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, first.String(), revision)
|
||||||
|
data, err := os.ReadFile(filePath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "one", string(data))
|
||||||
|
}
|
||||||
|
|
||||||
func setupTestRegistry(t *testing.T) (*Registry, afero.Fs, string) {
|
func setupTestRegistry(t *testing.T) (*Registry, afero.Fs, string) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
tmpDir := "/test-cache"
|
tmpDir := "/test-cache"
|
||||||
registry := &Registry{
|
registry := &Registry{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
cacheDir: tmpDir,
|
cacheDir: tmpDir,
|
||||||
plugins: []Plugin{},
|
registries: []registries.Source{{Name: "test", URL: testRegistryURL}},
|
||||||
git: &mockGitClient{},
|
plugins: []Plugin{},
|
||||||
|
git: &mockGitClient{},
|
||||||
}
|
}
|
||||||
return registry, fs, tmpDir
|
return registry, fs, tmpDir
|
||||||
}
|
}
|
||||||
@@ -104,14 +174,14 @@ func TestLoadPlugins(t *testing.T) {
|
|||||||
createTestPlugin(t, fs, tmpDir, "plugin1.json", plugin1)
|
createTestPlugin(t, fs, tmpDir, "plugin1.json", plugin1)
|
||||||
createTestPlugin(t, fs, tmpDir, "plugin2.json", plugin2)
|
createTestPlugin(t, fs, tmpDir, "plugin2.json", plugin2)
|
||||||
|
|
||||||
err := registry.loadPlugins()
|
plugins, err := registry.loadPluginsFrom(tmpDir)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, registry.plugins, 2)
|
assert.Len(t, plugins, 2)
|
||||||
|
|
||||||
assert.Equal(t, "TestPlugin1", registry.plugins[0].Name)
|
assert.Equal(t, "TestPlugin1", plugins[0].Name)
|
||||||
assert.Equal(t, "TestPlugin2", registry.plugins[1].Name)
|
assert.Equal(t, "TestPlugin2", plugins[1].Name)
|
||||||
assert.Equal(t, []string{"dankbar-widget"}, registry.plugins[0].Capabilities)
|
assert.Equal(t, []string{"dankbar-widget"}, plugins[0].Capabilities)
|
||||||
assert.Equal(t, []string{"dep1", "dep2"}, registry.plugins[1].Dependencies)
|
assert.Equal(t, []string{"dep1", "dep2"}, plugins[1].Dependencies)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("skips non-json files", func(t *testing.T) {
|
t.Run("skips non-json files", func(t *testing.T) {
|
||||||
@@ -136,34 +206,10 @@ func TestLoadPlugins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
createTestPlugin(t, fs, tmpDir, "valid.json", plugin)
|
createTestPlugin(t, fs, tmpDir, "valid.json", plugin)
|
||||||
|
|
||||||
err = registry.loadPlugins()
|
plugins, err := registry.loadPluginsFrom(tmpDir)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, registry.plugins, 1)
|
assert.Len(t, plugins, 1)
|
||||||
assert.Equal(t, "ValidPlugin", registry.plugins[0].Name)
|
assert.Equal(t, "ValidPlugin", plugins[0].Name)
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("skips directories", func(t *testing.T) {
|
|
||||||
registry, fs, tmpDir := setupTestRegistry(t)
|
|
||||||
|
|
||||||
pluginsDir := filepath.Join(tmpDir, "plugins")
|
|
||||||
err := fs.MkdirAll(filepath.Join(pluginsDir, "subdir"), 0o755)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
plugin := Plugin{
|
|
||||||
Name: "ValidPlugin",
|
|
||||||
Capabilities: []string{"test"},
|
|
||||||
Category: "test",
|
|
||||||
Repo: "https://github.com/test/test",
|
|
||||||
Author: "Test",
|
|
||||||
Description: "Test",
|
|
||||||
Compositors: []string{"niri"},
|
|
||||||
Distro: []string{"any"},
|
|
||||||
}
|
|
||||||
createTestPlugin(t, fs, tmpDir, "valid.json", plugin)
|
|
||||||
|
|
||||||
err = registry.loadPlugins()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Len(t, registry.plugins, 1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("skips invalid json files", func(t *testing.T) {
|
t.Run("skips invalid json files", func(t *testing.T) {
|
||||||
@@ -188,18 +234,18 @@ func TestLoadPlugins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
createTestPlugin(t, fs, tmpDir, "valid.json", plugin)
|
createTestPlugin(t, fs, tmpDir, "valid.json", plugin)
|
||||||
|
|
||||||
err = registry.loadPlugins()
|
plugins, err := registry.loadPluginsFrom(tmpDir)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, registry.plugins, 1)
|
assert.Len(t, plugins, 1)
|
||||||
assert.Equal(t, "ValidPlugin", registry.plugins[0].Name)
|
assert.Equal(t, "ValidPlugin", plugins[0].Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns error when plugins directory missing", func(t *testing.T) {
|
t.Run("missing plugins directory is a themes-only registry", func(t *testing.T) {
|
||||||
registry, _, _ := setupTestRegistry(t)
|
registry, _, _ := setupTestRegistry(t)
|
||||||
|
|
||||||
err := registry.loadPlugins()
|
plugins, err := registry.loadPluginsFrom(registry.cacheDir)
|
||||||
assert.Error(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Contains(t, err.Error(), "failed to read plugins directory")
|
assert.Empty(t, plugins)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,19 +286,40 @@ func TestList(t *testing.T) {
|
|||||||
Distro: []string{"any"},
|
Distro: []string{"any"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mockGit := &mockGitClient{
|
registry.git = &mockGitClient{
|
||||||
cloneFunc: func(path string, url string) error {
|
cloneFunc: func(path string, url string) error {
|
||||||
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry.git = mockGit
|
|
||||||
|
|
||||||
plugins, err := registry.List()
|
plugins, err := registry.List()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, plugins, 1)
|
assert.Len(t, plugins, 1)
|
||||||
assert.Equal(t, "NewPlugin", plugins[0].Name)
|
assert.Equal(t, "NewPlugin", plugins[0].Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("partial registry failure still returns loaded plugins", func(t *testing.T) {
|
||||||
|
registry, fs, _ := setupTestRegistry(t)
|
||||||
|
|
||||||
|
registry.registries = []registries.Source{
|
||||||
|
{Name: "test", URL: testRegistryURL},
|
||||||
|
{Name: "broken", URL: "https://example.com/broken.git"},
|
||||||
|
}
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
if url != testRegistryURL {
|
||||||
|
return errors.New("clone failed")
|
||||||
|
}
|
||||||
|
createTestPlugin(t, fs, path, "x.json", Plugin{ID: "x", Name: "X"})
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins, err := registry.List()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, plugins, 1)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
@@ -271,16 +338,15 @@ func TestUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cloneCalled := false
|
cloneCalled := false
|
||||||
mockGit := &mockGitClient{
|
registry.git = &mockGitClient{
|
||||||
cloneFunc: func(path string, url string) error {
|
cloneFunc: func(path string, url string) error {
|
||||||
cloneCalled = true
|
cloneCalled = true
|
||||||
assert.Equal(t, registryRepo, url)
|
assert.Equal(t, testRegistryURL, url)
|
||||||
assert.Equal(t, tmpDir, path)
|
assert.Equal(t, filepath.Join(tmpDir, "test"), path)
|
||||||
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry.git = mockGit
|
|
||||||
|
|
||||||
err := registry.Update()
|
err := registry.Update()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -289,7 +355,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
assert.Equal(t, "RepoPlugin", registry.plugins[0].Name)
|
assert.Equal(t, "RepoPlugin", registry.plugins[0].Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("pulls updates when cache exists", func(t *testing.T) {
|
t.Run("pulls when cache exists with matching origin", func(t *testing.T) {
|
||||||
registry, fs, tmpDir := setupTestRegistry(t)
|
registry, fs, tmpDir := setupTestRegistry(t)
|
||||||
|
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
@@ -303,24 +369,188 @@ func TestUpdate(t *testing.T) {
|
|||||||
Distro: []string{"any"},
|
Distro: []string{"any"},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := fs.MkdirAll(tmpDir, 0o755)
|
subdir := filepath.Join(tmpDir, "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, fs.MkdirAll(subdir, 0o755))
|
||||||
|
|
||||||
pullCalled := false
|
pullCalled := false
|
||||||
mockGit := &mockGitClient{
|
registry.git = &mockGitClient{
|
||||||
|
originFunc: func(path string) (string, error) {
|
||||||
|
return testRegistryURL, nil
|
||||||
|
},
|
||||||
pullFunc: func(path string) error {
|
pullFunc: func(path string) error {
|
||||||
pullCalled = true
|
pullCalled = true
|
||||||
assert.Equal(t, tmpDir, path)
|
assert.Equal(t, subdir, path)
|
||||||
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
createTestPlugin(t, fs, path, "plugin.json", plugin)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry.git = mockGit
|
|
||||||
|
|
||||||
err = registry.Update()
|
err := registry.Update()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, pullCalled)
|
assert.True(t, pullCalled)
|
||||||
assert.Len(t, registry.plugins, 1)
|
assert.Len(t, registry.plugins, 1)
|
||||||
assert.Equal(t, "UpdatedPlugin", registry.plugins[0].Name)
|
assert.Equal(t, "UpdatedPlugin", registry.plugins[0].Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("re-clones when cached origin does not match configured URL", func(t *testing.T) {
|
||||||
|
registry, fs, tmpDir := setupTestRegistry(t)
|
||||||
|
|
||||||
|
subdir := filepath.Join(tmpDir, "test")
|
||||||
|
require.NoError(t, fs.MkdirAll(subdir, 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, filepath.Join(subdir, "stale"), []byte("x"), 0o644))
|
||||||
|
|
||||||
|
pullCalled := false
|
||||||
|
cloneCalled := false
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
originFunc: func(path string) (string, error) {
|
||||||
|
return "https://example.com/old-origin.git", nil
|
||||||
|
},
|
||||||
|
pullFunc: func(path string) error {
|
||||||
|
pullCalled = true
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
cloneCalled = true
|
||||||
|
assert.Equal(t, testRegistryURL, url)
|
||||||
|
createTestPlugin(t, fs, path, "x.json", Plugin{ID: "x", Name: "X"})
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.False(t, pullCalled, "stale origin must not be pulled")
|
||||||
|
assert.True(t, cloneCalled)
|
||||||
|
exists, _ := afero.Exists(fs, filepath.Join(subdir, "stale"))
|
||||||
|
assert.False(t, exists, "stale cache contents removed before re-clone")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("re-clones when pull fails", func(t *testing.T) {
|
||||||
|
registry, fs, tmpDir := setupTestRegistry(t)
|
||||||
|
|
||||||
|
subdir := filepath.Join(tmpDir, "test")
|
||||||
|
require.NoError(t, fs.MkdirAll(subdir, 0o755))
|
||||||
|
|
||||||
|
cloneCalled := false
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
originFunc: func(path string) (string, error) {
|
||||||
|
return testRegistryURL, nil
|
||||||
|
},
|
||||||
|
pullFunc: func(path string) error {
|
||||||
|
return errors.New("shallow clone corruption")
|
||||||
|
},
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
cloneCalled = true
|
||||||
|
createTestPlugin(t, fs, path, "x.json", Plugin{ID: "x", Name: "X"})
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, cloneCalled)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("aggregates from multiple registries", func(t *testing.T) {
|
||||||
|
registry, fs, _ := setupTestRegistry(t)
|
||||||
|
|
||||||
|
pluginA := Plugin{ID: "a", Name: "PluginA", Compositors: []string{"niri"}, Distro: []string{"any"}}
|
||||||
|
pluginB := Plugin{ID: "b", Name: "PluginB", Compositors: []string{"niri"}, Distro: []string{"any"}}
|
||||||
|
|
||||||
|
registry.registries = []registries.Source{
|
||||||
|
{Name: "official", URL: testRegistryURL},
|
||||||
|
{Name: "louzt", URL: "https://example.com/louzt.git"},
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
switch filepath.Base(path) {
|
||||||
|
case "official":
|
||||||
|
createTestPlugin(t, fs, path, "x.json", pluginA)
|
||||||
|
case "louzt":
|
||||||
|
createTestPlugin(t, fs, path, "x.json", pluginB)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, registry.plugins, 2)
|
||||||
|
assert.Equal(t, "a", registry.plugins[0].ID)
|
||||||
|
assert.Equal(t, "b", registry.plugins[1].ID)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("dedupes by ID with declaration order priority", func(t *testing.T) {
|
||||||
|
registry, fs, _ := setupTestRegistry(t)
|
||||||
|
|
||||||
|
pluginOfficial := Plugin{ID: "weather", Name: "OfficialWeather", Compositors: []string{"niri"}, Distro: []string{"any"}}
|
||||||
|
pluginLouzt := Plugin{ID: "weather", Name: "LouztWeather", Compositors: []string{"niri"}, Distro: []string{"any"}}
|
||||||
|
|
||||||
|
registry.registries = []registries.Source{
|
||||||
|
{Name: "official", URL: testRegistryURL},
|
||||||
|
{Name: "louzt", URL: "https://example.com/louzt.git"},
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
switch filepath.Base(path) {
|
||||||
|
case "official":
|
||||||
|
createTestPlugin(t, fs, path, "x.json", pluginOfficial)
|
||||||
|
case "louzt":
|
||||||
|
createTestPlugin(t, fs, path, "x.json", pluginLouzt)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, registry.plugins, 1)
|
||||||
|
assert.Equal(t, "OfficialWeather", registry.plugins[0].Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("continues past failing registry and reports it", func(t *testing.T) {
|
||||||
|
registry, fs, _ := setupTestRegistry(t)
|
||||||
|
|
||||||
|
registry.registries = []registries.Source{
|
||||||
|
{Name: "broken", URL: "https://example.com/broken.git"},
|
||||||
|
{Name: "test", URL: testRegistryURL},
|
||||||
|
}
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
if url != testRegistryURL {
|
||||||
|
return errors.New("network unreachable")
|
||||||
|
}
|
||||||
|
createTestPlugin(t, fs, path, "x.json", Plugin{ID: "x", Name: "X"})
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "registry broken")
|
||||||
|
assert.Len(t, registry.plugins, 1, "healthy registry still loads")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("removes legacy single-clone cache at base", func(t *testing.T) {
|
||||||
|
registry, fs, tmpDir := setupTestRegistry(t)
|
||||||
|
|
||||||
|
require.NoError(t, fs.MkdirAll(filepath.Join(tmpDir, ".git"), 0o755))
|
||||||
|
createTestPlugin(t, fs, tmpDir, "legacy.json", Plugin{ID: "legacy", Name: "Legacy"})
|
||||||
|
|
||||||
|
registry.git = &mockGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
createTestPlugin(t, fs, path, "x.json", Plugin{ID: "x", Name: "X"})
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := registry.Update()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
exists, _ := afero.DirExists(fs, filepath.Join(tmpDir, ".git"))
|
||||||
|
assert.False(t, exists, "legacy clone removed")
|
||||||
|
assert.Len(t, registry.plugins, 1)
|
||||||
|
assert.Equal(t, "x", registry.plugins[0].ID)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,16 @@ func TestLockScreenPasswordFieldBypassesTextInputIME(t *testing.T) {
|
|||||||
if !strings.Contains(content, "Keys.onPressed") || !strings.Contains(content, "event.text") {
|
if !strings.Contains(content, "Keys.onPressed") || !strings.Contains(content, "event.text") {
|
||||||
t.Fatalf("passwordField should handle physical key text manually instead of relying on a text input control")
|
t.Fatalf("passwordField should handle physical key text manually instead of relying on a text input control")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wayland IMEs commit unconsumed printable keys as text-input text rather
|
||||||
|
// than forwarding raw keys, so the lock screen needs an IME commit sink
|
||||||
|
// alongside raw key handling.
|
||||||
|
if !strings.Contains(content, "id: imeCommitSink") {
|
||||||
|
t.Fatalf("passwordField must keep the imeCommitSink TextInput so IME-routed keyboards can type (#2950)")
|
||||||
|
}
|
||||||
|
if !strings.Contains(content, "Qt.ImhSensitiveData") {
|
||||||
|
t.Fatalf("imeCommitSink must advertise hidden-text hints so IMEs treat it as a password field")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLockScreenPamSupportsManagedAndSystemPolicies(t *testing.T) {
|
func TestLockScreenPamSupportsManagedAndSystemPolicies(t *testing.T) {
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package registries
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OfficialName = "official"
|
||||||
|
officialURL = "https://github.com/AvengeMedia/dms-plugin-registry.git"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Source identifies a registry repository. Name doubles as the per-registry
|
||||||
|
// cache subdirectory, so it is restricted to a filesystem-safe slug.
|
||||||
|
type Source struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Source) Official() bool {
|
||||||
|
return s.Name == OfficialName
|
||||||
|
}
|
||||||
|
|
||||||
|
var nameRe = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,31}$`)
|
||||||
|
|
||||||
|
func configPath() (string, error) {
|
||||||
|
configDir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get user config dir: %w", err)
|
||||||
|
}
|
||||||
|
return filepath.Join(configDir, "DankMaterialShell", "registries.json"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load returns the official registry followed by any user-configured extras.
|
||||||
|
// A missing or unreadable config yields just the official registry.
|
||||||
|
func Load(fs afero.Fs) []Source {
|
||||||
|
sources := []Source{{Name: OfficialName, URL: officialURL}}
|
||||||
|
|
||||||
|
path, err := configPath()
|
||||||
|
if err != nil {
|
||||||
|
return sources
|
||||||
|
}
|
||||||
|
data, err := afero.ReadFile(fs, path)
|
||||||
|
if err != nil {
|
||||||
|
return sources
|
||||||
|
}
|
||||||
|
var extras []Source
|
||||||
|
if err := json.Unmarshal(data, &extras); err != nil {
|
||||||
|
return sources
|
||||||
|
}
|
||||||
|
for _, s := range extras {
|
||||||
|
if !nameRe.MatchString(s.Name) || s.Name == OfficialName || s.URL == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sources = append(sources, s)
|
||||||
|
}
|
||||||
|
return sources
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveExtras(fs afero.Fs, extras []Source) error {
|
||||||
|
path, err := configPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := fs.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create config dir: %w", err)
|
||||||
|
}
|
||||||
|
data, err := json.MarshalIndent(extras, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return afero.WriteFile(fs, path, append(data, '\n'), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadExtras(fs afero.Fs) []Source {
|
||||||
|
sources := Load(fs)
|
||||||
|
return sources[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func Add(fs afero.Fs, name, url string) error {
|
||||||
|
name = strings.TrimSpace(name)
|
||||||
|
url = strings.TrimSpace(url)
|
||||||
|
|
||||||
|
if !nameRe.MatchString(name) {
|
||||||
|
return fmt.Errorf("invalid registry name %q: use 1-32 lowercase letters, digits or hyphens", name)
|
||||||
|
}
|
||||||
|
if name == OfficialName {
|
||||||
|
return fmt.Errorf("registry name %q is reserved", OfficialName)
|
||||||
|
}
|
||||||
|
if url == "" {
|
||||||
|
return fmt.Errorf("registry URL is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
extras := loadExtras(fs)
|
||||||
|
for _, s := range extras {
|
||||||
|
if s.Name == name {
|
||||||
|
return fmt.Errorf("registry %q already exists", name)
|
||||||
|
}
|
||||||
|
if s.URL == url {
|
||||||
|
return fmt.Errorf("registry %q already uses this URL", s.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveExtras(fs, append(extras, Source{Name: name, URL: url}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Remove(fs afero.Fs, name string) error {
|
||||||
|
if name == OfficialName {
|
||||||
|
return fmt.Errorf("the official registry cannot be removed")
|
||||||
|
}
|
||||||
|
|
||||||
|
extras := loadExtras(fs)
|
||||||
|
kept := make([]Source, 0, len(extras))
|
||||||
|
for _, s := range extras {
|
||||||
|
if s.Name != name {
|
||||||
|
kept = append(kept, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(kept) == len(extras) {
|
||||||
|
return fmt.Errorf("registry %q not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveExtras(fs, kept)
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package registries
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupFs(t *testing.T) afero.Fs {
|
||||||
|
t.Setenv("XDG_CONFIG_HOME", "/xdg")
|
||||||
|
return afero.NewMemMapFs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadDefaults(t *testing.T) {
|
||||||
|
fs := setupFs(t)
|
||||||
|
|
||||||
|
sources := Load(fs)
|
||||||
|
require.Len(t, sources, 1)
|
||||||
|
assert.Equal(t, OfficialName, sources[0].Name)
|
||||||
|
assert.Equal(t, officialURL, sources[0].URL)
|
||||||
|
assert.True(t, sources[0].Official())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddAndLoad(t *testing.T) {
|
||||||
|
fs := setupFs(t)
|
||||||
|
|
||||||
|
require.NoError(t, Add(fs, "extra", "https://example.com/extra.git"))
|
||||||
|
require.NoError(t, Add(fs, "another", "https://example.com/another.git"))
|
||||||
|
|
||||||
|
sources := Load(fs)
|
||||||
|
require.Len(t, sources, 3)
|
||||||
|
assert.Equal(t, OfficialName, sources[0].Name)
|
||||||
|
assert.Equal(t, "extra", sources[1].Name)
|
||||||
|
assert.Equal(t, "another", sources[2].Name)
|
||||||
|
assert.False(t, sources[1].Official())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddValidation(t *testing.T) {
|
||||||
|
fs := setupFs(t)
|
||||||
|
|
||||||
|
assert.Error(t, Add(fs, "", "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, "Has Spaces", "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, "UPPER", "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, "../escape", "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, OfficialName, "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, "noname", ""))
|
||||||
|
|
||||||
|
require.NoError(t, Add(fs, "extra", "https://example.com/x.git"))
|
||||||
|
assert.Error(t, Add(fs, "extra", "https://example.com/other.git"), "duplicate name rejected")
|
||||||
|
assert.Error(t, Add(fs, "extra2", "https://example.com/x.git"), "duplicate URL rejected")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemove(t *testing.T) {
|
||||||
|
fs := setupFs(t)
|
||||||
|
|
||||||
|
require.NoError(t, Add(fs, "extra", "https://example.com/x.git"))
|
||||||
|
require.NoError(t, Remove(fs, "extra"))
|
||||||
|
assert.Len(t, Load(fs), 1)
|
||||||
|
|
||||||
|
assert.Error(t, Remove(fs, "extra"), "already removed")
|
||||||
|
assert.Error(t, Remove(fs, OfficialName), "official is not removable")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadIgnoresInvalidConfig(t *testing.T) {
|
||||||
|
fs := setupFs(t)
|
||||||
|
|
||||||
|
require.NoError(t, fs.MkdirAll("/xdg/DankMaterialShell", 0o755))
|
||||||
|
require.NoError(t, afero.WriteFile(fs, "/xdg/DankMaterialShell/registries.json", []byte("{not json"), 0o644))
|
||||||
|
assert.Len(t, Load(fs), 1)
|
||||||
|
|
||||||
|
entries := `[{"name":"ok","url":"https://example.com/ok.git"},{"name":"Bad Name","url":"https://example.com/bad.git"},{"name":"official","url":"https://example.com/spoof.git"},{"name":"nourl","url":""}]`
|
||||||
|
require.NoError(t, afero.WriteFile(fs, "/xdg/DankMaterialShell/registries.json", []byte(entries), 0o644))
|
||||||
|
sources := Load(fs)
|
||||||
|
require.Len(t, sources, 2, "invalid entries dropped")
|
||||||
|
assert.Equal(t, "ok", sources[1].Name)
|
||||||
|
assert.Equal(t, officialURL, sources[0].URL, "official cannot be spoofed from config")
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ func NewManager() (*Manager, error) {
|
|||||||
return nil, fmt.Errorf("failed to find keyboards: %w", err)
|
return nil, fmt.Errorf("failed to find keyboards: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
initialCapsLock := readInitialCapsLockState(devices[0])
|
initialCapsLock, _ := capsLockFromDevices(devices)
|
||||||
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,14 +85,21 @@ func NewManager() (*Manager, error) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInitialCapsLockState(device EvdevDevice) bool {
|
func capsLockFromDevices(devices []EvdevDevice) (bool, bool) {
|
||||||
ledStates, err := device.State(evLedType)
|
for _, device := range devices {
|
||||||
if err != nil {
|
if device == nil {
|
||||||
log.Debugf("Could not read LED state: %v", err)
|
continue
|
||||||
return false
|
}
|
||||||
|
|
||||||
|
ledStates, err := device.State(evLedType)
|
||||||
|
if err != nil || len(ledStates) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return ledStates[ledCapslockKey], true
|
||||||
}
|
}
|
||||||
|
|
||||||
return ledStates[ledCapslockKey]
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func findKeyboards() ([]EvdevDevice, error) {
|
func findKeyboards() ([]EvdevDevice, error) {
|
||||||
@@ -297,25 +304,22 @@ func (m *Manager) readAndUpdateCapsLockState(deviceIndex int) {
|
|||||||
m.devicesMutex.RUnlock()
|
m.devicesMutex.RUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
device := m.devices[deviceIndex]
|
ordered := make([]EvdevDevice, 0, len(m.devices))
|
||||||
|
ordered = append(ordered, m.devices[deviceIndex])
|
||||||
|
for i, device := range m.devices {
|
||||||
|
if i == deviceIndex {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ordered = append(ordered, device)
|
||||||
|
}
|
||||||
m.devicesMutex.RUnlock()
|
m.devicesMutex.RUnlock()
|
||||||
|
|
||||||
ledStates, err := device.State(evLedType)
|
capsLockState, ok := capsLockFromDevices(ordered)
|
||||||
if err != nil {
|
if !ok {
|
||||||
log.Warnf("Failed to read LED state: %v", err)
|
log.Debug("No LED-capable device available for caps lock state")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ledStates) == 0 {
|
|
||||||
log.Debug("No LED state available (empty map)")
|
|
||||||
|
|
||||||
// This means the device either:
|
|
||||||
// - doesn't support LED reporting at all, or
|
|
||||||
// - the kernel returned an empty state
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
capsLockState := ledStates[ledCapslockKey]
|
|
||||||
m.updateCapsLockStateDirect(capsLockState)
|
m.updateCapsLockStateDirect(capsLockState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ func TestNotifySubscribers(t *testing.T) {
|
|||||||
m.Close()
|
m.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadInitialCapsLockState(t *testing.T) {
|
func TestCapsLockFromDevices(t *testing.T) {
|
||||||
t.Run("caps lock is on", func(t *testing.T) {
|
t.Run("caps lock is on", func(t *testing.T) {
|
||||||
mockDevice := mocks.NewMockEvdevDevice(t)
|
mockDevice := mocks.NewMockEvdevDevice(t)
|
||||||
ledState := evdev.StateMap{
|
ledState := evdev.StateMap{
|
||||||
@@ -314,7 +314,8 @@ func TestReadInitialCapsLockState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(ledState, nil).Once()
|
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(ledState, nil).Once()
|
||||||
|
|
||||||
result := readInitialCapsLockState(mockDevice)
|
result, ok := capsLockFromDevices([]EvdevDevice{mockDevice})
|
||||||
|
assert.True(t, ok)
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -325,7 +326,8 @@ func TestReadInitialCapsLockState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(ledState, nil).Once()
|
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(ledState, nil).Once()
|
||||||
|
|
||||||
result := readInitialCapsLockState(mockDevice)
|
result, ok := capsLockFromDevices([]EvdevDevice{mockDevice})
|
||||||
|
assert.True(t, ok)
|
||||||
assert.False(t, result)
|
assert.False(t, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -333,9 +335,25 @@ func TestReadInitialCapsLockState(t *testing.T) {
|
|||||||
mockDevice := mocks.NewMockEvdevDevice(t)
|
mockDevice := mocks.NewMockEvdevDevice(t)
|
||||||
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(nil, errors.New("read error")).Once()
|
mockDevice.EXPECT().State(evdev.EvType(evLedType)).Return(nil, errors.New("read error")).Once()
|
||||||
|
|
||||||
result := readInitialCapsLockState(mockDevice)
|
result, ok := capsLockFromDevices([]EvdevDevice{mockDevice})
|
||||||
|
assert.False(t, ok)
|
||||||
assert.False(t, result)
|
assert.False(t, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("falls back past device without LED state", func(t *testing.T) {
|
||||||
|
noLedDevice := mocks.NewMockEvdevDevice(t)
|
||||||
|
noLedDevice.EXPECT().State(evdev.EvType(evLedType)).Return(evdev.StateMap{}, nil).Once()
|
||||||
|
|
||||||
|
ledDevice := mocks.NewMockEvdevDevice(t)
|
||||||
|
ledState := evdev.StateMap{
|
||||||
|
ledCapslockKey: true,
|
||||||
|
}
|
||||||
|
ledDevice.EXPECT().State(evdev.EvType(evLedType)).Return(ledState, nil).Once()
|
||||||
|
|
||||||
|
result, ok := capsLockFromDevices([]EvdevDevice{noLedDevice, nil, ledDevice})
|
||||||
|
assert.True(t, ok)
|
||||||
|
assert.True(t, result)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasInputGroupAccess(t *testing.T) {
|
func TestHasInputGroupAccess(t *testing.T) {
|
||||||
|
|||||||
@@ -302,17 +302,17 @@ func (a *SecretAgent) GetSecrets(
|
|||||||
}
|
}
|
||||||
a.backend.cachedVPNCredsMu.Unlock()
|
a.backend.cachedVPNCredsMu.Unlock()
|
||||||
|
|
||||||
a.backend.cachedGPSamlMu.Lock()
|
a.backend.cachedOpenConnectMu.Lock()
|
||||||
cachedGPSaml := a.backend.cachedGPSamlCookie
|
cachedOpenConnect := a.backend.cachedOpenConnectAuth
|
||||||
if cachedGPSaml != nil && cachedGPSaml.ConnectionUUID == connUuid {
|
if cachedOpenConnect != nil && cachedOpenConnect.ConnectionUUID == connUuid {
|
||||||
a.backend.cachedGPSamlCookie = nil
|
a.backend.cachedOpenConnectAuth = nil
|
||||||
a.backend.cachedGPSamlMu.Unlock()
|
a.backend.cachedOpenConnectMu.Unlock()
|
||||||
|
|
||||||
log.Infof("[SecretAgent] Using cached GlobalProtect SAML cookie for %s", connUuid)
|
log.Infof("[SecretAgent] Using cached OpenConnect authentication for %s", connUuid)
|
||||||
|
|
||||||
return buildGPSamlSecretsResponse(settingName, cachedGPSaml.Cookie, cachedGPSaml.Host, cachedGPSaml.Fingerprint), nil
|
return buildOpenConnectSecretsResponse(settingName, cachedOpenConnect.Cookie, cachedOpenConnect.Host, cachedOpenConnect.Fingerprint), nil
|
||||||
}
|
}
|
||||||
a.backend.cachedGPSamlMu.Unlock()
|
a.backend.cachedOpenConnectMu.Unlock()
|
||||||
|
|
||||||
if len(fields) == 1 && fields[0] == "gp-saml" {
|
if len(fields) == 1 && fields[0] == "gp-saml" {
|
||||||
gateway := ""
|
gateway := ""
|
||||||
@@ -347,17 +347,17 @@ func (a *SecretAgent) GetSecrets(
|
|||||||
|
|
||||||
log.Infof("[SecretAgent] GlobalProtect SAML authentication successful, returning cookie to NetworkManager")
|
log.Infof("[SecretAgent] GlobalProtect SAML authentication successful, returning cookie to NetworkManager")
|
||||||
|
|
||||||
a.backend.cachedGPSamlMu.Lock()
|
a.backend.cachedOpenConnectMu.Lock()
|
||||||
a.backend.cachedGPSamlCookie = &cachedGPSamlCookie{
|
a.backend.cachedOpenConnectAuth = &cachedOpenConnectAuth{
|
||||||
ConnectionUUID: connUuid,
|
ConnectionUUID: connUuid,
|
||||||
Cookie: authResult.Cookie,
|
Cookie: authResult.Cookie,
|
||||||
Host: authResult.Host,
|
Host: authResult.Host,
|
||||||
User: authResult.User,
|
User: authResult.User,
|
||||||
Fingerprint: authResult.Fingerprint,
|
Fingerprint: authResult.Fingerprint,
|
||||||
}
|
}
|
||||||
a.backend.cachedGPSamlMu.Unlock()
|
a.backend.cachedOpenConnectMu.Unlock()
|
||||||
|
|
||||||
return buildGPSamlSecretsResponse(settingName, authResult.Cookie, authResult.Host, authResult.Fingerprint), nil
|
return buildOpenConnectSecretsResponse(settingName, authResult.Cookie, authResult.Host, authResult.Fingerprint), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -987,7 +987,7 @@ func buildWiFiSecretsResponse(settingName string, secrets map[string]string) nmS
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGPSamlSecretsResponse(settingName, cookie, host, fingerprint string) nmSettingMap {
|
func buildOpenConnectSecretsResponse(settingName, cookie, host, fingerprint string) nmSettingMap {
|
||||||
out := nmSettingMap{}
|
out := nmSettingMap{}
|
||||||
vpnSec := nmVariantMap{}
|
vpnSec := nmVariantMap{}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func TestNeedsExternalBrowserAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildGPSamlSecretsResponse(t *testing.T) {
|
func TestBuildOpenConnectSecretsResponse(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
settingName string
|
settingName string
|
||||||
@@ -155,7 +155,7 @@ func TestBuildGPSamlSecretsResponse(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := buildGPSamlSecretsResponse(tt.settingName, tt.cookie, tt.host, tt.fingerprint)
|
result := buildOpenConnectSecretsResponse(tt.settingName, tt.cookie, tt.host, tt.fingerprint)
|
||||||
|
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
assert.Contains(t, result, tt.settingName)
|
assert.Contains(t, result, tt.settingName)
|
||||||
|
|||||||
@@ -80,16 +80,16 @@ type NetworkManagerBackend struct {
|
|||||||
|
|
||||||
hotspotPendingDevice string
|
hotspotPendingDevice string
|
||||||
|
|
||||||
pendingVPNSave *pendingVPNCredentials
|
pendingVPNSave *pendingVPNCredentials
|
||||||
pendingVPNSaveMu sync.Mutex
|
pendingVPNSaveMu sync.Mutex
|
||||||
cachedVPNCreds *cachedVPNCredentials
|
cachedVPNCreds *cachedVPNCredentials
|
||||||
cachedVPNCredsMu sync.Mutex
|
cachedVPNCredsMu sync.Mutex
|
||||||
cachedPKCS11PIN *cachedPKCS11PIN
|
cachedPKCS11PIN *cachedPKCS11PIN
|
||||||
cachedPKCS11Mu sync.Mutex
|
cachedPKCS11Mu sync.Mutex
|
||||||
cachedGPSamlCookie *cachedGPSamlCookie
|
cachedOpenConnectAuth *cachedOpenConnectAuth
|
||||||
cachedGPSamlMu sync.Mutex
|
cachedOpenConnectMu sync.Mutex
|
||||||
cachedWiFiSecret *cachedWiFiSecret
|
cachedWiFiSecret *cachedWiFiSecret
|
||||||
cachedWiFiSecretMu sync.Mutex
|
cachedWiFiSecretMu sync.Mutex
|
||||||
|
|
||||||
onStateChange func()
|
onStateChange func()
|
||||||
}
|
}
|
||||||
@@ -100,8 +100,9 @@ type pendingVPNCredentials struct {
|
|||||||
Password string
|
Password string
|
||||||
// Secrets holds all VPN secret fields keyed by name (e.g. "cert-pass");
|
// Secrets holds all VPN secret fields keyed by name (e.g. "cert-pass");
|
||||||
// falls back to Password under the "password" key when empty.
|
// falls back to Password under the "password" key when empty.
|
||||||
Secrets map[string]string
|
Secrets map[string]string
|
||||||
SavePassword bool
|
PersistentSecrets map[string]string
|
||||||
|
SavePassword bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type cachedVPNCredentials struct {
|
type cachedVPNCredentials struct {
|
||||||
@@ -124,7 +125,7 @@ type cachedWiFiSecret struct {
|
|||||||
Secrets map[string]string
|
Secrets map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type cachedGPSamlCookie struct {
|
type cachedOpenConnectAuth struct {
|
||||||
ConnectionUUID string
|
ConnectionUUID string
|
||||||
Cookie string
|
Cookie string
|
||||||
Host string
|
Host string
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package network
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,16 +11,29 @@ import (
|
|||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type gpSamlAuthResult struct {
|
type openConnectAuthResult struct {
|
||||||
Cookie string
|
Cookie string
|
||||||
Host string
|
Host string
|
||||||
User string
|
User string
|
||||||
Fingerprint string
|
Fingerprint string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type openConnectAuthError struct {
|
||||||
|
cause error
|
||||||
|
serverCert string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *openConnectAuthError) Error() string {
|
||||||
|
return fmt.Sprintf("openconnect --authenticate failed: %v", e.cause)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *openConnectAuthError) Unwrap() error {
|
||||||
|
return e.cause
|
||||||
|
}
|
||||||
|
|
||||||
// runGlobalProtectSAMLAuth handles GlobalProtect SAML/SSO authentication using gp-saml-gui.
|
// runGlobalProtectSAMLAuth handles GlobalProtect SAML/SSO authentication using gp-saml-gui.
|
||||||
// Only supports protocol=gp. Other protocols need their own implementations.
|
// Only supports protocol=gp. Other protocols need their own implementations.
|
||||||
func (b *NetworkManagerBackend) runGlobalProtectSAMLAuth(ctx context.Context, gateway, protocol string) (*gpSamlAuthResult, error) {
|
func (b *NetworkManagerBackend) runGlobalProtectSAMLAuth(ctx context.Context, gateway, protocol string) (*openConnectAuthResult, error) {
|
||||||
if gateway == "" {
|
if gateway == "" {
|
||||||
return nil, fmt.Errorf("GP SAML auth: gateway is empty")
|
return nil, fmt.Errorf("GP SAML auth: gateway is empty")
|
||||||
}
|
}
|
||||||
@@ -63,7 +77,7 @@ func (b *NetworkManagerBackend) runGlobalProtectSAMLAuth(ctx context.Context, ga
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
result := &gpSamlAuthResult{Host: gateway}
|
result := &openConnectAuthResult{Host: gateway}
|
||||||
var allOutput []string
|
var allOutput []string
|
||||||
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
scanner := bufio.NewScanner(stdout)
|
||||||
@@ -117,13 +131,8 @@ func (b *NetworkManagerBackend) runGlobalProtectSAMLAuth(ctx context.Context, ga
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertGPPreloginCookie(ctx context.Context, gateway, preloginCookie, user string) (*gpSamlAuthResult, error) {
|
func convertGPPreloginCookie(ctx context.Context, gateway, preloginCookie, user string) (*openConnectAuthResult, error) {
|
||||||
ocPath, err := exec.LookPath("openconnect")
|
return runOpenConnectAuthenticate(ctx, []string{
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("openconnect not found: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{
|
|
||||||
"--protocol=gp",
|
"--protocol=gp",
|
||||||
"--usergroup=gateway:prelogin-cookie",
|
"--usergroup=gateway:prelogin-cookie",
|
||||||
"--user=" + user,
|
"--user=" + user,
|
||||||
@@ -131,18 +140,83 @@ func convertGPPreloginCookie(ctx context.Context, gateway, preloginCookie, user
|
|||||||
"--allow-insecure-crypto",
|
"--allow-insecure-crypto",
|
||||||
"--authenticate",
|
"--authenticate",
|
||||||
gateway,
|
gateway,
|
||||||
|
}, preloginCookie)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runOpenConnectPasswordAuth(
|
||||||
|
ctx context.Context,
|
||||||
|
data map[string]string,
|
||||||
|
username, password, serverCert string,
|
||||||
|
) (*openConnectAuthResult, error) {
|
||||||
|
if data["protocol"] != "fortinet" {
|
||||||
|
return nil, fmt.Errorf("only Fortinet password authentication is supported")
|
||||||
|
}
|
||||||
|
gateway := data["gateway"]
|
||||||
|
if gateway == "" {
|
||||||
|
return nil, fmt.Errorf("OpenConnect gateway is empty")
|
||||||
|
}
|
||||||
|
if username == "" || password == "" {
|
||||||
|
return nil, fmt.Errorf("OpenConnect username and password are required")
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"--protocol=fortinet",
|
||||||
|
"--user=" + username,
|
||||||
|
"--passwd-on-stdin",
|
||||||
|
"--non-inter",
|
||||||
|
}
|
||||||
|
if usergroup := data["usergroup"]; usergroup != "" {
|
||||||
|
args = append(args, "--usergroup="+usergroup)
|
||||||
|
}
|
||||||
|
if serverCert != "" {
|
||||||
|
args = append(args, "--servercert="+serverCert)
|
||||||
|
}
|
||||||
|
args = append(args, "--authenticate", gateway)
|
||||||
|
|
||||||
|
result, err := runOpenConnectAuthenticate(ctx, args, password)
|
||||||
|
if err == nil {
|
||||||
|
result.Host = gateway
|
||||||
|
if result.Fingerprint == "" {
|
||||||
|
result.Fingerprint = serverCert
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func runOpenConnectAuthenticate(ctx context.Context, args []string, secret string) (*openConnectAuthResult, error) {
|
||||||
|
ocPath, err := exec.LookPath("openconnect")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("openconnect not found: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, ocPath, args...)
|
cmd := exec.CommandContext(ctx, ocPath, args...)
|
||||||
cmd.Stdin = strings.NewReader(preloginCookie)
|
cmd.Stdin = strings.NewReader(secret + "\n")
|
||||||
|
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
result := parseOpenConnectAuthenticateOutput(string(output))
|
||||||
|
serverCert := suggestedOpenConnectServerCert(string(output))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("openconnect --authenticate failed: %w\noutput: %s", err, string(output))
|
if ctx.Err() != nil {
|
||||||
|
return nil, fmt.Errorf("openconnect authentication timed out or was cancelled: %w", ctx.Err())
|
||||||
|
}
|
||||||
|
return nil, &openConnectAuthError{cause: err, serverCert: serverCert}
|
||||||
|
}
|
||||||
|
if result.Cookie == "" {
|
||||||
|
return nil, &openConnectAuthError{
|
||||||
|
cause: errors.New("no COOKIE in command output"),
|
||||||
|
serverCert: serverCert,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &gpSamlAuthResult{}
|
log.Infof("[OpenConnect] Authentication successful: cookie_len=%d, host=%s, has_fingerprint=%v",
|
||||||
for _, line := range strings.Split(string(output), "\n") {
|
len(result.Cookie), result.Host, result.Fingerprint != "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseOpenConnectAuthenticateOutput(output string) *openConnectAuthResult {
|
||||||
|
result := &openConnectAuthResult{}
|
||||||
|
for _, line := range strings.Split(output, "\n") {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(line, "COOKIE="):
|
case strings.HasPrefix(line, "COOKIE="):
|
||||||
@@ -158,15 +232,7 @@ func convertGPPreloginCookie(ctx context.Context, gateway, preloginCookie, user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
if result.Cookie == "" {
|
|
||||||
return nil, fmt.Errorf("no COOKIE in openconnect --authenticate output: %s", string(output))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("[GP-SAML] openconnect --authenticate: cookie_len=%d, host=%s, fingerprint=%s",
|
|
||||||
len(result.Cookie), result.Host, result.Fingerprint)
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unshellQuote(s string) string {
|
func unshellQuote(s string) string {
|
||||||
@@ -179,7 +245,7 @@ func unshellQuote(s string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGPSamlFromCommandLine(line string, result *gpSamlAuthResult) {
|
func parseGPSamlFromCommandLine(line string, result *openConnectAuthResult) {
|
||||||
if !strings.Contains(line, "openconnect") {
|
if !strings.Contains(line, "openconnect") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -71,7 +75,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
line string
|
line string
|
||||||
initialResult *gpSamlAuthResult
|
initialResult *openConnectAuthResult
|
||||||
expectedCookie string
|
expectedCookie string
|
||||||
expectedUser string
|
expectedUser string
|
||||||
expectedFP string
|
expectedFP string
|
||||||
@@ -79,7 +83,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "full openconnect command",
|
name: "full openconnect command",
|
||||||
line: "openconnect --protocol=gp --cookie=AUTH123 --servercert=pin-sha256:ABC --user=john",
|
line: "openconnect --protocol=gp --cookie=AUTH123 --servercert=pin-sha256:ABC --user=john",
|
||||||
initialResult: &gpSamlAuthResult{},
|
initialResult: &openConnectAuthResult{},
|
||||||
expectedCookie: "AUTH123",
|
expectedCookie: "AUTH123",
|
||||||
expectedUser: "john",
|
expectedUser: "john",
|
||||||
expectedFP: "pin-sha256:ABC",
|
expectedFP: "pin-sha256:ABC",
|
||||||
@@ -87,7 +91,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "with equals signs in cookie",
|
name: "with equals signs in cookie",
|
||||||
line: "openconnect --cookie=authcookie=xyz123&portal=GATE --user=jane",
|
line: "openconnect --cookie=authcookie=xyz123&portal=GATE --user=jane",
|
||||||
initialResult: &gpSamlAuthResult{},
|
initialResult: &openConnectAuthResult{},
|
||||||
expectedCookie: "authcookie=xyz123&portal=GATE",
|
expectedCookie: "authcookie=xyz123&portal=GATE",
|
||||||
expectedUser: "jane",
|
expectedUser: "jane",
|
||||||
expectedFP: "",
|
expectedFP: "",
|
||||||
@@ -95,7 +99,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "non-openconnect line",
|
name: "non-openconnect line",
|
||||||
line: "some other output",
|
line: "some other output",
|
||||||
initialResult: &gpSamlAuthResult{},
|
initialResult: &openConnectAuthResult{},
|
||||||
expectedCookie: "",
|
expectedCookie: "",
|
||||||
expectedUser: "",
|
expectedUser: "",
|
||||||
expectedFP: "",
|
expectedFP: "",
|
||||||
@@ -103,7 +107,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "preserves existing values",
|
name: "preserves existing values",
|
||||||
line: "openconnect --user=newuser",
|
line: "openconnect --user=newuser",
|
||||||
initialResult: &gpSamlAuthResult{Cookie: "existing", Fingerprint: "existing-fp"},
|
initialResult: &openConnectAuthResult{Cookie: "existing", Fingerprint: "existing-fp"},
|
||||||
expectedCookie: "existing",
|
expectedCookie: "existing",
|
||||||
expectedUser: "newuser",
|
expectedUser: "newuser",
|
||||||
expectedFP: "existing-fp",
|
expectedFP: "existing-fp",
|
||||||
@@ -111,7 +115,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "only updates empty fields",
|
name: "only updates empty fields",
|
||||||
line: "openconnect --cookie=NEW --user=NEW",
|
line: "openconnect --cookie=NEW --user=NEW",
|
||||||
initialResult: &gpSamlAuthResult{Cookie: "OLD"},
|
initialResult: &openConnectAuthResult{Cookie: "OLD"},
|
||||||
expectedCookie: "OLD",
|
expectedCookie: "OLD",
|
||||||
expectedUser: "NEW",
|
expectedUser: "NEW",
|
||||||
expectedFP: "",
|
expectedFP: "",
|
||||||
@@ -119,7 +123,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "real gp-saml-gui output",
|
name: "real gp-saml-gui output",
|
||||||
line: "openconnect --protocol=gp --user=john.doe@example.com --os=linux-64 --usergroup=gateway:prelogin-cookie --passwd-on-stdin",
|
line: "openconnect --protocol=gp --user=john.doe@example.com --os=linux-64 --usergroup=gateway:prelogin-cookie --passwd-on-stdin",
|
||||||
initialResult: &gpSamlAuthResult{},
|
initialResult: &openConnectAuthResult{},
|
||||||
expectedCookie: "",
|
expectedCookie: "",
|
||||||
expectedUser: "john.doe@example.com",
|
expectedUser: "john.doe@example.com",
|
||||||
expectedFP: "",
|
expectedFP: "",
|
||||||
@@ -127,7 +131,7 @@ func TestParseGPSamlFromCommandLine(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "with server cert flag",
|
name: "with server cert flag",
|
||||||
line: "openconnect --servercert=pin-sha256:xp3scfzy3rOgQEXnfPiYKrUk7D66a8b8O+gEXaMPleE= vpn.example.com",
|
line: "openconnect --servercert=pin-sha256:xp3scfzy3rOgQEXnfPiYKrUk7D66a8b8O+gEXaMPleE= vpn.example.com",
|
||||||
initialResult: &gpSamlAuthResult{},
|
initialResult: &openConnectAuthResult{},
|
||||||
expectedCookie: "",
|
expectedCookie: "",
|
||||||
expectedUser: "",
|
expectedUser: "",
|
||||||
expectedFP: "pin-sha256:xp3scfzy3rOgQEXnfPiYKrUk7D66a8b8O+gEXaMPleE=",
|
expectedFP: "pin-sha256:xp3scfzy3rOgQEXnfPiYKrUk7D66a8b8O+gEXaMPleE=",
|
||||||
@@ -158,7 +162,7 @@ func TestParseGPSamlFromCommandLine_MultipleLines(t *testing.T) {
|
|||||||
"",
|
"",
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &gpSamlAuthResult{}
|
result := &openConnectAuthResult{}
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
parseGPSamlFromCommandLine(line, result)
|
parseGPSamlFromCommandLine(line, result)
|
||||||
}
|
}
|
||||||
@@ -167,3 +171,19 @@ func TestParseGPSamlFromCommandLine_MultipleLines(t *testing.T) {
|
|||||||
assert.Empty(t, result.Cookie, "cookie should not be parsed from command line")
|
assert.Empty(t, result.Cookie, "cookie should not be parsed from command line")
|
||||||
assert.Empty(t, result.Fingerprint)
|
assert.Empty(t, result.Fingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunOpenConnectAuthenticateSanitizesFailure(t *testing.T) {
|
||||||
|
binDir := t.TempDir()
|
||||||
|
openConnectPath := filepath.Join(binDir, "openconnect")
|
||||||
|
script := "#!/bin/sh\nprintf '%s\\n' 'Cookie: should-not-leak' 'Add --servercert pin-sha256:TEST-FINGERPRINT' >&2\nexit 1\n"
|
||||||
|
assert.NoError(t, os.WriteFile(openConnectPath, []byte(script), 0o755))
|
||||||
|
t.Setenv("PATH", binDir)
|
||||||
|
|
||||||
|
_, err := runOpenConnectAuthenticate(context.Background(), []string{"--authenticate", "vpn.example.test"}, "password")
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.NotContains(t, err.Error(), "should-not-leak")
|
||||||
|
|
||||||
|
var authErr *openConnectAuthError
|
||||||
|
assert.True(t, errors.As(err, &authErr))
|
||||||
|
assert.Equal(t, "pin-sha256:TEST-FINGERPRINT", authErr.serverCert)
|
||||||
|
}
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
authAction := detectVPNAuthAction(vpnServiceType, vpnData)
|
authAction := detectVPNAuthAction(vpnServiceType, vpnData)
|
||||||
|
var openConnectAuth *openConnectAuthResult
|
||||||
|
|
||||||
switch authAction {
|
switch authAction {
|
||||||
case "openvpn_username":
|
case "openvpn_username":
|
||||||
@@ -335,6 +336,19 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
if err := b.handleOpenVPNUsernameAuth(targetConn, connName, targetUUID, vpnServiceType); err != nil {
|
if err := b.handleOpenVPNUsernameAuth(targetConn, connName, targetUUID, vpnServiceType); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case "openconnect_password":
|
||||||
|
if err := b.ensureOpenConnectAgentFlags(targetConn, vpnData); err != nil {
|
||||||
|
return fmt.Errorf("failed to prepare OpenConnect connection: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authCtx, authCancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||||
|
openConnectAuth, err = b.handleOpenConnectPasswordAuth(
|
||||||
|
authCtx, targetConn, connName, targetUUID, vpnServiceType, vpnData,
|
||||||
|
)
|
||||||
|
authCancel()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("OpenConnect authentication failed: %w", err)
|
||||||
|
}
|
||||||
case "gp_saml":
|
case "gp_saml":
|
||||||
gateway := vpnData["gateway"]
|
gateway := vpnData["gateway"]
|
||||||
protocol := vpnData["protocol"]
|
protocol := vpnData["protocol"]
|
||||||
@@ -345,7 +359,7 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
log.Infof("[ConnectVPN] GlobalProtect SAML/SSO authentication required for %s (gateway=%s)", connName, gateway)
|
log.Infof("[ConnectVPN] GlobalProtect SAML/SSO authentication required for %s (gateway=%s)", connName, gateway)
|
||||||
|
|
||||||
samlCtx, samlCancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
samlCtx, samlCancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||||
authResult, err := b.runGlobalProtectSAMLAuth(samlCtx, gateway, protocol)
|
openConnectAuth, err = b.runGlobalProtectSAMLAuth(samlCtx, gateway, protocol)
|
||||||
samlCancel()
|
samlCancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := err.Error()
|
errMsg := err.Error()
|
||||||
@@ -363,16 +377,6 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.cachedGPSamlMu.Lock()
|
|
||||||
b.cachedGPSamlCookie = &cachedGPSamlCookie{
|
|
||||||
ConnectionUUID: targetUUID,
|
|
||||||
Cookie: authResult.Cookie,
|
|
||||||
Host: authResult.Host,
|
|
||||||
User: authResult.User,
|
|
||||||
Fingerprint: authResult.Fingerprint,
|
|
||||||
}
|
|
||||||
b.cachedGPSamlMu.Unlock()
|
|
||||||
|
|
||||||
if err := targetConn.ClearSecrets(); err != nil {
|
if err := targetConn.ClearSecrets(); err != nil {
|
||||||
log.Warnf("[ConnectVPN] ClearSecrets failed (non-fatal): %v", err)
|
log.Warnf("[ConnectVPN] ClearSecrets failed (non-fatal): %v", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -382,6 +386,19 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
log.Infof("[ConnectVPN] GlobalProtect SAML cookie cached for %s, proceeding with activation", connName)
|
log.Infof("[ConnectVPN] GlobalProtect SAML cookie cached for %s, proceeding with activation", connName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if openConnectAuth != nil {
|
||||||
|
b.cachedOpenConnectMu.Lock()
|
||||||
|
b.cachedOpenConnectAuth = &cachedOpenConnectAuth{
|
||||||
|
ConnectionUUID: targetUUID,
|
||||||
|
Cookie: openConnectAuth.Cookie,
|
||||||
|
Host: openConnectAuth.Host,
|
||||||
|
User: openConnectAuth.User,
|
||||||
|
Fingerprint: openConnectAuth.Fingerprint,
|
||||||
|
}
|
||||||
|
b.cachedOpenConnectMu.Unlock()
|
||||||
|
log.Infof("[ConnectVPN] OpenConnect authentication cached for %s, proceeding with activation", connName)
|
||||||
|
}
|
||||||
|
|
||||||
b.stateMutex.Lock()
|
b.stateMutex.Lock()
|
||||||
b.state.IsConnectingVPN = true
|
b.state.IsConnectingVPN = true
|
||||||
b.state.ConnectingVPNUUID = targetUUID
|
b.state.ConnectingVPNUUID = targetUUID
|
||||||
@@ -394,6 +411,13 @@ func (b *NetworkManagerBackend) ConnectVPN(uuidOrName string, singleActive bool)
|
|||||||
nm := b.nmConn.(gonetworkmanager.NetworkManager)
|
nm := b.nmConn.(gonetworkmanager.NetworkManager)
|
||||||
_, err = nm.ActivateConnection(targetConn, nil, nil)
|
_, err = nm.ActivateConnection(targetConn, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
b.cachedOpenConnectMu.Lock()
|
||||||
|
b.cachedOpenConnectAuth = nil
|
||||||
|
b.cachedOpenConnectMu.Unlock()
|
||||||
|
b.pendingVPNSaveMu.Lock()
|
||||||
|
b.pendingVPNSave = nil
|
||||||
|
b.pendingVPNSaveMu.Unlock()
|
||||||
|
|
||||||
b.stateMutex.Lock()
|
b.stateMutex.Lock()
|
||||||
b.state.IsConnectingVPN = false
|
b.state.IsConnectingVPN = false
|
||||||
b.state.ConnectingVPNUUID = ""
|
b.state.ConnectingVPNUUID = ""
|
||||||
@@ -425,6 +449,9 @@ func detectVPNAuthAction(serviceType string, data map[string]string) string {
|
|||||||
log.Infof("[VPN] External browser auth detected for protocol '%s' but only GlobalProtect (gp) is currently supported", protocol)
|
log.Infof("[VPN] External browser auth detected for protocol '%s' but only GlobalProtect (gp) is currently supported", protocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if protocol == "fortinet" && data["authtype"] == "password" {
|
||||||
|
return "openconnect_password"
|
||||||
|
}
|
||||||
case strings.Contains(serviceType, "openvpn"):
|
case strings.Contains(serviceType, "openvpn"):
|
||||||
connType := data["connection-type"]
|
connType := data["connection-type"]
|
||||||
username := data["username"]
|
username := data["username"]
|
||||||
@@ -435,6 +462,200 @@ func detectVPNAuthAction(serviceType string, data map[string]string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setOpenConnectAgentFlags(data map[string]string) bool {
|
||||||
|
changed := false
|
||||||
|
for _, field := range []string{"cookie", "gateway", "gwcert"} {
|
||||||
|
key := field + "-flags"
|
||||||
|
if data[key] != "2" {
|
||||||
|
data[key] = "2"
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *NetworkManagerBackend) ensureOpenConnectAgentFlags(conn gonetworkmanager.Connection, data map[string]string) error {
|
||||||
|
if !setOpenConnectAgentFlags(data) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if b.dbusConn == nil {
|
||||||
|
return fmt.Errorf("NetworkManager D-Bus connection is unavailable")
|
||||||
|
}
|
||||||
|
|
||||||
|
connObj := b.dbusConn.Object("org.freedesktop.NetworkManager", conn.GetPath())
|
||||||
|
var existingSettings map[string]map[string]dbus.Variant
|
||||||
|
if err := connObj.Call("org.freedesktop.NetworkManager.Settings.Connection.GetSettings", 0).Store(&existingSettings); err != nil {
|
||||||
|
return fmt.Errorf("failed to get connection settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vpn, ok := existingSettings["vpn"]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("VPN settings are missing")
|
||||||
|
}
|
||||||
|
vpn["data"] = dbus.MakeVariant(data)
|
||||||
|
|
||||||
|
var stored map[string]map[string]dbus.Variant
|
||||||
|
if err := connObj.Call("org.freedesktop.NetworkManager.Settings.Connection.GetSecrets", 0, "vpn").Store(&stored); err != nil {
|
||||||
|
return fmt.Errorf("failed to preserve VPN secrets: %w", err)
|
||||||
|
}
|
||||||
|
if storedVPN, ok := stored["vpn"]; ok {
|
||||||
|
if secrets, ok := storedVPN["secrets"]; ok {
|
||||||
|
vpn["secrets"] = secrets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings := map[string]map[string]dbus.Variant{"vpn": vpn}
|
||||||
|
if connection, ok := existingSettings["connection"]; ok {
|
||||||
|
settings["connection"] = connection
|
||||||
|
}
|
||||||
|
|
||||||
|
var result map[string]dbus.Variant
|
||||||
|
if err := connObj.Call("org.freedesktop.NetworkManager.Settings.Connection.Update2", 0,
|
||||||
|
settings, uint32(0x1), map[string]dbus.Variant{}).Store(&result); err != nil {
|
||||||
|
return fmt.Errorf("failed to set NetworkManager secret-agent flags: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *NetworkManagerBackend) handleOpenConnectPasswordAuth(
|
||||||
|
ctx context.Context,
|
||||||
|
targetConn gonetworkmanager.Connection,
|
||||||
|
connName, targetUUID, vpnServiceType string,
|
||||||
|
data map[string]string,
|
||||||
|
) (*openConnectAuthResult, error) {
|
||||||
|
username := data["username"]
|
||||||
|
secrets := map[string]string{}
|
||||||
|
if stored, err := targetConn.GetSecrets("vpn"); err == nil {
|
||||||
|
if vpn, ok := stored["vpn"]; ok {
|
||||||
|
if saved, ok := vpn["secrets"].(map[string]string); ok {
|
||||||
|
secrets = saved
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
password := secrets["password"]
|
||||||
|
serverCert := secrets["certificate:"+data["gateway"]]
|
||||||
|
if serverCert == "" {
|
||||||
|
serverCert = secrets["gwcert"]
|
||||||
|
}
|
||||||
|
|
||||||
|
var reply PromptReply
|
||||||
|
if username == "" || password == "" {
|
||||||
|
if b.promptBroker == nil {
|
||||||
|
return nil, fmt.Errorf("password authentication requires an interactive prompt")
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := []string{}
|
||||||
|
fieldsInfo := []FieldInfo{}
|
||||||
|
if username == "" {
|
||||||
|
fields = append(fields, "username")
|
||||||
|
fieldsInfo = append(fieldsInfo, FieldInfo{Name: "username", Label: "Username", IsSecret: false})
|
||||||
|
}
|
||||||
|
if password == "" {
|
||||||
|
fields = append(fields, "password")
|
||||||
|
fieldsInfo = append(fieldsInfo, FieldInfo{Name: "password", Label: "Password", IsSecret: true})
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := b.promptBroker.Ask(ctx, PromptRequest{
|
||||||
|
Name: connName,
|
||||||
|
ConnType: "vpn",
|
||||||
|
VpnService: vpnServiceType,
|
||||||
|
SettingName: "vpn",
|
||||||
|
Fields: fields,
|
||||||
|
FieldsInfo: fieldsInfo,
|
||||||
|
Reason: "required",
|
||||||
|
ConnectionId: connName,
|
||||||
|
ConnectionUuid: targetUUID,
|
||||||
|
ConnectionPath: string(targetConn.GetPath()),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to request credentials: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reply, err = b.promptBroker.Wait(ctx, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("credentials prompt failed: %w", err)
|
||||||
|
}
|
||||||
|
if username == "" {
|
||||||
|
username = reply.Secrets["username"]
|
||||||
|
}
|
||||||
|
if password == "" {
|
||||||
|
password = reply.Secrets["password"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auth, err := runOpenConnectPasswordAuth(ctx, data, username, password, serverCert)
|
||||||
|
persistentSecrets := map[string]string{}
|
||||||
|
var authErr *openConnectAuthError
|
||||||
|
if err != nil && errors.As(err, &authErr) && authErr.serverCert != "" && authErr.serverCert != serverCert {
|
||||||
|
if b.promptBroker == nil {
|
||||||
|
return nil, fmt.Errorf("VPN server certificate is untrusted: %s", authErr.serverCert)
|
||||||
|
}
|
||||||
|
|
||||||
|
reason := "server-certificate"
|
||||||
|
if serverCert != "" {
|
||||||
|
reason = "server-certificate-changed"
|
||||||
|
}
|
||||||
|
|
||||||
|
token, promptErr := b.promptBroker.Ask(ctx, PromptRequest{
|
||||||
|
Name: connName,
|
||||||
|
ConnType: "vpn",
|
||||||
|
VpnService: vpnServiceType,
|
||||||
|
SettingName: "vpn",
|
||||||
|
Hints: []string{authErr.serverCert},
|
||||||
|
Reason: reason,
|
||||||
|
ConnectionId: connName,
|
||||||
|
ConnectionUuid: targetUUID,
|
||||||
|
ConnectionPath: string(targetConn.GetPath()),
|
||||||
|
})
|
||||||
|
if promptErr != nil {
|
||||||
|
return nil, fmt.Errorf("failed to request certificate confirmation: %w", promptErr)
|
||||||
|
}
|
||||||
|
if _, promptErr = b.promptBroker.Wait(ctx, token); promptErr != nil {
|
||||||
|
return nil, fmt.Errorf("certificate confirmation failed: %w", promptErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
auth, err = runOpenConnectPasswordAuth(ctx, data, username, password, authErr.serverCert)
|
||||||
|
if err == nil {
|
||||||
|
persistentSecrets["certificate:"+data["gateway"]] = authErr.serverCert
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(reply.Secrets) > 0 || len(persistentSecrets) > 0 {
|
||||||
|
creds := &pendingVPNCredentials{
|
||||||
|
ConnectionPath: string(targetConn.GetPath()),
|
||||||
|
PersistentSecrets: persistentSecrets,
|
||||||
|
}
|
||||||
|
if _, ok := reply.Secrets["username"]; ok {
|
||||||
|
creds.Username = username
|
||||||
|
}
|
||||||
|
if reply.Save {
|
||||||
|
creds.Username = username
|
||||||
|
creds.Password = password
|
||||||
|
creds.Secrets = map[string]string{"password": password}
|
||||||
|
creds.SavePassword = true
|
||||||
|
}
|
||||||
|
b.pendingVPNSaveMu.Lock()
|
||||||
|
b.pendingVPNSave = creds
|
||||||
|
b.pendingVPNSaveMu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
return auth, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func suggestedOpenConnectServerCert(output string) string {
|
||||||
|
for _, field := range strings.Fields(output) {
|
||||||
|
field = strings.Trim(field, "'\".,")
|
||||||
|
if strings.HasPrefix(field, "pin-sha256:") {
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (b *NetworkManagerBackend) handleOpenVPNUsernameAuth(targetConn gonetworkmanager.Connection, connName, targetUUID, vpnServiceType string) error {
|
func (b *NetworkManagerBackend) handleOpenVPNUsernameAuth(targetConn gonetworkmanager.Connection, connName, targetUUID, vpnServiceType string) error {
|
||||||
log.Infof("[ConnectVPN] OpenVPN requires username in vpn.data - prompting before activation")
|
log.Infof("[ConnectVPN] OpenVPN requires username in vpn.data - prompting before activation")
|
||||||
|
|
||||||
@@ -758,13 +979,13 @@ func (b *NetworkManagerBackend) updateVPNConnectionState() {
|
|||||||
b.state.VPNErrorUuid = ""
|
b.state.VPNErrorUuid = ""
|
||||||
b.stateMutex.Unlock()
|
b.stateMutex.Unlock()
|
||||||
|
|
||||||
// Clear cached PKCS11 PIN and SAML cookie on success
|
// Clear cached one-shot authentication values on success.
|
||||||
b.cachedPKCS11Mu.Lock()
|
b.cachedPKCS11Mu.Lock()
|
||||||
b.cachedPKCS11PIN = nil
|
b.cachedPKCS11PIN = nil
|
||||||
b.cachedPKCS11Mu.Unlock()
|
b.cachedPKCS11Mu.Unlock()
|
||||||
b.cachedGPSamlMu.Lock()
|
b.cachedOpenConnectMu.Lock()
|
||||||
b.cachedGPSamlCookie = nil
|
b.cachedOpenConnectAuth = nil
|
||||||
b.cachedGPSamlMu.Unlock()
|
b.cachedOpenConnectMu.Unlock()
|
||||||
|
|
||||||
b.pendingVPNSaveMu.Lock()
|
b.pendingVPNSaveMu.Lock()
|
||||||
pending := b.pendingVPNSave
|
pending := b.pendingVPNSave
|
||||||
@@ -787,13 +1008,16 @@ func (b *NetworkManagerBackend) updateVPNConnectionState() {
|
|||||||
b.state.VPNErrorUuid = connectingVPNUUID
|
b.state.VPNErrorUuid = connectingVPNUUID
|
||||||
b.stateMutex.Unlock()
|
b.stateMutex.Unlock()
|
||||||
|
|
||||||
// Clear cached PKCS11 PIN and SAML cookie on failure
|
// Clear cached one-shot authentication values on failure.
|
||||||
b.cachedPKCS11Mu.Lock()
|
b.cachedPKCS11Mu.Lock()
|
||||||
b.cachedPKCS11PIN = nil
|
b.cachedPKCS11PIN = nil
|
||||||
b.cachedPKCS11Mu.Unlock()
|
b.cachedPKCS11Mu.Unlock()
|
||||||
b.cachedGPSamlMu.Lock()
|
b.cachedOpenConnectMu.Lock()
|
||||||
b.cachedGPSamlCookie = nil
|
b.cachedOpenConnectAuth = nil
|
||||||
b.cachedGPSamlMu.Unlock()
|
b.cachedOpenConnectMu.Unlock()
|
||||||
|
b.pendingVPNSaveMu.Lock()
|
||||||
|
b.pendingVPNSave = nil
|
||||||
|
b.pendingVPNSaveMu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -811,13 +1035,16 @@ func (b *NetworkManagerBackend) updateVPNConnectionState() {
|
|||||||
b.state.VPNErrorUuid = connectingVPNUUID
|
b.state.VPNErrorUuid = connectingVPNUUID
|
||||||
b.stateMutex.Unlock()
|
b.stateMutex.Unlock()
|
||||||
|
|
||||||
// Clear cached PKCS11 PIN and SAML cookie
|
// Clear cached one-shot authentication values.
|
||||||
b.cachedPKCS11Mu.Lock()
|
b.cachedPKCS11Mu.Lock()
|
||||||
b.cachedPKCS11PIN = nil
|
b.cachedPKCS11PIN = nil
|
||||||
b.cachedPKCS11Mu.Unlock()
|
b.cachedPKCS11Mu.Unlock()
|
||||||
b.cachedGPSamlMu.Lock()
|
b.cachedOpenConnectMu.Lock()
|
||||||
b.cachedGPSamlCookie = nil
|
b.cachedOpenConnectAuth = nil
|
||||||
b.cachedGPSamlMu.Unlock()
|
b.cachedOpenConnectMu.Unlock()
|
||||||
|
b.pendingVPNSaveMu.Lock()
|
||||||
|
b.pendingVPNSave = nil
|
||||||
|
b.pendingVPNSaveMu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,17 +1090,40 @@ func (b *NetworkManagerBackend) saveVPNCredentials(creds *pendingVPNCredentials)
|
|||||||
log.Infof("[saveVPNCredentials] Saving username")
|
log.Infof("[saveVPNCredentials] Saving username")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save secrets if requested
|
secs := map[string]string{}
|
||||||
if creds.SavePassword {
|
if len(creds.PersistentSecrets) > 0 {
|
||||||
secs := creds.Secrets
|
var stored map[string]map[string]dbus.Variant
|
||||||
if len(secs) == 0 {
|
if err := connObj.Call("org.freedesktop.NetworkManager.Settings.Connection.GetSecrets", 0, "vpn").Store(&stored); err != nil {
|
||||||
secs = map[string]string{"password": creds.Password}
|
log.Warnf("[saveVPNCredentials] GetSecrets failed: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
for field := range secs {
|
if storedVPN, ok := stored["vpn"]; ok {
|
||||||
|
if storedSecrets, ok := storedVPN["secrets"]; ok {
|
||||||
|
saved, _ := storedSecrets.Value().(map[string]string)
|
||||||
|
for field, value := range saved {
|
||||||
|
secs[field] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for field, value := range creds.PersistentSecrets {
|
||||||
|
secs[field] = value
|
||||||
data[field+"-flags"] = "0"
|
data[field+"-flags"] = "0"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if creds.SavePassword {
|
||||||
|
toSave := creds.Secrets
|
||||||
|
if len(toSave) == 0 {
|
||||||
|
toSave = map[string]string{"password": creds.Password}
|
||||||
|
}
|
||||||
|
for field, value := range toSave {
|
||||||
|
secs[field] = value
|
||||||
|
data[field+"-flags"] = "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(secs) > 0 {
|
||||||
vpn["secrets"] = dbus.MakeVariant(secs)
|
vpn["secrets"] = dbus.MakeVariant(secs)
|
||||||
log.Infof("[saveVPNCredentials] Saving %d secret field(s) with flags=0", len(secs))
|
log.Infof("[saveVPNCredentials] Saving %d secret field(s)", len(secs))
|
||||||
}
|
}
|
||||||
|
|
||||||
vpn["data"] = dbus.MakeVariant(data)
|
vpn["data"] = dbus.MakeVariant(data)
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
mock_gonetworkmanager "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/github.com/Wifx/gonetworkmanager/v2"
|
mock_gonetworkmanager "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/github.com/Wifx/gonetworkmanager/v2"
|
||||||
"github.com/Wifx/gonetworkmanager/v2"
|
"github.com/Wifx/gonetworkmanager/v2"
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -136,3 +140,137 @@ func TestNetworkManagerBackend_UpdateVPNConnectionState_EmptyUUID(t *testing.T)
|
|||||||
backend.updateVPNConnectionState()
|
backend.updateVPNConnectionState()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDetectVPNAuthAction_FortinetPasswordOnly(t *testing.T) {
|
||||||
|
service := "org.freedesktop.NetworkManager.openconnect"
|
||||||
|
|
||||||
|
assert.Equal(t, "openconnect_password", detectVPNAuthAction(service, map[string]string{
|
||||||
|
"protocol": "fortinet",
|
||||||
|
"authtype": "password",
|
||||||
|
}))
|
||||||
|
assert.Empty(t, detectVPNAuthAction(service, map[string]string{
|
||||||
|
"protocol": "anyconnect",
|
||||||
|
"authtype": "password",
|
||||||
|
}))
|
||||||
|
assert.Empty(t, detectVPNAuthAction(service, map[string]string{
|
||||||
|
"protocol": "fortinet",
|
||||||
|
"authtype": "saml",
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnsureOpenConnectAgentFlags(t *testing.T) {
|
||||||
|
data := map[string]string{"protocol": "fortinet"}
|
||||||
|
assert.True(t, setOpenConnectAgentFlags(data))
|
||||||
|
assert.Equal(t, "2", data["cookie-flags"])
|
||||||
|
assert.Equal(t, "2", data["gateway-flags"])
|
||||||
|
assert.Equal(t, "2", data["gwcert-flags"])
|
||||||
|
assert.False(t, setOpenConnectAgentFlags(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpenConnectCertificateConfirmation(t *testing.T) {
|
||||||
|
binDir := t.TempDir()
|
||||||
|
openConnectPath := filepath.Join(binDir, "openconnect")
|
||||||
|
script := `#!/bin/sh
|
||||||
|
case "$*" in
|
||||||
|
*--servercert=pin-sha256:TEST-FINGERPRINT*)
|
||||||
|
printf '%s\n' "COOKIE='SVPNCOOKIE=test'" "HOST='vpn.example.test'" "FINGERPRINT='pin-sha256:TEST-FINGERPRINT'"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
printf '%s\n' 'Add --servercert pin-sha256:TEST-FINGERPRINT' >&2
|
||||||
|
exit 1
|
||||||
|
`
|
||||||
|
assert.NoError(t, os.WriteFile(openConnectPath, []byte(script), 0o755))
|
||||||
|
t.Setenv("PATH", binDir)
|
||||||
|
|
||||||
|
conn := mock_gonetworkmanager.NewMockConnection(t)
|
||||||
|
connPath := dbus.ObjectPath("/org/freedesktop/NetworkManager/Settings/999")
|
||||||
|
conn.EXPECT().GetSecrets("vpn").Return(gonetworkmanager.ConnectionSettings{
|
||||||
|
"vpn": {"secrets": map[string]string{"password": "test-password"}},
|
||||||
|
}, nil)
|
||||||
|
conn.EXPECT().GetPath().Return(connPath).Twice()
|
||||||
|
|
||||||
|
broker := &fakePromptBroker{
|
||||||
|
asked: make(chan PromptRequest, 1),
|
||||||
|
reply: PromptReply{},
|
||||||
|
}
|
||||||
|
backend := &NetworkManagerBackend{promptBroker: broker}
|
||||||
|
data := map[string]string{
|
||||||
|
"gateway": "vpn.example.test:443",
|
||||||
|
"protocol": "fortinet",
|
||||||
|
"authtype": "password",
|
||||||
|
"username": "test-user",
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := backend.handleOpenConnectPasswordAuth(
|
||||||
|
context.Background(), conn, "Test VPN", "test-uuid",
|
||||||
|
"org.freedesktop.NetworkManager.openconnect", data,
|
||||||
|
)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "SVPNCOOKIE=test", result.Cookie)
|
||||||
|
assert.Equal(t, "vpn.example.test:443", result.Host)
|
||||||
|
|
||||||
|
prompt := <-broker.asked
|
||||||
|
assert.Equal(t, "server-certificate", prompt.Reason)
|
||||||
|
assert.Equal(t, []string{"pin-sha256:TEST-FINGERPRINT"}, prompt.Hints)
|
||||||
|
|
||||||
|
assert.Equal(t, map[string]string{
|
||||||
|
"certificate:vpn.example.test:443": "pin-sha256:TEST-FINGERPRINT",
|
||||||
|
}, backend.pendingVPNSave.PersistentSecrets)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpenConnectCertificateRotationReprompts(t *testing.T) {
|
||||||
|
binDir := t.TempDir()
|
||||||
|
openConnectPath := filepath.Join(binDir, "openconnect")
|
||||||
|
script := `#!/bin/sh
|
||||||
|
case "$*" in
|
||||||
|
*--servercert=pin-sha256:NEW-FINGERPRINT*)
|
||||||
|
printf '%s\n' "COOKIE='SVPNCOOKIE=test'" "HOST='vpn.example.test'" "FINGERPRINT='pin-sha256:NEW-FINGERPRINT'"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
printf '%s\n' 'Add --servercert pin-sha256:NEW-FINGERPRINT' >&2
|
||||||
|
exit 1
|
||||||
|
`
|
||||||
|
assert.NoError(t, os.WriteFile(openConnectPath, []byte(script), 0o755))
|
||||||
|
t.Setenv("PATH", binDir)
|
||||||
|
|
||||||
|
conn := mock_gonetworkmanager.NewMockConnection(t)
|
||||||
|
connPath := dbus.ObjectPath("/org/freedesktop/NetworkManager/Settings/999")
|
||||||
|
conn.EXPECT().GetSecrets("vpn").Return(gonetworkmanager.ConnectionSettings{
|
||||||
|
"vpn": {"secrets": map[string]string{
|
||||||
|
"password": "test-password",
|
||||||
|
"certificate:vpn.example.test:443": "pin-sha256:OLD-FINGERPRINT",
|
||||||
|
}},
|
||||||
|
}, nil)
|
||||||
|
conn.EXPECT().GetPath().Return(connPath).Twice()
|
||||||
|
|
||||||
|
broker := &fakePromptBroker{
|
||||||
|
asked: make(chan PromptRequest, 1),
|
||||||
|
reply: PromptReply{},
|
||||||
|
}
|
||||||
|
backend := &NetworkManagerBackend{promptBroker: broker}
|
||||||
|
data := map[string]string{
|
||||||
|
"gateway": "vpn.example.test:443",
|
||||||
|
"protocol": "fortinet",
|
||||||
|
"authtype": "password",
|
||||||
|
"username": "test-user",
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := backend.handleOpenConnectPasswordAuth(
|
||||||
|
context.Background(), conn, "Test VPN", "test-uuid",
|
||||||
|
"org.freedesktop.NetworkManager.openconnect", data,
|
||||||
|
)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "SVPNCOOKIE=test", result.Cookie)
|
||||||
|
|
||||||
|
prompt := <-broker.asked
|
||||||
|
assert.Equal(t, "server-certificate-changed", prompt.Reason)
|
||||||
|
assert.Equal(t, []string{"pin-sha256:NEW-FINGERPRINT"}, prompt.Hints)
|
||||||
|
|
||||||
|
assert.Equal(t, map[string]string{
|
||||||
|
"certificate:vpn.example.test:443": "pin-sha256:NEW-FINGERPRINT",
|
||||||
|
}, backend.pendingVPNSave.PersistentSecrets)
|
||||||
|
assert.False(t, backend.pendingVPNSave.SavePassword)
|
||||||
|
assert.Empty(t, backend.pendingVPNSave.Secrets)
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ func HandleRequest(conn *models.Conn, req models.Request, manager *Manager) {
|
|||||||
handleGetNetworkQRCode(conn, req, manager)
|
handleGetNetworkQRCode(conn, req, manager)
|
||||||
case "network.qrcode-content":
|
case "network.qrcode-content":
|
||||||
handleGetNetworkQRCodeContent(conn, req, manager)
|
handleGetNetworkQRCodeContent(conn, req, manager)
|
||||||
|
case "network.generate-qrcode":
|
||||||
|
handleGenerateQRCode(conn, req)
|
||||||
case "network.delete-qrcode":
|
case "network.delete-qrcode":
|
||||||
handleDeleteQRCode(conn, req, manager)
|
handleDeleteQRCode(conn, req, manager)
|
||||||
case "network.ethernet.info":
|
case "network.ethernet.info":
|
||||||
@@ -365,6 +367,22 @@ func handleGetNetworkQRCodeContent(conn *models.Conn, req models.Request, manage
|
|||||||
models.Respond(conn, req.ID, content)
|
models.Respond(conn, req.ID, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleGenerateQRCode(conn *models.Conn, req models.Request) {
|
||||||
|
text, err := params.String(req.Params, "text")
|
||||||
|
if err != nil {
|
||||||
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
paths, err := generateTextQRCode(text)
|
||||||
|
if err != nil {
|
||||||
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
models.Respond(conn, req.ID, paths)
|
||||||
|
}
|
||||||
|
|
||||||
func handleDeleteQRCode(conn *models.Conn, req models.Request, _ *Manager) {
|
func handleDeleteQRCode(conn *models.Conn, req models.Request, _ *Manager) {
|
||||||
path, err := params.String(req.Params, "path")
|
path, err := params.String(req.Params, "path")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/yeqown/go-qrcode/v2"
|
||||||
|
"github.com/yeqown/go-qrcode/writer/standard"
|
||||||
|
)
|
||||||
|
|
||||||
|
const textQRCodeTmpPrefix = "/tmp/dank-text-qrcode-"
|
||||||
|
|
||||||
|
func generateTextQRCode(text string) ([2]string, error) {
|
||||||
|
qrc, err := qrcode.New(text)
|
||||||
|
if err != nil {
|
||||||
|
return [2]string{}, fmt.Errorf("failed to create QR code for text: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pathThemed, pathNormal := textQRCodePaths(text)
|
||||||
|
|
||||||
|
if err := saveQRCodePNG(qrc, pathThemed, standard.WithBgTransparent(), standard.WithFgColorRGBHex("#ffffff")); err != nil {
|
||||||
|
return [2]string{}, err
|
||||||
|
}
|
||||||
|
if err := saveQRCodePNG(qrc, pathNormal); err != nil {
|
||||||
|
return [2]string{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return [2]string{pathThemed, pathNormal}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to a temp file and rename into place so the shell's Image never
|
||||||
|
// observes a partially written PNG.
|
||||||
|
func saveQRCodePNG(qrc *qrcode.QRCode, path string, opts ...standard.ImageOption) error {
|
||||||
|
tmpPath := path + ".tmp"
|
||||||
|
opts = append(opts, standard.WithBuiltinImageEncoder(standard.PNG_FORMAT))
|
||||||
|
|
||||||
|
w, err := standard.New(tmpPath, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create QR code writer: %w", err)
|
||||||
|
}
|
||||||
|
if err := qrc.Save(w); err != nil {
|
||||||
|
os.Remove(tmpPath)
|
||||||
|
return fmt.Errorf("failed to save QR code: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.Rename(tmpPath, path); err != nil {
|
||||||
|
os.Remove(tmpPath)
|
||||||
|
return fmt.Errorf("failed to move QR code into place: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paths are unique per generation, not per text: the library's mask selection
|
||||||
|
// is non-deterministic, so regenerating the same text produces different
|
||||||
|
// bytes, and reusing a path lets the shell's URL-keyed pixmap cache serve a
|
||||||
|
// stale pattern over the new file.
|
||||||
|
func textQRCodePaths(text string) (themed, normal string) {
|
||||||
|
hash := fmt.Sprintf("%x", sha256.Sum256([]byte(text)))[:8]
|
||||||
|
nonce := time.Now().UnixNano()
|
||||||
|
themed = fmt.Sprintf("%s%s-%d-themed.png", textQRCodeTmpPrefix, hash, nonce)
|
||||||
|
normal = fmt.Sprintf("%s%s-%d-normal.png", textQRCodeTmpPrefix, hash, nonce)
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ func qrCodePaths(ssid string) (themed, normal string) {
|
|||||||
|
|
||||||
func isValidQRCodePath(path string) bool {
|
func isValidQRCodePath(path string) bool {
|
||||||
clean := filepath.Clean(path)
|
clean := filepath.Clean(path)
|
||||||
return strings.HasPrefix(clean, qrCodeTmpPrefix) && strings.HasSuffix(clean, ".png")
|
return (strings.HasPrefix(clean, qrCodeTmpPrefix) || strings.HasPrefix(clean, textQRCodeTmpPrefix)) && strings.HasSuffix(clean, ".png")
|
||||||
}
|
}
|
||||||
|
|
||||||
var safePathChar = regexp.MustCompile(`[^a-zA-Z0-9_-]`)
|
var safePathChar = regexp.MustCompile(`[^a-zA-Z0-9_-]`)
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package registries
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RegistryInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Official bool `json:"official"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuccessResult struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleRequest(conn *models.Conn, req models.Request) {
|
||||||
|
switch req.Method {
|
||||||
|
case "registries.list":
|
||||||
|
HandleList(conn, req)
|
||||||
|
case "registries.add":
|
||||||
|
HandleAdd(conn, req)
|
||||||
|
case "registries.remove":
|
||||||
|
HandleRemove(conn, req)
|
||||||
|
default:
|
||||||
|
models.RespondError(conn, req.ID, fmt.Sprintf("unknown method: %s", req.Method))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleList(conn *models.Conn, req models.Request) {
|
||||||
|
sources := registries.Load(afero.NewOsFs())
|
||||||
|
result := make([]RegistryInfo, len(sources))
|
||||||
|
for i, s := range sources {
|
||||||
|
result[i] = RegistryInfo{Name: s.Name, URL: s.URL, Official: s.Official()}
|
||||||
|
}
|
||||||
|
models.Respond(conn, req.ID, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleAdd(conn *models.Conn, req models.Request) {
|
||||||
|
name, ok := models.Get[string](req, "name")
|
||||||
|
if !ok {
|
||||||
|
models.RespondError(conn, req.ID, "missing or invalid 'name' parameter")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
url, ok := models.Get[string](req, "url")
|
||||||
|
if !ok {
|
||||||
|
models.RespondError(conn, req.ID, "missing or invalid 'url' parameter")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := registries.Add(afero.NewOsFs(), name, url); err != nil {
|
||||||
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
models.Respond(conn, req.ID, SuccessResult{
|
||||||
|
Success: true,
|
||||||
|
Message: fmt.Sprintf("registry added: %s", name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleRemove(conn *models.Conn, req models.Request) {
|
||||||
|
name, ok := models.Get[string](req, "name")
|
||||||
|
if !ok {
|
||||||
|
models.RespondError(conn, req.ID, "missing or invalid 'name' parameter")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := registries.Remove(afero.NewOsFs(), name); err != nil {
|
||||||
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
models.Respond(conn, req.ID, SuccessResult{
|
||||||
|
Success: true,
|
||||||
|
Message: fmt.Sprintf("registry removed: %s", name),
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/network"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/network"
|
||||||
serverPlugins "github.com/AvengeMedia/DankMaterialShell/core/internal/server/plugins"
|
serverPlugins "github.com/AvengeMedia/DankMaterialShell/core/internal/server/plugins"
|
||||||
|
serverRegistries "github.com/AvengeMedia/DankMaterialShell/core/internal/server/registries"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/sysupdate"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/sysupdate"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/tailscale"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/tailscale"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/thememode"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/thememode"
|
||||||
@@ -47,6 +48,11 @@ func RouteRequest(conn *models.Conn, req models.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(req.Method, "registries.") {
|
||||||
|
serverRegistries.HandleRequest(conn, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(req.Method, "theme.auto.") {
|
if strings.HasPrefix(req.Method, "theme.auto.") {
|
||||||
if themeModeManager == nil {
|
if themeModeManager == nil {
|
||||||
models.RespondError(conn, req.ID, "theme mode manager not initialized")
|
models.RespondError(conn, req.ID, "theme mode manager not initialized")
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"github.com/AvengeMedia/dankgo/syncmap"
|
"github.com/AvengeMedia/dankgo/syncmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APIVersion = 28
|
const APIVersion = 29
|
||||||
|
|
||||||
var CLIVersion = "dev"
|
var CLIVersion = "dev"
|
||||||
|
|
||||||
@@ -1183,6 +1183,38 @@ func handleSubscribe(conn *models.Conn, req models.Request) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shouldSubscribe("location") && locationManager != nil {
|
||||||
|
wg.Add(1)
|
||||||
|
locationChan := locationManager.Subscribe(clientID + "-location")
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
defer locationManager.Unsubscribe(clientID + "-location")
|
||||||
|
|
||||||
|
initialState := locationManager.GetState()
|
||||||
|
select {
|
||||||
|
case eventChan <- ServiceEvent{Service: "location", Data: initialState}:
|
||||||
|
case <-stopChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case state, ok := <-locationChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case eventChan <- ServiceEvent{Service: "location", Data: state}:
|
||||||
|
case <-stopChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-stopChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if shouldSubscribe("sysupdate") && sysUpdateManager != nil {
|
if shouldSubscribe("sysupdate") && sysUpdateManager != nil {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
sysupdateChan := sysUpdateManager.Subscribe(clientID + "-sysupdate")
|
sysupdateChan := sysUpdateManager.Subscribe(clientID + "-sysupdate")
|
||||||
|
|||||||
@@ -759,6 +759,9 @@ func (m *Manager) schedulerLoop() {
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
m.recalcSchedule(now)
|
m.recalcSchedule(now)
|
||||||
|
// publish independent of output readiness so night status never
|
||||||
|
// presents a stale schedule while applies are blocked (#2967)
|
||||||
|
m.updateStateFromSchedule()
|
||||||
|
|
||||||
waitDur := 24 * time.Hour
|
waitDur := 24 * time.Hour
|
||||||
if enabled {
|
if enabled {
|
||||||
@@ -1104,13 +1107,15 @@ func (m *Manager) SetTemperature(low, high int) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.LowTemp = low
|
updated := m.config
|
||||||
m.config.HighTemp = high
|
updated.LowTemp = low
|
||||||
err := m.config.Validate()
|
updated.HighTemp = high
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1122,14 +1127,16 @@ func (m *Manager) SetLocation(lat, lon float64) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.Latitude = &lat
|
updated := m.config
|
||||||
m.config.Longitude = &lon
|
updated.Latitude = &lat
|
||||||
m.config.UseIPLocation = false
|
updated.Longitude = &lon
|
||||||
err := m.config.Validate()
|
updated.UseIPLocation = false
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1164,13 +1171,15 @@ func (m *Manager) SetManualTimes(sunrise, sunset time.Time) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.ManualSunrise = &sunrise
|
updated := m.config
|
||||||
m.config.ManualSunset = &sunset
|
updated.ManualSunrise = &sunrise
|
||||||
err := m.config.Validate()
|
updated.ManualSunset = &sunset
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1193,12 +1202,14 @@ func (m *Manager) SetGamma(gamma float64) error {
|
|||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m.config.Gamma = gamma
|
updated := m.config
|
||||||
err := m.config.Validate()
|
updated.Gamma = gamma
|
||||||
m.configMutex.Unlock()
|
if err := updated.Validate(); err != nil {
|
||||||
if err != nil {
|
m.configMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
m.config = updated
|
||||||
|
m.configMutex.Unlock()
|
||||||
m.triggerUpdate()
|
m.triggerUpdate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
mocks_wlclient "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlclient"
|
mocks_wlclient "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlclient"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/proto/wlr_gamma_control"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestManager_ActorSerializesOutputStateAccess(t *testing.T) {
|
func TestManager_ActorSerializesOutputStateAccess(t *testing.T) {
|
||||||
@@ -412,3 +413,75 @@ func TestNewManager_InvalidConfig(t *testing.T) {
|
|||||||
_, err := NewManager(mockDisplay, config)
|
_, err := NewManager(mockDisplay, config)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetters_RejectedValuesLeaveConfigUntouched(t *testing.T) {
|
||||||
|
newManager := func() *Manager {
|
||||||
|
return &Manager{
|
||||||
|
config: DefaultConfig(),
|
||||||
|
updateTrigger: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("SetTemperature", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetTemperature(3200, 2500)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetLocation", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetLocation(120.0, 10.0)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetGamma", func(t *testing.T) {
|
||||||
|
m := newManager()
|
||||||
|
before := m.config
|
||||||
|
|
||||||
|
err := m.SetGamma(-1.0)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, before, m.config)
|
||||||
|
assert.Empty(t, m.updateTrigger)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetters_ValidValuesCommitAndTrigger(t *testing.T) {
|
||||||
|
m := &Manager{
|
||||||
|
config: DefaultConfig(),
|
||||||
|
updateTrigger: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
err := m.SetTemperature(3000, 6000)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 3000, m.config.LowTemp)
|
||||||
|
assert.Equal(t, 6000, m.config.HighTemp)
|
||||||
|
assert.Len(t, m.updateTrigger, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyGamma_SkipsUnchangedTempAndGamma(t *testing.T) {
|
||||||
|
m := &Manager{config: DefaultConfig()}
|
||||||
|
m.controlsInitialized = true
|
||||||
|
|
||||||
|
out := &outputState{
|
||||||
|
id: 1,
|
||||||
|
rampSize: 256,
|
||||||
|
gammaControl: &wlr_gamma_control.ZwlrGammaControlV1{},
|
||||||
|
lastTemp: 5000,
|
||||||
|
lastGamma: m.config.Gamma,
|
||||||
|
}
|
||||||
|
m.outputs.Store(out.id, out)
|
||||||
|
|
||||||
|
m.applyGamma(5000)
|
||||||
|
|
||||||
|
assert.False(t, out.failed, "unchanged temp must not reach the compositor write path")
|
||||||
|
assert.Equal(t, 5000, out.lastTemp)
|
||||||
|
assert.Equal(t, uint32(256), out.rampSize)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
"github.com/go-git/go-git/v6"
|
"github.com/go-git/go-git/v6"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
const registryRepo = "https://github.com/AvengeMedia/dms-plugin-registry.git"
|
|
||||||
|
|
||||||
type ColorScheme struct {
|
type ColorScheme struct {
|
||||||
Primary string `json:"primary,omitempty"`
|
Primary string `json:"primary,omitempty"`
|
||||||
PrimaryText string `json:"primaryText,omitempty"`
|
PrimaryText string `json:"primaryText,omitempty"`
|
||||||
@@ -151,6 +150,7 @@ type Theme struct {
|
|||||||
type GitClient interface {
|
type GitClient interface {
|
||||||
PlainClone(path string, url string) error
|
PlainClone(path string, url string) error
|
||||||
Pull(path string) error
|
Pull(path string) error
|
||||||
|
OriginURL(path string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type realGitClient struct{}
|
type realGitClient struct{}
|
||||||
@@ -182,11 +182,28 @@ func (g *realGitClient) Pull(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *realGitClient) OriginURL(path string) (string, error) {
|
||||||
|
repo, err := git.PlainOpen(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
remote, err := repo.Remote("origin")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
urls := remote.Config().URLs
|
||||||
|
if len(urls) == 0 {
|
||||||
|
return "", errors.New("origin remote has no URL")
|
||||||
|
}
|
||||||
|
return urls[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
type Registry struct {
|
type Registry struct {
|
||||||
fs afero.Fs
|
fs afero.Fs
|
||||||
cacheDir string
|
cacheDir string
|
||||||
themes []Theme
|
registries []registries.Source
|
||||||
git GitClient
|
themes []Theme
|
||||||
|
git GitClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRegistry() (*Registry, error) {
|
func NewRegistry() (*Registry, error) {
|
||||||
@@ -194,61 +211,63 @@ func NewRegistry() (*Registry, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRegistryWithFs(fs afero.Fs) (*Registry, error) {
|
func NewRegistryWithFs(fs afero.Fs) (*Registry, error) {
|
||||||
cacheDir := getCacheDir()
|
|
||||||
return &Registry{
|
return &Registry{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
cacheDir: cacheDir,
|
cacheDir: getCacheDir(),
|
||||||
git: &realGitClient{},
|
registries: registries.Load(fs),
|
||||||
|
git: &realGitClient{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Registry) cacheDirFor(src registries.Source) string {
|
||||||
|
return filepath.Join(r.cacheDir, src.Name)
|
||||||
|
}
|
||||||
|
|
||||||
func getCacheDir() string {
|
func getCacheDir() string {
|
||||||
return filepath.Join(os.TempDir(), "dankdots-plugin-registry")
|
return filepath.Join(os.TempDir(), "dankdots-plugin-registry")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) Update() error {
|
// A cached clone is reused only when its origin still matches the configured
|
||||||
exists, err := afero.DirExists(r.fs, r.cacheDir)
|
// URL; renamed or re-pointed registries re-clone instead of pulling from the
|
||||||
|
// stale remote.
|
||||||
|
func (r *Registry) updateOne(src registries.Source) error {
|
||||||
|
dir := r.cacheDirFor(src)
|
||||||
|
exists, err := afero.DirExists(r.fs, dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to check cache directory: %w", err)
|
return fmt.Errorf("failed to check cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if exists {
|
||||||
if err := r.fs.MkdirAll(filepath.Dir(r.cacheDir), 0o755); err != nil {
|
origin, originErr := r.git.OriginURL(dir)
|
||||||
return fmt.Errorf("failed to create cache directory: %w", err)
|
if originErr == nil && origin == src.URL && r.git.Pull(dir) == nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
if err := r.fs.RemoveAll(dir); err != nil {
|
||||||
if err := r.git.PlainClone(r.cacheDir, registryRepo); err != nil {
|
return fmt.Errorf("failed to remove stale registry cache: %w", err)
|
||||||
return fmt.Errorf("failed to clone registry: %w", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := r.git.Pull(r.cacheDir); err != nil {
|
|
||||||
if err := r.fs.RemoveAll(r.cacheDir); err != nil {
|
|
||||||
return fmt.Errorf("failed to remove corrupted registry: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.fs.MkdirAll(filepath.Dir(r.cacheDir), 0o755); err != nil {
|
|
||||||
return fmt.Errorf("failed to create cache directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.git.PlainClone(r.cacheDir, registryRepo); err != nil {
|
|
||||||
return fmt.Errorf("failed to re-clone registry: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.loadThemes()
|
if err := r.fs.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create cache directory: %w", err)
|
||||||
|
}
|
||||||
|
if err := r.git.PlainClone(dir, src.URL); err != nil {
|
||||||
|
return fmt.Errorf("failed to clone: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) loadThemes() error {
|
// A registry without a themes/ directory is a valid plugins-only registry.
|
||||||
themesDir := filepath.Join(r.cacheDir, "themes")
|
func (r *Registry) loadThemesFrom(dir string) ([]Theme, error) {
|
||||||
|
themesDir := filepath.Join(dir, "themes")
|
||||||
entries, err := afero.ReadDir(r.fs, themesDir)
|
entries, err := afero.ReadDir(r.fs, themesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read themes directory: %w", err)
|
if os.IsNotExist(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("failed to read themes directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.themes = []Theme{}
|
var themes []Theme
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if !entry.IsDir() {
|
if !entry.IsDir() {
|
||||||
continue
|
continue
|
||||||
@@ -278,10 +297,46 @@ func (r *Registry) loadThemes() error {
|
|||||||
theme.PreviewPath = previewPath
|
theme.PreviewPath = previewPath
|
||||||
}
|
}
|
||||||
|
|
||||||
r.themes = append(r.themes, theme)
|
themes = append(themes, theme)
|
||||||
}
|
}
|
||||||
|
return themes, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
// Pre-multi-registry caches were a single clone at the base dir; the per-name
|
||||||
|
// layout nests under it, so a leftover clone is deleted wholesale first.
|
||||||
|
func (r *Registry) resetLegacyCache() {
|
||||||
|
if exists, _ := afero.DirExists(r.fs, filepath.Join(r.cacheDir, ".git")); exists {
|
||||||
|
_ = r.fs.RemoveAll(r.cacheDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update refreshes every configured registry, aggregating themes in
|
||||||
|
// declaration order (first occurrence of an ID wins). A failing registry is
|
||||||
|
// reported in the joined error but does not block the others.
|
||||||
|
func (r *Registry) Update() error {
|
||||||
|
r.resetLegacyCache()
|
||||||
|
r.themes = []Theme{}
|
||||||
|
seen := make(map[string]struct{})
|
||||||
|
var errs []error
|
||||||
|
for _, src := range r.registries {
|
||||||
|
if err := r.updateOne(src); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("registry %s: %w", src.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
themes, err := r.loadThemesFrom(r.cacheDirFor(src))
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("registry %s: %w", src.Name, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, t := range themes {
|
||||||
|
if _, dup := seen[t.ID]; dup {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[t.ID] = struct{}{}
|
||||||
|
r.themes = append(r.themes, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadThemeWCAG(fs afero.Fs, themeDir string) *ThemeWCAG {
|
func loadThemeWCAG(fs afero.Fs, themeDir string) *ThemeWCAG {
|
||||||
@@ -300,7 +355,7 @@ func loadThemeWCAG(fs afero.Fs, themeDir string) *ThemeWCAG {
|
|||||||
|
|
||||||
func (r *Registry) List() ([]Theme, error) {
|
func (r *Registry) List() ([]Theme, error) {
|
||||||
if len(r.themes) == 0 {
|
if len(r.themes) == 0 {
|
||||||
if err := r.Update(); err != nil {
|
if err := r.Update(); err != nil && len(r.themes) == 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,11 +398,25 @@ func (r *Registry) Get(idOrName string) (*Theme, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) GetThemeSourcePath(themeID string) string {
|
func (r *Registry) GetThemeSourcePath(themeID string) string {
|
||||||
return filepath.Join(r.cacheDir, "themes", themeID, "theme.json")
|
// Themes may live under any registry's subdir. Search them all; first hit wins.
|
||||||
|
for _, cfg := range r.registries {
|
||||||
|
candidate := filepath.Join(r.cacheDirFor(cfg), "themes", themeID, "theme.json")
|
||||||
|
if exists, _ := afero.Exists(r.fs, candidate); exists {
|
||||||
|
return candidate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fallback to first registry (legacy path semantics).
|
||||||
|
return filepath.Join(r.cacheDirFor(r.registries[0]), "themes", themeID, "theme.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) GetThemeDir(themeID string) string {
|
func (r *Registry) GetThemeDir(themeID string) string {
|
||||||
return filepath.Join(r.cacheDir, "themes", themeID)
|
for _, cfg := range r.registries {
|
||||||
|
candidate := filepath.Join(r.cacheDirFor(cfg), "themes", themeID)
|
||||||
|
if exists, _ := afero.DirExists(r.fs, candidate); exists {
|
||||||
|
return candidate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filepath.Join(r.cacheDirFor(r.registries[0]), "themes", themeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortByFirstParty(themes []Theme) []Theme {
|
func SortByFirstParty(themes []Theme) []Theme {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package themes
|
package themes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/registries"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,3 +66,73 @@ func TestLoadThemeWCAGInvalidJSON(t *testing.T) {
|
|||||||
t.Fatalf("expected nil for invalid wcag.json, got %+v", wcag)
|
t.Fatalf("expected nil for invalid wcag.json, got %+v", wcag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type stubGitClient struct {
|
||||||
|
cloneFunc func(path string, url string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stubGitClient) PlainClone(path string, url string) error {
|
||||||
|
if s.cloneFunc != nil {
|
||||||
|
return s.cloneFunc(path, url)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *stubGitClient) Pull(path string) error { return nil }
|
||||||
|
func (s *stubGitClient) OriginURL(path string) (string, error) { return "", os.ErrNotExist }
|
||||||
|
|
||||||
|
func writeTestTheme(t *testing.T, fs afero.Fs, registryDir, themeID, name string) {
|
||||||
|
dir := registryDir + "/themes/" + themeID
|
||||||
|
if err := fs.MkdirAll(dir, 0o755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
themeJSON := `{"id":"` + themeID + `","name":"` + name + `","version":"1.0","author":"a","description":"d"}`
|
||||||
|
if err := afero.WriteFile(fs, dir+"/theme.json", []byte(themeJSON), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateMultiRegistry(t *testing.T) {
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
base := "/test-cache"
|
||||||
|
r := &Registry{
|
||||||
|
fs: fs,
|
||||||
|
cacheDir: base,
|
||||||
|
registries: []registries.Source{
|
||||||
|
{Name: "official", URL: "https://example.com/official.git"},
|
||||||
|
{Name: "extra", URL: "https://example.com/extra.git"},
|
||||||
|
},
|
||||||
|
themes: []Theme{},
|
||||||
|
}
|
||||||
|
r.git = &stubGitClient{
|
||||||
|
cloneFunc: func(path string, url string) error {
|
||||||
|
switch path {
|
||||||
|
case base + "/official":
|
||||||
|
writeTestTheme(t, fs, path, "shared", "OfficialShared")
|
||||||
|
writeTestTheme(t, fs, path, "one", "One")
|
||||||
|
case base + "/extra":
|
||||||
|
writeTestTheme(t, fs, path, "shared", "ExtraShared")
|
||||||
|
writeTestTheme(t, fs, path, "two", "Two")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Update(); err != nil {
|
||||||
|
t.Fatalf("Update: %v", err)
|
||||||
|
}
|
||||||
|
if len(r.themes) != 3 {
|
||||||
|
t.Fatalf("expected 3 themes after dedupe, got %d", len(r.themes))
|
||||||
|
}
|
||||||
|
for _, theme := range r.themes {
|
||||||
|
if theme.ID == "shared" && theme.Name != "OfficialShared" {
|
||||||
|
t.Fatalf("first registry should win for duplicate ID, got %q", theme.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir := r.GetThemeDir("two"); dir != base+"/extra/themes/two" {
|
||||||
|
t.Fatalf("expected theme dir under extra registry, got %q", dir)
|
||||||
|
}
|
||||||
|
if path := r.GetThemeSourcePath("one"); path != base+"/official/themes/one/theme.json" {
|
||||||
|
t.Fatalf("expected theme source under official registry, got %q", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
Submodule dank-qml-common updated: 7cc4564e59...28fde73112
Generated
+3
-3
@@ -3,11 +3,11 @@
|
|||||||
"dank-qml-common": {
|
"dank-qml-common": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1785121997,
|
"lastModified": 1786121412,
|
||||||
"narHash": "sha256-/MslqFCpjxws8DZqipEKCCTBa0m/SCV3+v1NRT6EuvQ=",
|
"narHash": "sha256-XHNpDNfQfjP6nIscd26GK6ydgBdVN5gknYGOVxXBWLw=",
|
||||||
"owner": "AvengeMedia",
|
"owner": "AvengeMedia",
|
||||||
"repo": "dank-qml-common",
|
"repo": "dank-qml-common",
|
||||||
"rev": "7cc4564e5903a2955fe7da76969f20252cacf9bf",
|
"rev": "28fde7311296cbd041e5b704e54a481082b92b18",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@
|
|||||||
inherit version;
|
inherit version;
|
||||||
pname = "dms-shell";
|
pname = "dms-shell";
|
||||||
src = ./core;
|
src = ./core;
|
||||||
vendorHash = "sha256-ZvaOPC92ZFRPqSyLJa2TA9OUKQ3QnWCIMxrnYLGnC58=";
|
vendorHash = "sha256-pjaRyB6E2TZvVd5a4xcdGSRVr9Dg9wEG/5e+HdtZJCg=";
|
||||||
|
|
||||||
subPackages = [ "cmd/dms" ];
|
subPackages = [ "cmd/dms" ];
|
||||||
|
|
||||||
|
|||||||
@@ -271,3 +271,61 @@ function getConflictingBinds(keyCombo, currentAction, allBinds, modKey) {
|
|||||||
}
|
}
|
||||||
return conflicts;
|
return conflicts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function qtKeyFromName(name) {
|
||||||
|
var n = (name || "").toUpperCase();
|
||||||
|
if (n.length === 1 && n >= "A" && n <= "Z")
|
||||||
|
return Qt.Key_A + (n.charCodeAt(0) - 65);
|
||||||
|
if (n.length === 1 && n >= "0" && n <= "9")
|
||||||
|
return Qt.Key_0 + (n.charCodeAt(0) - 48);
|
||||||
|
if (n.length >= 2 && n[0] === "F") {
|
||||||
|
var f = parseInt(n.slice(1), 10);
|
||||||
|
if (f >= 1 && f <= 12)
|
||||||
|
return Qt.Key_F1 + (f - 1);
|
||||||
|
}
|
||||||
|
var named = {
|
||||||
|
"SPACE": Qt.Key_Space,
|
||||||
|
"TAB": Qt.Key_Tab,
|
||||||
|
"RETURN": Qt.Key_Return,
|
||||||
|
"ENTER": Qt.Key_Enter,
|
||||||
|
"BACKSPACE": Qt.Key_Backspace,
|
||||||
|
"DELETE": Qt.Key_Delete,
|
||||||
|
"HOME": Qt.Key_Home,
|
||||||
|
"END": Qt.Key_End,
|
||||||
|
"UP": Qt.Key_Up,
|
||||||
|
"DOWN": Qt.Key_Down,
|
||||||
|
"LEFT": Qt.Key_Left,
|
||||||
|
"RIGHT": Qt.Key_Right
|
||||||
|
};
|
||||||
|
return named[n] || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isModifierKey(qk) {
|
||||||
|
return qk === Qt.Key_Control || qk === Qt.Key_Shift || qk === Qt.Key_Alt || qk === Qt.Key_Meta
|
||||||
|
|| qk === Qt.Key_NumLock || qk === Qt.Key_CapsLock || qk === Qt.Key_ScrollLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
function eventMatchesCombo(event, combo) {
|
||||||
|
if (!combo)
|
||||||
|
return false;
|
||||||
|
var parts = combo.split("+");
|
||||||
|
var keyName = parts[parts.length - 1].trim().toUpperCase();
|
||||||
|
var wantsShift = false;
|
||||||
|
var hasCtrl = false;
|
||||||
|
for (var i = 0; i < parts.length - 1; i++) {
|
||||||
|
var mod = parts[i].trim().toLowerCase();
|
||||||
|
if (mod === "shift")
|
||||||
|
wantsShift = true;
|
||||||
|
else if (mod === "ctrl" || mod === "control")
|
||||||
|
hasCtrl = true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (hasCtrl && !(event.modifiers & Qt.ControlModifier))
|
||||||
|
return false;
|
||||||
|
if (event.modifiers & (Qt.AltModifier | Qt.MetaModifier))
|
||||||
|
return false;
|
||||||
|
if (((event.modifiers & Qt.ShiftModifier) !== 0) !== wantsShift)
|
||||||
|
return false;
|
||||||
|
return event.key === qtKeyFromName(keyName);
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ Singleton {
|
|||||||
function openModal(modal) {
|
function openModal(modal) {
|
||||||
PopoutManager.screenshotActive = false;
|
PopoutManager.screenshotActive = false;
|
||||||
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
||||||
currentModalsByScreen[screenName] = modal;
|
var next = {};
|
||||||
|
for (var k in currentModalsByScreen)
|
||||||
|
next[k] = currentModalsByScreen[k];
|
||||||
|
next[screenName] = modal;
|
||||||
|
currentModalsByScreen = next;
|
||||||
modalChanged();
|
modalChanged();
|
||||||
Qt.callLater(() => {
|
Qt.callLater(() => {
|
||||||
if (!modal.allowStacking)
|
if (!modal.allowStacking)
|
||||||
@@ -34,7 +38,12 @@ Singleton {
|
|||||||
function closeModal(modal) {
|
function closeModal(modal) {
|
||||||
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
||||||
if (currentModalsByScreen[screenName] === modal) {
|
if (currentModalsByScreen[screenName] === modal) {
|
||||||
delete currentModalsByScreen[screenName];
|
var next = {};
|
||||||
|
for (var k in currentModalsByScreen) {
|
||||||
|
if (k !== screenName)
|
||||||
|
next[k] = currentModalsByScreen[k];
|
||||||
|
}
|
||||||
|
currentModalsByScreen = next;
|
||||||
modalChanged();
|
modalChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ Singleton {
|
|||||||
property var includedTransitions: availableWallpaperTransitions.filter(t => t !== "none")
|
property var includedTransitions: availableWallpaperTransitions.filter(t => t !== "none")
|
||||||
|
|
||||||
property bool wallpaperCyclingEnabled: false
|
property bool wallpaperCyclingEnabled: false
|
||||||
|
property bool wallpaperCyclingRandom: false
|
||||||
property string wallpaperCyclingMode: "interval"
|
property string wallpaperCyclingMode: "interval"
|
||||||
property int wallpaperCyclingInterval: 300
|
property int wallpaperCyclingInterval: 300
|
||||||
property string wallpaperCyclingTime: "06:00"
|
property string wallpaperCyclingTime: "06:00"
|
||||||
@@ -646,6 +647,11 @@ Singleton {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setWallpaperCyclingRandom(random) {
|
||||||
|
wallpaperCyclingRandom = random;
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
function setWallpaperCyclingMode(mode) {
|
function setWallpaperCyclingMode(mode) {
|
||||||
wallpaperCyclingMode = mode;
|
wallpaperCyclingMode = mode;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
@@ -692,6 +698,37 @@ Singleton {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMonitorCyclingRandom(screenName, random) {
|
||||||
|
var screen = null;
|
||||||
|
var screens = Quickshell.screens;
|
||||||
|
for (var i = 0; i < screens.length; i++) {
|
||||||
|
if (screens[i].name === screenName) {
|
||||||
|
screen = screens[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!screen) {
|
||||||
|
log.warn("Screen not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var identifier = typeof SettingsData !== "undefined" ? SettingsData.getScreenDisplayName(screen) : screen.name;
|
||||||
|
|
||||||
|
var newSettings = {};
|
||||||
|
for (var key in monitorCyclingSettings) {
|
||||||
|
var isThisScreen = key === screen.name || (screen.model && key === screen.model);
|
||||||
|
if (!isThisScreen) {
|
||||||
|
newSettings[key] = monitorCyclingSettings[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newSettings[identifier] = getMonitorCyclingSettings(screenName);
|
||||||
|
newSettings[identifier].random = random;
|
||||||
|
monitorCyclingSettings = newSettings;
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
function setMonitorCyclingMode(screenName, mode) {
|
function setMonitorCyclingMode(screenName, mode) {
|
||||||
var screen = null;
|
var screen = null;
|
||||||
var screens = Quickshell.screens;
|
var screens = Quickshell.screens;
|
||||||
@@ -1322,6 +1359,7 @@ Singleton {
|
|||||||
function getMonitorCyclingSettings(screenName) {
|
function getMonitorCyclingSettings(screenName) {
|
||||||
var defaults = {
|
var defaults = {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
|
"random": false,
|
||||||
"mode": "interval",
|
"mode": "interval",
|
||||||
"interval": 300,
|
"interval": 300,
|
||||||
"time": "06:00"
|
"time": "06:00"
|
||||||
|
|||||||
@@ -164,6 +164,11 @@ Singleton {
|
|||||||
property string matugenTargetMonitor: ""
|
property string matugenTargetMonitor: ""
|
||||||
property real popupTransparency: 1.0
|
property real popupTransparency: 1.0
|
||||||
property real dockTransparency: 1
|
property real dockTransparency: 1
|
||||||
|
property bool floatingWindowSyncGlobal: true
|
||||||
|
property real floatingWindowTransparency: 1.0
|
||||||
|
property bool floatingWindowForegroundLayers: true
|
||||||
|
property real floatingWindowForegroundTransparency: 1.0
|
||||||
|
property bool dmsWindowsFloating: true
|
||||||
property string widgetBackgroundColor: "sch"
|
property string widgetBackgroundColor: "sch"
|
||||||
property string widgetBackgroundCustomColor: "#6750A4"
|
property string widgetBackgroundCustomColor: "#6750A4"
|
||||||
property real widgetBackgroundCustomStrength: 0.50
|
property real widgetBackgroundCustomStrength: 0.50
|
||||||
@@ -203,6 +208,16 @@ Singleton {
|
|||||||
property bool touchpadTapAndDrag: true
|
property bool touchpadTapAndDrag: true
|
||||||
property bool touchpadTapToClick: true
|
property bool touchpadTapToClick: true
|
||||||
|
|
||||||
|
property string keyboardLayouts: ""
|
||||||
|
property string keyboardVariants: ""
|
||||||
|
property string keyboardModel: ""
|
||||||
|
property string keyboardOptions: ""
|
||||||
|
property string keyboardKeymapFile: ""
|
||||||
|
property string keyboardTrackLayout: ""
|
||||||
|
property int keyboardRepeatDelay: 0
|
||||||
|
property int keyboardRepeatRate: 0
|
||||||
|
property bool keyboardNumlock: false
|
||||||
|
|
||||||
property int firstDayOfWeek: -1
|
property int firstDayOfWeek: -1
|
||||||
property bool showWeekNumber: false
|
property bool showWeekNumber: false
|
||||||
property string calendarBackend: "auto"
|
property string calendarBackend: "auto"
|
||||||
@@ -254,6 +269,7 @@ Singleton {
|
|||||||
onBlurEnabledChanged: saveSettings()
|
onBlurEnabledChanged: saveSettings()
|
||||||
property bool blurForegroundLayers: true
|
property bool blurForegroundLayers: true
|
||||||
onBlurForegroundLayersChanged: saveSettings()
|
onBlurForegroundLayersChanged: saveSettings()
|
||||||
|
property real foregroundLayerTransparency: 1.0
|
||||||
property real blurLayerOutlineOpacity: 0.12
|
property real blurLayerOutlineOpacity: 0.12
|
||||||
onBlurLayerOutlineOpacityChanged: saveSettings()
|
onBlurLayerOutlineOpacityChanged: saveSettings()
|
||||||
property bool blurBorderEnabled: true
|
property bool blurBorderEnabled: true
|
||||||
@@ -479,6 +495,7 @@ Singleton {
|
|||||||
property bool mediaAdaptiveWidthEnabled: true
|
property bool mediaAdaptiveWidthEnabled: true
|
||||||
property bool audioVisualizerEnabled: true
|
property bool audioVisualizerEnabled: true
|
||||||
property bool mediaUseAlbumArtAccent: false
|
property bool mediaUseAlbumArtAccent: false
|
||||||
|
property bool appleMusicAnimatedArtEnabled: false
|
||||||
property string audioScrollMode: "volume"
|
property string audioScrollMode: "volume"
|
||||||
property int audioWheelScrollAmount: 5
|
property int audioWheelScrollAmount: 5
|
||||||
property bool audioDeviceScrollVolumeEnabled: false
|
property bool audioDeviceScrollVolumeEnabled: false
|
||||||
@@ -659,9 +676,6 @@ Singleton {
|
|||||||
readonly property string iconTheme: resolveIconTheme()
|
readonly property string iconTheme: resolveIconTheme()
|
||||||
property var availableIconThemes: ["System Default"]
|
property var availableIconThemes: ["System Default"]
|
||||||
property string systemDefaultIconTheme: ""
|
property string systemDefaultIconTheme: ""
|
||||||
property bool qt5ctAvailable: false
|
|
||||||
property bool qt6ctAvailable: false
|
|
||||||
property bool gtkAvailable: false
|
|
||||||
|
|
||||||
property var cursorSettings: ({
|
property var cursorSettings: ({
|
||||||
"theme": "System Default",
|
"theme": "System Default",
|
||||||
@@ -798,8 +812,6 @@ Singleton {
|
|||||||
property int fadeToDpmsGracePeriod: 5
|
property int fadeToDpmsGracePeriod: 5
|
||||||
property string launchPrefix: ""
|
property string launchPrefix: ""
|
||||||
|
|
||||||
property bool gtkThemingEnabled: false
|
|
||||||
property bool qtThemingEnabled: false
|
|
||||||
property bool syncModeWithPortal: true
|
property bool syncModeWithPortal: true
|
||||||
property bool terminalsAlwaysDark: false
|
property bool terminalsAlwaysDark: false
|
||||||
|
|
||||||
@@ -922,6 +934,8 @@ Singleton {
|
|||||||
property bool lockPamInlineU2f: false
|
property bool lockPamInlineU2f: false
|
||||||
property bool lockPamExternallyManaged: false
|
property bool lockPamExternallyManaged: false
|
||||||
property string lockU2fPamPath: ""
|
property string lockU2fPamPath: ""
|
||||||
|
property string lockScreenSecurityKeyShortcut: "Ctrl+Q"
|
||||||
|
property bool lockScreenSecurityKeyShortcutEnabled: false
|
||||||
property bool greeterPamExternallyManaged: false
|
property bool greeterPamExternallyManaged: false
|
||||||
property string lockScreenInactiveColor: "#000000"
|
property string lockScreenInactiveColor: "#000000"
|
||||||
property int lockScreenNotificationMode: 0
|
property int lockScreenNotificationMode: 0
|
||||||
@@ -976,6 +990,7 @@ Singleton {
|
|||||||
property string customPowerActionHibernate: ""
|
property string customPowerActionHibernate: ""
|
||||||
property string customPowerActionReboot: ""
|
property string customPowerActionReboot: ""
|
||||||
property string customPowerActionPowerOff: ""
|
property string customPowerActionPowerOff: ""
|
||||||
|
property var customPowerButtons: []
|
||||||
|
|
||||||
property bool updaterHideWidget: false
|
property bool updaterHideWidget: false
|
||||||
property bool updaterCheckOnStart: false
|
property bool updaterCheckOnStart: false
|
||||||
@@ -1683,7 +1698,6 @@ Singleton {
|
|||||||
_hasLoaded = true;
|
_hasLoaded = true;
|
||||||
applyStoredTheme();
|
applyStoredTheme();
|
||||||
updateCompositorCursor();
|
updateCompositorCursor();
|
||||||
Processes.detectQtTools();
|
|
||||||
Qt.callLater(checkIconThemeDrift);
|
Qt.callLater(checkIconThemeDrift);
|
||||||
|
|
||||||
_checkSettingsWritable();
|
_checkSettingsWritable();
|
||||||
@@ -2556,11 +2570,19 @@ Singleton {
|
|||||||
return edges;
|
return edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
function frameEdgeInsetForSide(screen, side) {
|
readonly property real frameBarContentGap: frameBarInsetPadding < 0 ? frameThickness : frameBarInsetPadding
|
||||||
if (!frameEnabled || !screen)
|
readonly property real frameBarContentGapExtra: Math.max(0, frameBarContentGap - frameThickness)
|
||||||
|
|
||||||
|
function frameEdgeReservation(screen, edge) {
|
||||||
|
if (!screen)
|
||||||
return 0;
|
return 0;
|
||||||
const edges = getActiveBarEdgesForScreen(screen);
|
return getActiveBarEdgesForScreen(screen).includes(edge) ? frameBarSize : frameThickness;
|
||||||
return edges.includes(side) ? frameBarSize : frameThickness;
|
}
|
||||||
|
|
||||||
|
function frameEdgeInsetForSide(screen, side) {
|
||||||
|
if (!frameEnabled)
|
||||||
|
return 0;
|
||||||
|
return frameEdgeReservation(screen, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMatugenScheme(scheme) {
|
function setMatugenScheme(scheme) {
|
||||||
|
|||||||
@@ -96,8 +96,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
property bool matugenAvailable: false
|
property bool matugenAvailable: false
|
||||||
property bool gtkThemingEnabled: typeof SettingsData !== "undefined" ? SettingsData.gtkAvailable : false
|
|
||||||
property bool qtThemingEnabled: typeof SettingsData !== "undefined" ? (SettingsData.qt5ctAvailable || SettingsData.qt6ctAvailable) : false
|
|
||||||
property var workerRunning: false
|
property var workerRunning: false
|
||||||
property var pendingThemeRequest: null
|
property var pendingThemeRequest: null
|
||||||
|
|
||||||
@@ -347,11 +345,28 @@ Singleton {
|
|||||||
readonly property bool foregroundLayers: typeof SettingsData === "undefined" || (SettingsData.blurForegroundLayers ?? true)
|
readonly property bool foregroundLayers: typeof SettingsData === "undefined" || (SettingsData.blurForegroundLayers ?? true)
|
||||||
readonly property bool blurForegroundLayers: blurLayersActive && foregroundLayers
|
readonly property bool blurForegroundLayers: blurLayersActive && foregroundLayers
|
||||||
readonly property bool transparentBlurLayers: blurLayersActive && !foregroundLayers
|
readonly property bool transparentBlurLayers: blurLayersActive && !foregroundLayers
|
||||||
|
readonly property real foregroundLayerTransparency: typeof SettingsData === "undefined" ? 1.0 : (SettingsData.foregroundLayerTransparency ?? 1.0)
|
||||||
readonly property bool notificationForegroundLayers: typeof SettingsData === "undefined" || (SettingsData.notificationForegroundLayers ?? true)
|
readonly property bool notificationForegroundLayers: typeof SettingsData === "undefined" || (SettingsData.notificationForegroundLayers ?? true)
|
||||||
readonly property color readableSurface: withAlpha(surfaceContainer, popupTransparency)
|
readonly property color readableSurface: withAlpha(surfaceContainer, popupTransparency)
|
||||||
readonly property color readableSurfaceHigh: withAlpha(surfaceContainerHigh, popupTransparency)
|
readonly property color readableSurfaceHigh: withAlpha(surfaceContainerHigh, popupTransparency)
|
||||||
readonly property color floatingSurface: foregroundLayers ? readableSurface : withAlpha(readableSurface, 0)
|
readonly property color floatingSurface: foregroundLayers ? readableSurface : withAlpha(readableSurface, 0)
|
||||||
readonly property color floatingSurfaceHigh: foregroundLayers ? readableSurfaceHigh : withAlpha(readableSurfaceHigh, 0)
|
readonly property color floatingSurfaceHigh: foregroundLayers ? withAlpha(surfaceContainerHigh, foregroundLayerTransparency) : withAlpha(surfaceContainerHigh, 0)
|
||||||
|
readonly property bool floatingWindowSynced: typeof SettingsData === "undefined" || (SettingsData.floatingWindowSyncGlobal ?? true)
|
||||||
|
readonly property real floatingWindowTransparency: {
|
||||||
|
if (typeof SettingsData === "undefined" || floatingWindowSynced)
|
||||||
|
return popupTransparency;
|
||||||
|
return SettingsData.floatingWindowTransparency ?? 1.0;
|
||||||
|
}
|
||||||
|
readonly property bool floatingWindowForegroundLayers: floatingWindowSynced ? foregroundLayers : (SettingsData.floatingWindowForegroundLayers ?? true)
|
||||||
|
readonly property real floatingWindowForegroundTransparency: {
|
||||||
|
if (typeof SettingsData === "undefined" || floatingWindowSynced)
|
||||||
|
return foregroundLayerTransparency;
|
||||||
|
return SettingsData.floatingWindowForegroundTransparency ?? 1.0;
|
||||||
|
}
|
||||||
|
readonly property color floatingWindowSurface: withAlpha(surfaceContainer, floatingWindowTransparency)
|
||||||
|
readonly property color floatingWindowSurfaceHigh: floatingWindowForegroundLayers ? withAlpha(surfaceContainerHigh, floatingWindowForegroundTransparency) : withAlpha(surfaceContainerHigh, 0)
|
||||||
|
readonly property color floatingWindowNestedSurface: floatingWindowSurfaceHigh
|
||||||
|
readonly property color notepadWindowSurface: withAlpha(surfaceContainer, notepadTransparency)
|
||||||
readonly property color nestedSurface: floatingSurfaceHigh
|
readonly property color nestedSurface: floatingSurfaceHigh
|
||||||
readonly property color notificationFloatingSurface: notificationForegroundLayers ? readableSurface : withAlpha(readableSurface, 0)
|
readonly property color notificationFloatingSurface: notificationForegroundLayers ? readableSurface : withAlpha(readableSurface, 0)
|
||||||
readonly property color notificationFloatingSurfaceHigh: notificationForegroundLayers ? readableSurfaceHigh : withAlpha(readableSurfaceHigh, 0)
|
readonly property color notificationFloatingSurfaceHigh: notificationForegroundLayers ? readableSurfaceHigh : withAlpha(readableSurfaceHigh, 0)
|
||||||
@@ -359,6 +374,20 @@ Singleton {
|
|||||||
readonly property real blurLayerOutlineOpacity: Math.max(0, Math.min(1, typeof SettingsData === "undefined" ? 0.12 : (SettingsData.blurLayerOutlineOpacity ?? 0.12)))
|
readonly property real blurLayerOutlineOpacity: Math.max(0, Math.min(1, typeof SettingsData === "undefined" ? 0.12 : (SettingsData.blurLayerOutlineOpacity ?? 0.12)))
|
||||||
readonly property real layerOutlineOpacity: blurLayerOutlineOpacity
|
readonly property real layerOutlineOpacity: blurLayerOutlineOpacity
|
||||||
readonly property int layerOutlineWidth: layerOutlineOpacity > 0 ? 1 : 0
|
readonly property int layerOutlineWidth: layerOutlineOpacity > 0 ? 1 : 0
|
||||||
|
readonly property real floatingWindowFieldAlpha: floatingWindowTransparency
|
||||||
|
readonly property color floatingWindowFieldColor: withAlpha(surfaceContainerHigh, floatingWindowFieldAlpha)
|
||||||
|
readonly property real popupFieldAlpha: {
|
||||||
|
if (transparentBlurLayers)
|
||||||
|
return 0.28;
|
||||||
|
if (blurForegroundLayers)
|
||||||
|
return Math.max(foregroundLayerTransparency, 0.62);
|
||||||
|
return popupTransparency;
|
||||||
|
}
|
||||||
|
readonly property color popupFieldColor: withAlpha(surfaceContainerHigh, popupFieldAlpha)
|
||||||
|
readonly property color popupFieldBorderColor: withAlpha(outline, blurLayersActive ? 0.16 : layerOutlineOpacity)
|
||||||
|
readonly property color popupFieldFocusedBorderColor: withAlpha(primary, blurLayersActive ? 0.72 : 1.0)
|
||||||
|
readonly property color floatingWindowFieldBorderColor: popupFieldBorderColor
|
||||||
|
readonly property color floatingWindowFieldFocusedBorderColor: popupFieldFocusedBorderColor
|
||||||
property color surfaceTextHover: withAlpha(surfaceText, 0.08)
|
property color surfaceTextHover: withAlpha(surfaceText, 0.08)
|
||||||
property color surfaceTextAlpha: withAlpha(surfaceText, 0.3)
|
property color surfaceTextAlpha: withAlpha(surfaceText, 0.3)
|
||||||
|
|
||||||
@@ -1196,7 +1225,7 @@ Singleton {
|
|||||||
readonly property var _availableThemeNames: StockThemes.getAllThemeNames()
|
readonly property var _availableThemeNames: StockThemes.getAllThemeNames()
|
||||||
property string currentThemeName: currentTheme
|
property string currentThemeName: currentTheme
|
||||||
|
|
||||||
property real notepadTransparency: SettingsData.notepadTransparencyOverride >= 0 ? SettingsData.notepadTransparencyOverride : popupTransparency
|
property real notepadTransparency: SettingsData.notepadTransparencyOverride >= 0 ? SettingsData.notepadTransparencyOverride : floatingWindowTransparency
|
||||||
|
|
||||||
property bool widgetBackgroundHasAlpha: {
|
property bool widgetBackgroundHasAlpha: {
|
||||||
const colorMode = typeof SettingsData !== "undefined" ? SettingsData.widgetBackgroundColor : "sch";
|
const colorMode = typeof SettingsData !== "undefined" ? SettingsData.widgetBackgroundColor : "sch";
|
||||||
|
|||||||
@@ -1,31 +1,69 @@
|
|||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Services.SystemTray
|
||||||
import QtQuick
|
import QtQuick
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property var activeTrayMenus: ({})
|
property var activeTrayMenus: ({})
|
||||||
|
property var _pendingMenuRequest: null
|
||||||
|
|
||||||
|
signal openTrayMenuRequested
|
||||||
|
|
||||||
|
function requestOpenMenu(itemId, screenName) {
|
||||||
|
_pendingMenuRequest = {
|
||||||
|
"itemId": itemId,
|
||||||
|
"screenName": screenName
|
||||||
|
};
|
||||||
|
openTrayMenuRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every SystemTrayBar instance receives the signal; the claim ensures
|
||||||
|
// exactly one opens the menu, preferring the requested screen
|
||||||
|
function claimMenuRequest(instanceScreenName) {
|
||||||
|
if (!_pendingMenuRequest)
|
||||||
|
return null;
|
||||||
|
if (_pendingMenuRequest.screenName && _pendingMenuRequest.screenName !== instanceScreenName)
|
||||||
|
return null;
|
||||||
|
const request = _pendingMenuRequest;
|
||||||
|
_pendingMenuRequest = null;
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findTrayItem(itemId: string): var {
|
||||||
|
if (!itemId)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return SystemTray.items.values.find(item => {
|
||||||
|
const id = item?.id || "";
|
||||||
|
const title = item?.tooltipTitle || "";
|
||||||
|
const fullKey = title ? `${id}::${title}` : id;
|
||||||
|
return fullKey === itemId || id === itemId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function registerMenu(screenName, menu) {
|
function registerMenu(screenName, menu) {
|
||||||
if (!screenName || !menu) return
|
if (!screenName || !menu)
|
||||||
const newMenus = Object.assign({}, activeTrayMenus)
|
return;
|
||||||
newMenus[screenName] = menu
|
const newMenus = Object.assign({}, activeTrayMenus);
|
||||||
activeTrayMenus = newMenus
|
newMenus[screenName] = menu;
|
||||||
|
activeTrayMenus = newMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unregisterMenu(screenName) {
|
function unregisterMenu(screenName) {
|
||||||
if (!screenName) return
|
if (!screenName)
|
||||||
const newMenus = Object.assign({}, activeTrayMenus)
|
return;
|
||||||
delete newMenus[screenName]
|
const newMenus = Object.assign({}, activeTrayMenus);
|
||||||
activeTrayMenus = newMenus
|
delete newMenus[screenName];
|
||||||
|
activeTrayMenus = newMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeAllMenus() {
|
function closeHoverMenus() {
|
||||||
for (const screenName in activeTrayMenus) {
|
for (const screenName in activeTrayMenus) {
|
||||||
const menu = activeTrayMenus[screenName]
|
const menu = activeTrayMenus[screenName]
|
||||||
if (!menu) continue
|
if (!menu || menu.openedByHover !== true) continue
|
||||||
if (typeof menu.close === "function") {
|
if (typeof menu.close === "function") {
|
||||||
menu.close()
|
menu.close()
|
||||||
} else if (menu.showMenu !== undefined) {
|
} else if (menu.showMenu !== undefined) {
|
||||||
@@ -33,4 +71,17 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeAllMenus() {
|
||||||
|
for (const screenName in activeTrayMenus) {
|
||||||
|
const menu = activeTrayMenus[screenName];
|
||||||
|
if (!menu)
|
||||||
|
continue;
|
||||||
|
if (typeof menu.close === "function") {
|
||||||
|
menu.close();
|
||||||
|
} else if (menu.showMenu !== undefined) {
|
||||||
|
menu.showMenu = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -487,41 +487,10 @@ Singleton {
|
|||||||
return pamFprintDetected ? "probe_failed" : "missing_pam_support";
|
return pamFprintDetected ? "probe_failed" : "missing_pam_support";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Qt tools detection ---
|
|
||||||
|
|
||||||
function detectQtTools() {
|
|
||||||
qtToolsDetectionProcess.running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkPluginSettings() {
|
function checkPluginSettings() {
|
||||||
pluginSettingsCheckProcess.running = true;
|
pluginSettingsCheckProcess.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
property var qtToolsDetectionProcess: Process {
|
|
||||||
command: ["sh", "-c", "echo -n 'qt5ct:'; command -v qt5ct >/dev/null && echo 'true' || echo 'false'; echo -n 'qt6ct:'; command -v qt6ct >/dev/null && echo 'true' || echo 'false'; echo -n 'gtk:'; (command -v gsettings >/dev/null || command -v dconf >/dev/null) && echo 'true' || echo 'false'"]
|
|
||||||
running: false
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
if (!settingsRoot)
|
|
||||||
return;
|
|
||||||
if (text && text.trim()) {
|
|
||||||
const lines = text.trim().split("\n");
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
const line = lines[i];
|
|
||||||
if (line.startsWith("qt5ct:")) {
|
|
||||||
settingsRoot.qt5ctAvailable = line.split(":")[1] === "true";
|
|
||||||
} else if (line.startsWith("qt6ct:")) {
|
|
||||||
settingsRoot.qt6ctAvailable = line.split(":")[1] === "true";
|
|
||||||
} else if (line.startsWith("gtk:")) {
|
|
||||||
settingsRoot.gtkAvailable = line.split(":")[1] === "true";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: authApplyDebounce
|
id: authApplyDebounce
|
||||||
interval: 300
|
interval: 300
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ var SPEC = {
|
|||||||
includedTransitions: { def: ["fade", "wipe", "disc", "stripes", "iris bloom", "pixelate", "portal"] },
|
includedTransitions: { def: ["fade", "wipe", "disc", "stripes", "iris bloom", "pixelate", "portal"] },
|
||||||
|
|
||||||
wallpaperCyclingEnabled: { def: false },
|
wallpaperCyclingEnabled: { def: false },
|
||||||
|
wallpaperCyclingRandom: { def: false },
|
||||||
wallpaperCyclingMode: { def: "interval" },
|
wallpaperCyclingMode: { def: "interval" },
|
||||||
wallpaperCyclingInterval: { def: 300 },
|
wallpaperCyclingInterval: { def: 300 },
|
||||||
wallpaperCyclingTime: { def: "06:00" },
|
wallpaperCyclingTime: { def: "06:00" },
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ var SPEC = {
|
|||||||
|
|
||||||
popupTransparency: { def: 1.0, coerce: percentToUnit },
|
popupTransparency: { def: 1.0, coerce: percentToUnit },
|
||||||
dockTransparency: { def: 1.0, coerce: percentToUnit },
|
dockTransparency: { def: 1.0, coerce: percentToUnit },
|
||||||
|
floatingWindowSyncGlobal: { def: true },
|
||||||
|
floatingWindowTransparency: { def: 1.0, coerce: percentToUnit },
|
||||||
|
floatingWindowForegroundLayers: { def: true },
|
||||||
|
floatingWindowForegroundTransparency: { def: 1.0, coerce: percentToUnit },
|
||||||
|
dmsWindowsFloating: { def: true },
|
||||||
|
|
||||||
widgetBackgroundColor: { def: "sch" },
|
widgetBackgroundColor: { def: "sch" },
|
||||||
widgetBackgroundCustomColor: { def: "#6750A4" },
|
widgetBackgroundCustomColor: { def: "#6750A4" },
|
||||||
@@ -57,6 +62,16 @@ var SPEC = {
|
|||||||
touchpadTapAndDrag: { def: true, onChange: "updateCompositorInput" },
|
touchpadTapAndDrag: { def: true, onChange: "updateCompositorInput" },
|
||||||
touchpadTapToClick: { def: true, onChange: "updateCompositorInput" },
|
touchpadTapToClick: { def: true, onChange: "updateCompositorInput" },
|
||||||
|
|
||||||
|
keyboardLayouts: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardVariants: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardModel: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardOptions: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardKeymapFile: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardTrackLayout: { def: "", onChange: "updateCompositorInput" },
|
||||||
|
keyboardRepeatDelay: { def: 0, onChange: "updateCompositorInput" },
|
||||||
|
keyboardRepeatRate: { def: 0, onChange: "updateCompositorInput" },
|
||||||
|
keyboardNumlock: { def: false, onChange: "updateCompositorInput" },
|
||||||
|
|
||||||
firstDayOfWeek: { def: -1 },
|
firstDayOfWeek: { def: -1 },
|
||||||
showWeekNumber: { def: false },
|
showWeekNumber: { def: false },
|
||||||
calendarBackend: { def: "auto" },
|
calendarBackend: { def: "auto" },
|
||||||
@@ -87,6 +102,7 @@ var SPEC = {
|
|||||||
barElevationEnabled: { def: true },
|
barElevationEnabled: { def: true },
|
||||||
blurEnabled: { def: false },
|
blurEnabled: { def: false },
|
||||||
blurForegroundLayers: { def: true },
|
blurForegroundLayers: { def: true },
|
||||||
|
foregroundLayerTransparency: { def: 1.0, coerce: percentToUnit },
|
||||||
blurLayerOutlineOpacity: { def: 0.12, coerce: percentToUnit },
|
blurLayerOutlineOpacity: { def: 0.12, coerce: percentToUnit },
|
||||||
blurBorderEnabled: { def: true },
|
blurBorderEnabled: { def: true },
|
||||||
blurBorderColor: { def: "outline" },
|
blurBorderColor: { def: "outline" },
|
||||||
@@ -205,6 +221,7 @@ var SPEC = {
|
|||||||
mediaAdaptiveWidthEnabled: { def: true },
|
mediaAdaptiveWidthEnabled: { def: true },
|
||||||
audioVisualizerEnabled: { def: true },
|
audioVisualizerEnabled: { def: true },
|
||||||
mediaUseAlbumArtAccent: { def: false },
|
mediaUseAlbumArtAccent: { def: false },
|
||||||
|
appleMusicAnimatedArtEnabled: { def: false },
|
||||||
audioScrollMode: { def: "volume" },
|
audioScrollMode: { def: "volume" },
|
||||||
audioWheelScrollAmount: { def: 5 },
|
audioWheelScrollAmount: { def: 5 },
|
||||||
audioDeviceScrollVolumeEnabled: { def: false },
|
audioDeviceScrollVolumeEnabled: { def: false },
|
||||||
@@ -298,9 +315,6 @@ var SPEC = {
|
|||||||
lastAppliedIconTheme: { def: "" },
|
lastAppliedIconTheme: { def: "" },
|
||||||
availableIconThemes: { def: ["System Default"], persist: false },
|
availableIconThemes: { def: ["System Default"], persist: false },
|
||||||
systemDefaultIconTheme: { def: "", persist: false },
|
systemDefaultIconTheme: { def: "", persist: false },
|
||||||
qt5ctAvailable: { def: false, persist: false },
|
|
||||||
qt6ctAvailable: { def: false, persist: false },
|
|
||||||
gtkAvailable: { def: false, persist: false },
|
|
||||||
|
|
||||||
cursorSettings: { def: { theme: "System Default", size: 24, niri: { hideWhenTyping: false, hideAfterInactiveMs: 0 }, hyprland: { hideOnKeyPress: false, hideOnTouch: false, inactiveTimeout: 0 }, dwl: { cursorHideTimeout: 0 }, mango: { cursorHideTimeout: 0 } }, onChange: "updateCompositorCursor" },
|
cursorSettings: { def: { theme: "System Default", size: 24, niri: { hideWhenTyping: false, hideAfterInactiveMs: 0 }, hyprland: { hideOnKeyPress: false, hideOnTouch: false, inactiveTimeout: 0 }, dwl: { cursorHideTimeout: 0 }, mango: { cursorHideTimeout: 0 } }, onChange: "updateCompositorCursor" },
|
||||||
availableCursorThemes: { def: ["System Default"], persist: false },
|
availableCursorThemes: { def: ["System Default"], persist: false },
|
||||||
@@ -374,8 +388,6 @@ var SPEC = {
|
|||||||
fadeToDpmsGracePeriod: { def: 5 },
|
fadeToDpmsGracePeriod: { def: 5 },
|
||||||
launchPrefix: { def: "" },
|
launchPrefix: { def: "" },
|
||||||
|
|
||||||
gtkThemingEnabled: { def: false, onChange: "regenSystemThemes" },
|
|
||||||
qtThemingEnabled: { def: false, onChange: "regenSystemThemes" },
|
|
||||||
syncModeWithPortal: { def: true },
|
syncModeWithPortal: { def: true },
|
||||||
terminalsAlwaysDark: { def: false, onChange: "regenSystemThemes" },
|
terminalsAlwaysDark: { def: false, onChange: "regenSystemThemes" },
|
||||||
|
|
||||||
@@ -473,6 +485,8 @@ var SPEC = {
|
|||||||
enableU2f: { def: false, onChange: "scheduleAuthApply" },
|
enableU2f: { def: false, onChange: "scheduleAuthApply" },
|
||||||
u2fMode: { def: "or" },
|
u2fMode: { def: "or" },
|
||||||
lockPamPath: { def: "" },
|
lockPamPath: { def: "" },
|
||||||
|
lockScreenSecurityKeyShortcut: { def: "Ctrl+Q" },
|
||||||
|
lockScreenSecurityKeyShortcutEnabled: { def: false },
|
||||||
lockPamInlineFprint: { def: false },
|
lockPamInlineFprint: { def: false },
|
||||||
lockPamInlineU2f: { def: false },
|
lockPamInlineU2f: { def: false },
|
||||||
lockPamExternallyManaged: { def: false },
|
lockPamExternallyManaged: { def: false },
|
||||||
@@ -529,6 +543,7 @@ var SPEC = {
|
|||||||
customPowerActionHibernate: { def: "" },
|
customPowerActionHibernate: { def: "" },
|
||||||
customPowerActionReboot: { def: "" },
|
customPowerActionReboot: { def: "" },
|
||||||
customPowerActionPowerOff: { def: "" },
|
customPowerActionPowerOff: { def: "" },
|
||||||
|
customPowerButtons: { def: [] },
|
||||||
|
|
||||||
updaterHideWidget: { def: false },
|
updaterHideWidget: { def: false },
|
||||||
updaterCheckOnStart: { def: false },
|
updaterCheckOnStart: { def: false },
|
||||||
|
|||||||
+22
-1
@@ -445,6 +445,23 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LazyLoader {
|
||||||
|
id: qrGeneratorModalLoader
|
||||||
|
active: false
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
PopoutService.qrGeneratorModalLoader = qrGeneratorModalLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRGeneratorModal {
|
||||||
|
id: qrGeneratorModalItem
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
PopoutService.qrGeneratorModal = qrGeneratorModalItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LazyLoader {
|
LazyLoader {
|
||||||
id: polkitAuthModalLoader
|
id: polkitAuthModalLoader
|
||||||
active: false
|
active: false
|
||||||
@@ -618,7 +635,7 @@ Item {
|
|||||||
if (visible) {
|
if (visible) {
|
||||||
wasShown = true;
|
wasShown = true;
|
||||||
} else if (wasShown) {
|
} else if (wasShown) {
|
||||||
PopoutService.unloadSettings();
|
Qt.callLater(() => PopoutService.unloadSettingsNow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -923,6 +940,7 @@ Item {
|
|||||||
expandedWidthValue: 960
|
expandedWidthValue: 960
|
||||||
edgeGap: SettingsData.notepadEffectiveEdgeGap
|
edgeGap: SettingsData.notepadEffectiveEdgeGap
|
||||||
slideEdge: SettingsData.notepadSlideoutSide
|
slideEdge: SettingsData.notepadSlideoutSide
|
||||||
|
customTransparency: Theme.notepadTransparency
|
||||||
|
|
||||||
onIsVisibleChanged: {
|
onIsVisibleChanged: {
|
||||||
if (isVisible)
|
if (isVisible)
|
||||||
@@ -998,6 +1016,9 @@ Item {
|
|||||||
case "reboot":
|
case "reboot":
|
||||||
SessionService.reboot();
|
SessionService.reboot();
|
||||||
break;
|
break;
|
||||||
|
case "softreboot":
|
||||||
|
SessionService.softReboot();
|
||||||
|
break;
|
||||||
case "poweroff":
|
case "poweroff":
|
||||||
SessionService.poweroff();
|
SessionService.poweroff();
|
||||||
break;
|
break;
|
||||||
|
|||||||
+31
-33
@@ -25,32 +25,30 @@ Item {
|
|||||||
required property var windowRuleModalLoader
|
required property var windowRuleModalLoader
|
||||||
|
|
||||||
function getPreferredBar(refPropertyName) {
|
function getPreferredBar(refPropertyName) {
|
||||||
if (!root.dankBarRepeater || root.dankBarRepeater.count === 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
const focusedScreenName = BarWidgetService.getFocusedScreenName();
|
const focusedScreenName = BarWidgetService.getFocusedScreenName();
|
||||||
|
|
||||||
const loaders = Array.from({
|
const bars = [];
|
||||||
length: root.dankBarRepeater.count
|
if (root.dankBarRepeater) {
|
||||||
}, (_, i) => root.dankBarRepeater.itemAt(i));
|
for (let i = 0; i < root.dankBarRepeater.count; i++)
|
||||||
|
bars.push(...(root.dankBarRepeater.itemAt(i)?.item?.barVariants?.instances || []));
|
||||||
|
}
|
||||||
|
const frameBars = BarWidgetService.frameHostedBars;
|
||||||
|
for (const screenName in frameBars)
|
||||||
|
bars.push(frameBars[screenName]);
|
||||||
|
|
||||||
let currentBar = null;
|
let currentBar = null;
|
||||||
|
for (const bar of bars) {
|
||||||
|
if (!bar)
|
||||||
|
continue;
|
||||||
|
|
||||||
for (const loader of loaders) {
|
const onFocusedScreen = focusedScreenName && bar.modelData?.name === focusedScreenName;
|
||||||
const instances = loader?.item?.barVariants?.instances || [];
|
const hasRef = !refPropertyName || !!bar[refPropertyName];
|
||||||
for (const bar of instances) {
|
|
||||||
if (!bar)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const onFocusedScreen = focusedScreenName && bar.modelData?.name === focusedScreenName;
|
if (hasRef) {
|
||||||
const hasRef = !refPropertyName || !!bar[refPropertyName];
|
currentBar = bar;
|
||||||
|
|
||||||
if (hasRef) {
|
if (onFocusedScreen)
|
||||||
currentBar = bar;
|
break;
|
||||||
|
|
||||||
if (onFocusedScreen)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2025,18 +2023,6 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function findTrayItem(itemId: string): var {
|
|
||||||
if (!itemId)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return SystemTray.items.values.find(item => {
|
|
||||||
const id = item?.id || "";
|
|
||||||
const title = item?.tooltipTitle || "";
|
|
||||||
const fullKey = title ? `${id}::${title}` : id;
|
|
||||||
return fullKey === itemId || id === itemId;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function list(): string {
|
function list(): string {
|
||||||
const items = SystemTray.items.values;
|
const items = SystemTray.items.values;
|
||||||
if (items.length === 0)
|
if (items.length === 0)
|
||||||
@@ -2052,7 +2038,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function activate(itemId: string): string {
|
function activate(itemId: string): string {
|
||||||
const item = findTrayItem(itemId);
|
const item = TrayMenuManager.findTrayItem(itemId);
|
||||||
if (!item)
|
if (!item)
|
||||||
return `ERROR: Tray item not found: ${itemId}`;
|
return `ERROR: Tray item not found: ${itemId}`;
|
||||||
|
|
||||||
@@ -2060,8 +2046,20 @@ Item {
|
|||||||
return `SUCCESS: Activated ${itemId}`;
|
return `SUCCESS: Activated ${itemId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function menu(itemId: string): string {
|
||||||
|
const item = TrayMenuManager.findTrayItem(itemId);
|
||||||
|
if (!item)
|
||||||
|
return `ERROR: Tray item not found: ${itemId}`;
|
||||||
|
|
||||||
|
if (!item.hasMenu)
|
||||||
|
return `ERROR: Tray item has no menu: ${itemId}`;
|
||||||
|
|
||||||
|
TrayMenuManager.requestOpenMenu(itemId, BarWidgetService.getFocusedScreenName());
|
||||||
|
return `SUCCESS: Requested menu ${itemId}`;
|
||||||
|
}
|
||||||
|
|
||||||
function status(itemId: string): string {
|
function status(itemId: string): string {
|
||||||
const item = findTrayItem(itemId);
|
const item = TrayMenuManager.findTrayItem(itemId);
|
||||||
if (!item)
|
if (!item)
|
||||||
return `ERROR: Tray item not found: ${itemId}`;
|
return `ERROR: Tray item not found: ${itemId}`;
|
||||||
|
|
||||||
|
|||||||
@@ -318,10 +318,6 @@ DankModal {
|
|||||||
width: parent.width - Theme.spacingS * 2
|
width: parent.width - Theme.spacingS * 2
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
height: 52
|
height: 52
|
||||||
cornerRadius: Theme.cornerRadius
|
|
||||||
backgroundColor: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
|
||||||
normalBorderColor: Theme.outlineMedium
|
|
||||||
focusedBorderColor: Theme.primary
|
|
||||||
leftIconName: "search"
|
leftIconName: "search"
|
||||||
leftIconSize: Theme.iconSize
|
leftIconSize: Theme.iconSize
|
||||||
leftIconColor: Theme.surfaceVariantText
|
leftIconColor: Theme.surfaceVariantText
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Rectangle {
|
|||||||
|
|
||||||
height: Math.round(Theme.fontSizeMedium * 4.2)
|
height: Math.round(Theme.fontSizeMedium * 4.2)
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ import qs.Common
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
readonly property int modalWidth: 680
|
readonly property int modalWidth: 680
|
||||||
readonly property int modalHeight: screen ? Math.min(720, screen.height - 80) : 720
|
readonly property int modalHeight: screen ? Math.min(720, screen.height - 80) : 720
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ FloatingWindow {
|
|||||||
title: i18n("What's New")
|
title: i18n("What's New")
|
||||||
minimumSize: Qt.size(modalWidth, modalHeight)
|
minimumSize: Qt.size(modalWidth, modalHeight)
|
||||||
maximumSize: Qt.size(modalWidth, modalHeight)
|
maximumSize: Qt.size(modalWidth, modalHeight)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: visible = false
|
onClosed: visible = false
|
||||||
@@ -112,7 +110,7 @@ FloatingWindow {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
height: Math.round(Theme.fontSizeMedium * 4.5)
|
height: Math.round(Theme.fontSizeMedium * 4.5)
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
|||||||
@@ -819,16 +819,24 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCategoryFiltered) {
|
if (isCategoryFiltered) {
|
||||||
var rawApps = AppSearchService.getAppsInCategory(appCategory);
|
var categoryPluginId = AppSearchService.getPluginIdForCategory(appCategory);
|
||||||
for (var i = 0; i < rawApps.length; i++) {
|
if (categoryPluginId) {
|
||||||
allItems.push(getOrTransformApp(rawApps[i]));
|
var pluginCategoryItems = getPluginItems(categoryPluginId, "");
|
||||||
}
|
for (var i = 0; i < pluginCategoryItems.length; i++) {
|
||||||
// Also include core apps (DMS Settings etc.) that match this category
|
allItems.push(pluginCategoryItems[i]);
|
||||||
var allCoreApps = AppSearchService.getCoreApps("");
|
}
|
||||||
for (var i = 0; i < allCoreApps.length; i++) {
|
} else {
|
||||||
var coreAppCats = AppSearchService.getCategoriesForApp(allCoreApps[i]);
|
var rawApps = AppSearchService.getAppsInCategory(appCategory);
|
||||||
if (coreAppCats.indexOf(appCategory) !== -1)
|
for (var i = 0; i < rawApps.length; i++) {
|
||||||
allItems.push(transformCoreApp(allCoreApps[i]));
|
allItems.push(getOrTransformApp(rawApps[i]));
|
||||||
|
}
|
||||||
|
// Also include core apps (DMS Settings etc.) that match this category
|
||||||
|
var allCoreApps = AppSearchService.getCoreApps("");
|
||||||
|
for (var i = 0; i < allCoreApps.length; i++) {
|
||||||
|
var coreAppCats = AppSearchService.getCategoriesForApp(allCoreApps[i]);
|
||||||
|
if (coreAppCats.indexOf(appCategory) !== -1)
|
||||||
|
allItems.push(transformCoreApp(allCoreApps[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var apps = searchApps(searchQuery);
|
var apps = searchApps(searchQuery);
|
||||||
@@ -839,7 +847,7 @@ Item {
|
|||||||
|
|
||||||
var scoredItems = Scorer.scoreItems(allItems, searchQuery, getFrecencyForItem);
|
var scoredItems = Scorer.scoreItems(allItems, searchQuery, getFrecencyForItem);
|
||||||
var sortAlpha = !searchQuery && SettingsData.sortAppsAlphabetically;
|
var sortAlpha = !searchQuery && SettingsData.sortAppsAlphabetically;
|
||||||
var newSections = Scorer.groupBySection(scoredItems, sectionDefinitions, sortAlpha, searchQuery ? 50 : 500);
|
var newSections = Scorer.groupBySection(scoredItems, buildDynamicSectionDefs(allItems), sortAlpha, searchQuery ? 50 : 500);
|
||||||
|
|
||||||
for (var sid in collapsedSections) {
|
for (var sid in collapsedSections) {
|
||||||
for (var i = 0; i < newSections.length; i++) {
|
for (var i = 0; i < newSections.length; i++) {
|
||||||
|
|||||||
@@ -23,17 +23,6 @@ FocusScope {
|
|||||||
property bool editMode: false
|
property bool editMode: false
|
||||||
property var editingApp: null
|
property var editingApp: null
|
||||||
property string editAppId: ""
|
property string editAppId: ""
|
||||||
readonly property bool _blurActive: Theme.blurForegroundLayers || Theme.transparentBlurLayers
|
|
||||||
readonly property real _launcherFieldAlpha: {
|
|
||||||
if (Theme.transparentBlurLayers)
|
|
||||||
return 0.28;
|
|
||||||
if (Theme.blurForegroundLayers)
|
|
||||||
return Math.max(Theme.popupTransparency, 0.62);
|
|
||||||
return Theme.popupTransparency;
|
|
||||||
}
|
|
||||||
readonly property color _launcherSearchFieldColor: Theme.withAlpha(Theme.surfaceContainerHigh, _launcherFieldAlpha)
|
|
||||||
readonly property color _launcherSearchBorderColor: Theme.withAlpha(Theme.outline, _blurActive ? 0.16 : Theme.layerOutlineOpacity)
|
|
||||||
readonly property color _launcherSearchFocusedBorderColor: Theme.withAlpha(Theme.primary, _blurActive ? 0.72 : 1.0)
|
|
||||||
|
|
||||||
function resetScroll() {
|
function resetScroll() {
|
||||||
resultsList.resetScroll();
|
resultsList.resetScroll();
|
||||||
@@ -314,7 +303,7 @@ FocusScope {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.topMargin: -Theme.cornerRadius
|
anchors.topMargin: -Theme.cornerRadius
|
||||||
// In connected mode the launcher provides the surface so update the toolbar for arcs
|
// In connected mode the launcher provides the surface so update the toolbar for arcs
|
||||||
visible: !(root.parentModal?.frameOwnsConnectedChrome ?? false) && !root._blurActive
|
visible: !(root.parentModal?.frameOwnsConnectedChrome ?? false) && !Theme.blurLayersActive
|
||||||
color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
}
|
}
|
||||||
@@ -472,12 +461,6 @@ FocusScope {
|
|||||||
DankTextField {
|
DankTextField {
|
||||||
id: searchField
|
id: searchField
|
||||||
width: parent.width - (pluginBadge.visible ? pluginBadge.width + Theme.spacingS : 0)
|
width: parent.width - (pluginBadge.visible ? pluginBadge.width + Theme.spacingS : 0)
|
||||||
cornerRadius: Theme.cornerRadius
|
|
||||||
backgroundColor: root._launcherSearchFieldColor
|
|
||||||
normalBorderColor: root._launcherSearchBorderColor
|
|
||||||
focusedBorderColor: root._launcherSearchFocusedBorderColor
|
|
||||||
borderWidth: 1
|
|
||||||
focusedBorderWidth: 2
|
|
||||||
leftIconName: controller.activePluginId ? "extension" : controller.searchQuery.startsWith("/") ? "folder" : "search"
|
leftIconName: controller.activePluginId ? "extension" : controller.searchQuery.startsWith("/") ? "folder" : "search"
|
||||||
leftIconSize: Theme.iconSize
|
leftIconSize: Theme.iconSize
|
||||||
leftIconColor: Theme.surfaceVariantText
|
leftIconColor: Theme.surfaceVariantText
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ Item {
|
|||||||
|
|
||||||
property string source: ""
|
property string source: ""
|
||||||
property int glyphSize: 14
|
property int glyphSize: 14
|
||||||
|
property bool badgeVisible: true
|
||||||
|
|
||||||
readonly property var sourceAsset: ({
|
readonly property var sourceAsset: ({
|
||||||
"flatpak": "../../assets/package-sources/flatpak.svg",
|
"flatpak": "../../assets/package-sources/flatpak.svg",
|
||||||
@@ -17,7 +18,7 @@ Item {
|
|||||||
|
|
||||||
readonly property string assetPath: sourceAsset[source] || ""
|
readonly property string assetPath: sourceAsset[source] || ""
|
||||||
|
|
||||||
visible: SettingsData.dankLauncherV2ShowSourceBadges && assetPath.length > 0
|
visible: badgeVisible && SettingsData.dankLauncherV2ShowSourceBadges && assetPath.length > 0
|
||||||
implicitWidth: glyphSize
|
implicitWidth: glyphSize
|
||||||
implicitHeight: glyphSize
|
implicitHeight: glyphSize
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ Rectangle {
|
|||||||
anchors.margins: Theme.spacingXS
|
anchors.margins: Theme.spacingXS
|
||||||
source: root.item?.type === "app" ? (root.item.source || "") : ""
|
source: root.item?.type === "app" ? (root.item.source || "") : ""
|
||||||
glyphSize: 16
|
glyphSize: 16
|
||||||
visible: !root.isSelected && !!source
|
badgeVisible: !root.isSelected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ Item {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
height: keybindsGrid.height + Theme.spacingM * 2
|
height: keybindsGrid.height + Theme.spacingM * 2
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
readonly property bool useTwoColumns: width > 500
|
readonly property bool useTwoColumns: width > 500
|
||||||
readonly property int columnCount: useTwoColumns ? 2 : 1
|
readonly property int columnCount: useTwoColumns ? 2 : 1
|
||||||
@@ -240,7 +240,7 @@ Item {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
height: noKeybindsColumn.height + Theme.spacingM * 2
|
height: noKeybindsColumn.height + Theme.spacingM * 2
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
visible: !root.hasKeybinds
|
visible: !root.hasKeybinds
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ Item {
|
|||||||
anchors.leftMargin: Theme.spacingXL
|
anchors.leftMargin: Theme.spacingXL
|
||||||
anchors.rightMargin: Theme.spacingXL
|
anchors.rightMargin: Theme.spacingXL
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Rectangle {
|
|||||||
|
|
||||||
height: Math.round(Theme.fontSizeMedium * 6.4)
|
height: Math.round(Theme.fontSizeMedium * 6.4)
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ import qs.Common
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
readonly property var log: Log.scoped("GreeterModal")
|
readonly property var log: Log.scoped("GreeterModal")
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
property int currentPage: 0
|
property int currentPage: 0
|
||||||
readonly property int totalPages: 3
|
readonly property int totalPages: 3
|
||||||
readonly property var pageComponents: [welcomePage, doctorPage, completePage]
|
readonly property var pageComponents: [welcomePage, doctorPage, completePage]
|
||||||
@@ -90,7 +89,6 @@ FloatingWindow {
|
|||||||
title: I18n.tr("Welcome", "greeter modal window title")
|
title: I18n.tr("Welcome", "greeter modal window title")
|
||||||
minimumSize: Qt.size(modalWidth, modalHeight)
|
minimumSize: Qt.size(modalWidth, modalHeight)
|
||||||
maximumSize: Qt.size(modalWidth, modalHeight)
|
maximumSize: Qt.size(modalWidth, modalHeight)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: visible = false
|
onClosed: visible = false
|
||||||
@@ -173,7 +171,7 @@ FloatingWindow {
|
|||||||
width: pageIndicatorRow.width + Theme.spacingM * 2
|
width: pageIndicatorRow.width + Theme.spacingM * 2
|
||||||
height: indicatorHeight
|
height: indicatorHeight
|
||||||
radius: indicatorHeight / 2
|
radius: indicatorHeight / 2
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
id: pageIndicatorRow
|
id: pageIndicatorRow
|
||||||
@@ -259,7 +257,7 @@ FloatingWindow {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
height: Math.round(Theme.fontSizeMedium * 4.5)
|
height: Math.round(Theme.fontSizeMedium * 4.5)
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Rectangle {
|
|||||||
|
|
||||||
height: Math.round(Theme.fontSizeMedium * 3.1)
|
height: Math.round(Theme.fontSizeMedium * 3.1)
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Rectangle {
|
|||||||
|
|
||||||
height: Math.round(Theme.fontSizeMedium * 4.5)
|
height: Math.round(Theme.fontSizeMedium * 4.5)
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Rectangle {
|
|||||||
property string label: ""
|
property string label: ""
|
||||||
property string iconName: ""
|
property string iconName: ""
|
||||||
property color iconColor: Theme.surfaceText
|
property color iconColor: Theme.surfaceText
|
||||||
property color bgColor: Theme.surfaceContainerHigh
|
property color bgColor: Theme.floatingWindowNestedSurface
|
||||||
property bool selected: false
|
property bool selected: false
|
||||||
|
|
||||||
signal clicked
|
signal clicked
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ import qs.Modals
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: win
|
id: win
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
property alias shouldBeVisible: win.visible
|
property alias shouldBeVisible: win.visible
|
||||||
|
|
||||||
signal floatingToggleRequested
|
signal floatingToggleRequested
|
||||||
@@ -30,7 +29,6 @@ FloatingWindow {
|
|||||||
minimumSize: Qt.size(Math.min(560, Screen.width), Math.min(400, Screen.height))
|
minimumSize: Qt.size(Math.min(560, Screen.width), Math.min(400, Screen.height))
|
||||||
implicitWidth: 1000
|
implicitWidth: 1000
|
||||||
implicitHeight: screen ? Math.min(820, screen.height - 100) : 820
|
implicitHeight: screen ? Math.min(820, screen.height - 100) : 820
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
@@ -61,12 +59,6 @@ FloatingWindow {
|
|||||||
onDoubleClicked: windowControls.tryToggleMaximize()
|
onDoubleClicked: windowControls.tryToggleMaximize()
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
anchors.fill: parent
|
|
||||||
color: Theme.surfaceContainer
|
|
||||||
opacity: 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: Theme.spacingL
|
anchors.leftMargin: Theme.spacingL
|
||||||
|
|||||||
@@ -313,10 +313,6 @@ DankModal {
|
|||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 48
|
height: 48
|
||||||
cornerRadius: Theme.cornerRadius
|
|
||||||
backgroundColor: Theme.surfaceContainerHigh
|
|
||||||
normalBorderColor: Theme.outlineMedium
|
|
||||||
focusedBorderColor: Theme.primary
|
|
||||||
leftIconName: "search"
|
leftIconName: "search"
|
||||||
leftIconSize: Theme.iconSize
|
leftIconSize: Theme.iconSize
|
||||||
leftIconColor: Theme.surfaceVariantText
|
leftIconColor: Theme.surfaceVariantText
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ DankModal {
|
|||||||
NotificationService.dismissAllPopups();
|
NotificationService.dismissAllPopups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dismissLastNotification() {
|
||||||
|
NotificationService.dismissLastNotification();
|
||||||
|
}
|
||||||
|
|
||||||
modalWidth: Math.min(500, screenWidth - 48)
|
modalWidth: Math.min(500, screenWidth - 48)
|
||||||
modalHeight: Math.min(700, screenHeight * 0.85)
|
modalHeight: Math.min(700, screenHeight * 0.85)
|
||||||
backgroundColor: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
backgroundColor: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
||||||
@@ -190,6 +194,11 @@ DankModal {
|
|||||||
return "NOTIFICATION_MODAL_DISMISS_ALL_POPUPS_SUCCESS";
|
return "NOTIFICATION_MODAL_DISMISS_ALL_POPUPS_SUCCESS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dismiss(): string {
|
||||||
|
notificationModal.dismissLastNotification();
|
||||||
|
return "NOTIFICATION_DISMISS_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
target: "notifications"
|
target: "notifications"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ FocusScope {
|
|||||||
StyledText {
|
StyledText {
|
||||||
text: root.currentFlow?.message ?? ""
|
text: root.currentFlow?.message ?? ""
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.surfaceTextMedium
|
color: Theme.surfaceText
|
||||||
width: parent.width
|
width: parent.width
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
maximumLineCount: 2
|
maximumLineCount: 2
|
||||||
@@ -272,11 +272,6 @@ FocusScope {
|
|||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: root.inputFieldHeight
|
height: root.inputFieldHeight
|
||||||
backgroundColor: Theme.surfaceHover
|
|
||||||
normalBorderColor: Theme.outlineStrong
|
|
||||||
focusedBorderColor: Theme.primary
|
|
||||||
borderWidth: 1
|
|
||||||
focusedBorderWidth: 2
|
|
||||||
leftIconName: root.polkitPamHasFprint ? "fingerprint" : ""
|
leftIconName: root.polkitPamHasFprint ? "fingerprint" : ""
|
||||||
leftIconSize: 20
|
leftIconSize: 20
|
||||||
leftIconColor: Theme.primary
|
leftIconColor: Theme.primary
|
||||||
@@ -352,7 +347,7 @@ FocusScope {
|
|||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: I18n.tr("Authenticate")
|
text: I18n.tr("Authenticate")
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.background
|
color: Theme.primaryText
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import qs.Common
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
if (contentLoader.item)
|
if (contentLoader.item)
|
||||||
contentLoader.item.reset();
|
contentLoader.item.reset();
|
||||||
@@ -29,7 +27,6 @@ FloatingWindow {
|
|||||||
title: I18n.tr("Authentication")
|
title: I18n.tr("Authentication")
|
||||||
minimumSize: Qt.size(460, 220)
|
minimumSize: Qt.size(460, 220)
|
||||||
maximumSize: Qt.size(460, 220)
|
maximumSize: Qt.size(460, 220)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: hide()
|
onClosed: hide()
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ DankModal {
|
|||||||
switchUserRequested();
|
switchUserRequested();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (action.startsWith("custom:")) {
|
||||||
|
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
|
||||||
|
close();
|
||||||
|
if (button?.command)
|
||||||
|
Quickshell.execDetached(["sh", "-c", button.command]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
close();
|
close();
|
||||||
root.powerActionRequested(action, "", "");
|
root.powerActionRequested(action, "", "");
|
||||||
}
|
}
|
||||||
@@ -172,11 +179,14 @@ DankModal {
|
|||||||
|
|
||||||
function updateVisibleActions() {
|
function updateVisibleActions() {
|
||||||
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
|
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
|
||||||
|
const customButtons = SettingsData.customPowerButtons || [];
|
||||||
visibleActions = allActions.filter(action => {
|
visibleActions = allActions.filter(action => {
|
||||||
if (action === "hibernate" && !SessionService.hibernateSupported)
|
if (action === "hibernate" && !SessionService.hibernateSupported)
|
||||||
return false;
|
return false;
|
||||||
|
if (action === "softreboot" && !SessionService.softRebootSupported)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
}).concat(customButtons.map((button, i) => "custom:" + i));
|
||||||
|
|
||||||
if (!SettingsData.powerMenuGridLayout)
|
if (!SettingsData.powerMenuGridLayout)
|
||||||
return;
|
return;
|
||||||
@@ -216,6 +226,14 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getActionData(action) {
|
function getActionData(action) {
|
||||||
|
if (action.startsWith("custom:")) {
|
||||||
|
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
|
||||||
|
return {
|
||||||
|
"icon": button?.icon || "terminal",
|
||||||
|
"label": button?.label || button?.command || "",
|
||||||
|
"key": ""
|
||||||
|
};
|
||||||
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "reboot":
|
case "reboot":
|
||||||
return {
|
return {
|
||||||
@@ -223,6 +241,12 @@ DankModal {
|
|||||||
"label": I18n.tr("Reboot"),
|
"label": I18n.tr("Reboot"),
|
||||||
"key": "R"
|
"key": "R"
|
||||||
};
|
};
|
||||||
|
case "softreboot":
|
||||||
|
return {
|
||||||
|
"icon": "autorenew",
|
||||||
|
"label": I18n.tr("Soft Reboot"),
|
||||||
|
"key": "B"
|
||||||
|
};
|
||||||
case "logout":
|
case "logout":
|
||||||
return {
|
return {
|
||||||
"icon": "logout",
|
"icon": "logout",
|
||||||
@@ -370,7 +394,7 @@ DankModal {
|
|||||||
|
|
||||||
function handleListNavigation(event, isPressed) {
|
function handleListNavigation(event, isPressed) {
|
||||||
if (!isPressed) {
|
if (!isPressed) {
|
||||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_B || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||||
cancelHold();
|
cancelHold();
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
@@ -429,6 +453,12 @@ DankModal {
|
|||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Qt.Key_B:
|
||||||
|
if (visibleActions.includes("softreboot")) {
|
||||||
|
startHold("softreboot", visibleActions.indexOf("softreboot"));
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Qt.Key_X:
|
case Qt.Key_X:
|
||||||
if (visibleActions.includes("logout")) {
|
if (visibleActions.includes("logout")) {
|
||||||
startHold("logout", visibleActions.indexOf("logout"));
|
startHold("logout", visibleActions.indexOf("logout"));
|
||||||
@@ -464,7 +494,7 @@ DankModal {
|
|||||||
|
|
||||||
function handleGridNavigation(event, isPressed) {
|
function handleGridNavigation(event, isPressed) {
|
||||||
if (!isPressed) {
|
if (!isPressed) {
|
||||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_B || event.key === Qt.Key_X || event.key === Qt.Key_L || event.key === Qt.Key_S || event.key === Qt.Key_H || event.key === Qt.Key_D || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
|
||||||
cancelHold();
|
cancelHold();
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
@@ -539,6 +569,12 @@ DankModal {
|
|||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Qt.Key_B:
|
||||||
|
if (visibleActions.includes("softreboot")) {
|
||||||
|
startHold("softreboot", visibleActions.indexOf("softreboot"));
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Qt.Key_X:
|
case Qt.Key_X:
|
||||||
if (visibleActions.includes("logout")) {
|
if (visibleActions.includes("logout")) {
|
||||||
startHold("logout", visibleActions.indexOf("logout"));
|
startHold("logout", visibleActions.indexOf("logout"));
|
||||||
@@ -597,7 +633,7 @@ DankModal {
|
|||||||
|
|
||||||
readonly property var actionData: root.getActionData(modelData)
|
readonly property var actionData: root.getActionData(modelData)
|
||||||
readonly property bool isSelected: root.selectedIndex === index
|
readonly property bool isSelected: root.selectedIndex === index
|
||||||
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
|
readonly property bool showWarning: modelData === "reboot" || modelData === "softreboot" || modelData === "poweroff"
|
||||||
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
||||||
|
|
||||||
width: (root.modalWidth - Theme.spacingL * 2 - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns
|
width: (root.modalWidth - Theme.spacingL * 2 - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns
|
||||||
@@ -627,7 +663,7 @@ DankModal {
|
|||||||
color: {
|
color: {
|
||||||
if (gridButtonRect.modelData === "poweroff")
|
if (gridButtonRect.modelData === "poweroff")
|
||||||
return Theme.errorSelected;
|
return Theme.errorSelected;
|
||||||
if (gridButtonRect.modelData === "reboot")
|
if (gridButtonRect.modelData === "reboot" || gridButtonRect.modelData === "softreboot")
|
||||||
return Theme.withAlpha(Theme.warning, 0.3);
|
return Theme.withAlpha(Theme.warning, 0.3);
|
||||||
return Theme.primarySelected;
|
return Theme.primarySelected;
|
||||||
}
|
}
|
||||||
@@ -668,6 +704,7 @@ DankModal {
|
|||||||
height: 16
|
height: 16
|
||||||
radius: 4
|
radius: 4
|
||||||
color: Theme.onSurface_12
|
color: Theme.onSurface_12
|
||||||
|
visible: gridButtonRect.actionData.key !== ""
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
@@ -722,7 +759,7 @@ DankModal {
|
|||||||
|
|
||||||
readonly property var actionData: root.getActionData(modelData)
|
readonly property var actionData: root.getActionData(modelData)
|
||||||
readonly property bool isSelected: root.selectedIndex === index
|
readonly property bool isSelected: root.selectedIndex === index
|
||||||
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
|
readonly property bool showWarning: modelData === "reboot" || modelData === "softreboot" || modelData === "poweroff"
|
||||||
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
@@ -752,7 +789,7 @@ DankModal {
|
|||||||
color: {
|
color: {
|
||||||
if (listButtonRect.modelData === "poweroff")
|
if (listButtonRect.modelData === "poweroff")
|
||||||
return Theme.errorSelected;
|
return Theme.errorSelected;
|
||||||
if (listButtonRect.modelData === "reboot")
|
if (listButtonRect.modelData === "reboot" || listButtonRect.modelData === "softreboot")
|
||||||
return Theme.withAlpha(Theme.warning, 0.3);
|
return Theme.withAlpha(Theme.warning, 0.3);
|
||||||
return Theme.primarySelected;
|
return Theme.primarySelected;
|
||||||
}
|
}
|
||||||
@@ -800,6 +837,7 @@ DankModal {
|
|||||||
height: 20
|
height: 20
|
||||||
radius: 4
|
radius: 4
|
||||||
color: Theme.onSurface_12
|
color: Theme.onSurface_12
|
||||||
|
visible: listButtonRect.actionData.key !== ""
|
||||||
anchors {
|
anchors {
|
||||||
right: parent.right
|
right: parent.right
|
||||||
rightMargin: Theme.spacingM
|
rightMargin: Theme.spacingM
|
||||||
|
|||||||
@@ -8,11 +8,10 @@ import qs.Services
|
|||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
import "../Common/Format.js" as Format
|
import "../Common/Format.js" as Format
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: processListModal
|
id: processListModal
|
||||||
readonly property var log: Log.scoped("ProcessListModal")
|
readonly property var log: Log.scoped("ProcessListModal")
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
property int currentTab: 0
|
property int currentTab: 0
|
||||||
property string searchText: ""
|
property string searchText: ""
|
||||||
property string expandedPid: ""
|
property string expandedPid: ""
|
||||||
@@ -81,7 +80,6 @@ FloatingWindow {
|
|||||||
minimumSize: Qt.size(Math.min(Math.round(Theme.fontSizeMedium * 48), Screen.width), Math.min(Math.round(Theme.fontSizeMedium * 34), Screen.height))
|
minimumSize: Qt.size(Math.min(Math.round(Theme.fontSizeMedium * 48), Screen.width), Math.min(Math.round(Theme.fontSizeMedium * 34), Screen.height))
|
||||||
implicitWidth: Math.round(Theme.fontSizeMedium * 71)
|
implicitWidth: Math.round(Theme.fontSizeMedium * 71)
|
||||||
implicitHeight: Math.round(Theme.fontSizeMedium * 51)
|
implicitHeight: Math.round(Theme.fontSizeMedium * 51)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: hide()
|
onClosed: hide()
|
||||||
@@ -420,7 +418,7 @@ FloatingWindow {
|
|||||||
Layout.margins: Theme.spacingL
|
Layout.margins: Theme.spacingL
|
||||||
Layout.topMargin: Theme.spacingM
|
Layout.topMargin: Theme.spacingM
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
color: Theme.floatingWindowNestedSurface
|
||||||
border.color: Theme.outlineLight
|
border.color: Theme.outlineLight
|
||||||
border.width: 1
|
border.width: 1
|
||||||
clip: true
|
clip: true
|
||||||
|
|||||||
@@ -0,0 +1,285 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import QtQuick.Effects
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
import qs.Modals.Common
|
||||||
|
import qs.Modals.FileBrowser
|
||||||
|
import qs.Common
|
||||||
|
import qs.Services
|
||||||
|
import qs.Widgets
|
||||||
|
|
||||||
|
DankModal {
|
||||||
|
id: root
|
||||||
|
visible: false
|
||||||
|
layerNamespace: "dms:qr-generator"
|
||||||
|
|
||||||
|
property bool disablePopupTransparency: true
|
||||||
|
property bool generating: false
|
||||||
|
property string themedQrCodePath: ""
|
||||||
|
property string normalQrCodePath: ""
|
||||||
|
property string initialText: ""
|
||||||
|
property string _pendingPayload: ""
|
||||||
|
property string _generatingPayload: ""
|
||||||
|
property string _displayedPayload: ""
|
||||||
|
modalWidth: 420
|
||||||
|
modalHeight: 440
|
||||||
|
onBackgroundClicked: hide()
|
||||||
|
onOpened: {
|
||||||
|
Qt.callLater(() => {
|
||||||
|
modalFocusScope.forceActiveFocus();
|
||||||
|
const item = contentLoader.item;
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
item.saveBrowserLoader = saveBrowserLoader;
|
||||||
|
if (item.textInput) {
|
||||||
|
item.textInput.text = initialText;
|
||||||
|
item.textInput.forceActiveFocus();
|
||||||
|
}
|
||||||
|
if (initialText.length > 0) {
|
||||||
|
_pendingPayload = initialText;
|
||||||
|
generateQR(initialText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(text) {
|
||||||
|
generating = false;
|
||||||
|
initialText = text || "";
|
||||||
|
_pendingPayload = "";
|
||||||
|
_generatingPayload = "";
|
||||||
|
_displayedPayload = "";
|
||||||
|
themedQrCodePath = "";
|
||||||
|
normalQrCodePath = "";
|
||||||
|
open();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide() {
|
||||||
|
deleteQrCodeFiles(themedQrCodePath, normalQrCodePath);
|
||||||
|
themedQrCodePath = "";
|
||||||
|
normalQrCodePath = "";
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteQrCodeFiles(themed, normal) {
|
||||||
|
if (themed.length > 0)
|
||||||
|
DMSService.sendRequest("network.delete-qrcode", {
|
||||||
|
path: themed
|
||||||
|
});
|
||||||
|
if (normal.length > 0)
|
||||||
|
DMSService.sendRequest("network.delete-qrcode", {
|
||||||
|
path: normal
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: genTimer
|
||||||
|
interval: 200
|
||||||
|
repeat: false
|
||||||
|
onTriggered: root.generateQR(root._pendingPayload)
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateQR(text) {
|
||||||
|
const trimmed = (text || "").trim();
|
||||||
|
if (trimmed.length === 0 || trimmed === _displayedPayload || generating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_generatingPayload = trimmed;
|
||||||
|
generating = true;
|
||||||
|
|
||||||
|
DMSService.sendRequest("network.generate-qrcode", {
|
||||||
|
text: trimmed
|
||||||
|
}, response => {
|
||||||
|
root.generating = false;
|
||||||
|
if (response.error) {
|
||||||
|
ToastService.showError(I18n.tr("Failed to generate QR code: %1").arg(JSON.stringify(response.error)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!response.result)
|
||||||
|
return;
|
||||||
|
if (root._generatingPayload !== root._pendingPayload.trim()) {
|
||||||
|
root.deleteQrCodeFiles(response.result[0], response.result[1]);
|
||||||
|
genTimer.restart();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldThemed = root.themedQrCodePath;
|
||||||
|
const oldNormal = root.normalQrCodePath;
|
||||||
|
root._displayedPayload = root._generatingPayload;
|
||||||
|
root.themedQrCodePath = response.result[0];
|
||||||
|
root.normalQrCodePath = response.result[1];
|
||||||
|
root.deleteQrCodeFiles(oldThemed, oldNormal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTextChanged(text) {
|
||||||
|
_pendingPayload = text;
|
||||||
|
const trimmed = text.trim();
|
||||||
|
if (trimmed.length === 0 || trimmed === _displayedPayload) {
|
||||||
|
genTimer.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
genTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyLoader {
|
||||||
|
id: saveBrowserLoader
|
||||||
|
active: false
|
||||||
|
|
||||||
|
FileBrowserSurfaceModal {
|
||||||
|
id: saveBrowser
|
||||||
|
|
||||||
|
browserTitle: I18n.tr("Save QR Code")
|
||||||
|
browserIcon: "qr_code"
|
||||||
|
browserType: "default"
|
||||||
|
fileExtensions: ["*.png"]
|
||||||
|
allowStacking: true
|
||||||
|
saveMode: true
|
||||||
|
defaultFileName: "qrcode.png"
|
||||||
|
onFileSelected: path => {
|
||||||
|
const cleanPath = decodeURI(path.toString().replace(/^file:\/\//, ''));
|
||||||
|
copyQrCodeProcess.exec(["cp", "-f", root.normalQrCodePath, cleanPath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: copyQrCodeProcess
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
saveBrowser.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content: Component {
|
||||||
|
Item {
|
||||||
|
id: contentItem
|
||||||
|
|
||||||
|
property alias textInput: textInput
|
||||||
|
property var saveBrowserLoader: null
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: Theme.spacingL
|
||||||
|
spacing: Theme.spacingL
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: modalTitle
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: I18n.tr("QR Generator")
|
||||||
|
font.pixelSize: Theme.fontSizeLarge
|
||||||
|
color: Theme.surfaceText
|
||||||
|
font.weight: Font.Bold
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
DankActionButton {
|
||||||
|
iconName: "close"
|
||||||
|
iconSize: Theme.iconSize - 4
|
||||||
|
iconColor: Theme.surfaceText
|
||||||
|
onClicked: root.hide()
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankTextField {
|
||||||
|
id: textInput
|
||||||
|
width: parent.width
|
||||||
|
placeholderText: I18n.tr("Enter text to encode")
|
||||||
|
showClearButton: true
|
||||||
|
focus: true
|
||||||
|
onTextEdited: root.onTextChanged(text)
|
||||||
|
Keys.onEscapePressed: event => {
|
||||||
|
event.accepted = true;
|
||||||
|
root.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: qrContainer
|
||||||
|
height: Math.min(parent.height - parent.spacing - modalTitle.height - textInput.height - parent.spacing * 4, 260)
|
||||||
|
width: height
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
opacity: 1
|
||||||
|
|
||||||
|
Behavior on opacity {
|
||||||
|
NumberAnimation {
|
||||||
|
duration: 80
|
||||||
|
easing.type: Easing.OutCubic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Image {
|
||||||
|
id: qrCodeImg
|
||||||
|
anchors.fill: parent
|
||||||
|
source: root.themedQrCodePath
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
asynchronous: true
|
||||||
|
cache: false
|
||||||
|
visible: false
|
||||||
|
|
||||||
|
onSourceChanged: qrContainer.opacity = 0
|
||||||
|
onStatusChanged: {
|
||||||
|
if (status === Image.Ready)
|
||||||
|
qrContainer.opacity = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiEffect {
|
||||||
|
source: qrCodeImg
|
||||||
|
anchors.fill: qrCodeImg
|
||||||
|
colorization: 1.0
|
||||||
|
colorizationColor: Theme.primary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
width: parent.width
|
||||||
|
visible: root.themedQrCodePath.length > 0
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
DankButton {
|
||||||
|
text: I18n.tr("Save")
|
||||||
|
iconName: "save"
|
||||||
|
backgroundColor: Theme.surfaceContainer
|
||||||
|
textColor: Theme.surfaceText
|
||||||
|
onClicked: {
|
||||||
|
contentItem.saveBrowserLoader.active = true;
|
||||||
|
if (contentItem.saveBrowserLoader.item) {
|
||||||
|
contentItem.saveBrowserLoader.item.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankButton {
|
||||||
|
text: I18n.tr("Copy")
|
||||||
|
iconName: "content_copy"
|
||||||
|
backgroundColor: Theme.primary
|
||||||
|
textColor: Theme.onPrimary
|
||||||
|
onClicked: {
|
||||||
|
if (root.normalQrCodePath.length > 0)
|
||||||
|
DMSService.sendRequest("clipboard.copyFile", {
|
||||||
|
filePath: root.normalQrCodePath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -733,5 +733,20 @@ FocusScope {
|
|||||||
Qt.callLater(() => item.forceActiveFocus());
|
Qt.callLater(() => item.forceActiveFocus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
id: keyboardLoader
|
||||||
|
anchors.fill: parent
|
||||||
|
active: root.currentIndex === 45
|
||||||
|
visible: active
|
||||||
|
focus: active
|
||||||
|
|
||||||
|
sourceComponent: KeyboardTab {}
|
||||||
|
|
||||||
|
onActiveChanged: {
|
||||||
|
if (active && item)
|
||||||
|
Qt.callLater(() => item.forceActiveFocus());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import qs.Modals.FileBrowser
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: settingsModal
|
id: settingsModal
|
||||||
|
|
||||||
property var profileBrowser: profileBrowserLoader.item
|
property var profileBrowser: profileBrowserLoader.item
|
||||||
@@ -95,7 +95,6 @@ FloatingWindow {
|
|||||||
minimumSize: Qt.size(500, 400)
|
minimumSize: Qt.size(500, 400)
|
||||||
implicitWidth: 900
|
implicitWidth: 900
|
||||||
implicitHeight: screen ? Math.min(940, screen.height - 100) : 940
|
implicitHeight: screen ? Math.min(940, screen.height - 100) : 940
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: hide()
|
onClosed: hide()
|
||||||
@@ -180,8 +179,6 @@ FloatingWindow {
|
|||||||
FocusScope {
|
FocusScope {
|
||||||
id: contentFocusScope
|
id: contentFocusScope
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
|
|
||||||
LayoutMirroring.enabled: I18n.isRtl
|
LayoutMirroring.enabled: I18n.isRtl
|
||||||
LayoutMirroring.childrenInherit: true
|
LayoutMirroring.childrenInherit: true
|
||||||
|
|
||||||
@@ -203,12 +200,6 @@ FloatingWindow {
|
|||||||
onDoubleClicked: windowControls.tryToggleMaximize()
|
onDoubleClicked: windowControls.tryToggleMaximize()
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
anchors.fill: parent
|
|
||||||
color: Theme.surfaceContainer
|
|
||||||
opacity: 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: Theme.spacingL
|
anchors.leftMargin: Theme.spacingL
|
||||||
@@ -276,7 +267,7 @@ FloatingWindow {
|
|||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: showBanner ? bannerContent.implicitHeight + Theme.spacingM * 2 : 0
|
height: showBanner ? bannerContent.implicitHeight + Theme.spacingM * 2 : 0
|
||||||
color: Theme.surfaceContainerHigh
|
color: Theme.floatingWindowNestedSurface
|
||||||
visible: showBanner
|
visible: showBanner
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
|
|||||||
@@ -326,6 +326,13 @@ Rectangle {
|
|||||||
"tabIndex": 44,
|
"tabIndex": 44,
|
||||||
"niriOnly": true
|
"niriOnly": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "keyboard",
|
||||||
|
"text": I18n.tr("Keyboard"),
|
||||||
|
"icon": "keyboard",
|
||||||
|
"tabIndex": 45,
|
||||||
|
"niriOnly": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "locale",
|
"id": "locale",
|
||||||
"text": I18n.tr("Locale"),
|
"text": I18n.tr("Locale"),
|
||||||
@@ -641,7 +648,7 @@ Rectangle {
|
|||||||
implicitWidth: __calculatedWidth
|
implicitWidth: __calculatedWidth
|
||||||
width: __calculatedWidth
|
width: __calculatedWidth
|
||||||
height: parent.height
|
height: parent.height
|
||||||
color: Theme.surfaceContainer
|
color: "transparent"
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@@ -742,12 +749,9 @@ Rectangle {
|
|||||||
id: searchField
|
id: searchField
|
||||||
width: parent.width - parent.leftPadding - parent.rightPadding
|
width: parent.width - parent.leftPadding - parent.rightPadding
|
||||||
placeholderText: I18n.tr("Search...")
|
placeholderText: I18n.tr("Search...")
|
||||||
normalBorderColor: Theme.outlineMedium
|
|
||||||
focusedBorderColor: Theme.primary
|
|
||||||
leftIconName: "search"
|
leftIconName: "search"
|
||||||
leftIconSize: Theme.iconSize - 4
|
leftIconSize: Theme.iconSize - 4
|
||||||
showClearButton: text.length > 0
|
showClearButton: text.length > 0
|
||||||
usePopupTransparency: false
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
SettingsSearchService.search(text);
|
SettingsSearchService.search(text);
|
||||||
root.searchSelectedIndex = 0;
|
root.searchSelectedIndex = 0;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ DankModal {
|
|||||||
property string promptToken: ""
|
property string promptToken: ""
|
||||||
property string promptReason: ""
|
property string promptReason: ""
|
||||||
property var promptFields: []
|
property var promptFields: []
|
||||||
|
property var promptHints: []
|
||||||
property string promptSetting: ""
|
property string promptSetting: ""
|
||||||
|
|
||||||
property bool isVpnPrompt: false
|
property bool isVpnPrompt: false
|
||||||
@@ -40,17 +41,21 @@ DankModal {
|
|||||||
property var fieldsInfo: []
|
property var fieldsInfo: []
|
||||||
property var secretValues: ({})
|
property var secretValues: ({})
|
||||||
|
|
||||||
|
readonly property bool isCertificateChangedPrompt: promptReason === "server-certificate-changed"
|
||||||
|
readonly property bool isCertificatePrompt: promptReason === "server-certificate" || isCertificateChangedPrompt
|
||||||
|
readonly property string serverCertificateFingerprint: promptHints.length > 0 ? promptHints[0] : ""
|
||||||
readonly property bool showUsernameField: requiresEnterprise && !isVpnPrompt && fieldsInfo.length === 0
|
readonly property bool showUsernameField: requiresEnterprise && !isVpnPrompt && fieldsInfo.length === 0
|
||||||
readonly property bool showPasswordField: fieldsInfo.length === 0
|
readonly property bool showPasswordField: fieldsInfo.length === 0 && !isCertificatePrompt
|
||||||
readonly property bool showAnonField: requiresEnterprise && !isVpnPrompt
|
readonly property bool showAnonField: requiresEnterprise && !isVpnPrompt
|
||||||
readonly property bool showDomainField: requiresEnterprise && !isVpnPrompt
|
readonly property bool showDomainField: requiresEnterprise && !isVpnPrompt
|
||||||
readonly property bool showSavePasswordCheckbox: (isVpnPrompt || fieldsInfo.length > 0) && promptReason !== "pkcs11"
|
readonly property bool showSavePasswordCheckbox: (isVpnPrompt || fieldsInfo.length > 0) && promptReason !== "pkcs11" && !isCertificatePrompt
|
||||||
|
|
||||||
readonly property int inputFieldHeight: Theme.fontSizeMedium + Theme.spacingL * 2
|
readonly property int inputFieldHeight: Theme.fontSizeMedium + Theme.spacingL * 2
|
||||||
readonly property int inputFieldWithSpacing: inputFieldHeight + Theme.spacingM
|
readonly property int inputFieldWithSpacing: inputFieldHeight + Theme.spacingM
|
||||||
readonly property int checkboxRowHeight: Theme.fontSizeMedium + Theme.spacingS
|
readonly property int checkboxRowHeight: Theme.fontSizeMedium + Theme.spacingS
|
||||||
readonly property int headerHeight: Theme.fontSizeLarge + Theme.fontSizeMedium + Theme.spacingM * 2
|
readonly property int headerHeight: Theme.fontSizeLarge + Theme.fontSizeMedium + Theme.spacingM * 2
|
||||||
readonly property int buttonRowHeight: 36 + Theme.spacingM
|
readonly property int buttonRowHeight: 36 + Theme.spacingM
|
||||||
|
readonly property int certificateWarningHeight: certificateWarningColumn.implicitHeight + Theme.spacingM * 2
|
||||||
|
|
||||||
property int calculatedHeight: {
|
property int calculatedHeight: {
|
||||||
let h = headerHeight + buttonRowHeight + Theme.spacingL * 2;
|
let h = headerHeight + buttonRowHeight + Theme.spacingL * 2;
|
||||||
@@ -67,10 +72,16 @@ DankModal {
|
|||||||
h += inputFieldWithSpacing;
|
h += inputFieldWithSpacing;
|
||||||
if (showSavePasswordCheckbox)
|
if (showSavePasswordCheckbox)
|
||||||
h += checkboxRowHeight;
|
h += checkboxRowHeight;
|
||||||
|
if (isCertificatePrompt)
|
||||||
|
h += certificateWarningHeight + Theme.spacingM;
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
function focusFirstField() {
|
function focusFirstField() {
|
||||||
|
if (isCertificatePrompt) {
|
||||||
|
connectButton.forceActiveFocus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (fieldsInfo.length > 0) {
|
if (fieldsInfo.length > 0) {
|
||||||
if (dynamicFieldsRepeater.count > 0) {
|
if (dynamicFieldsRepeater.count > 0) {
|
||||||
const firstItem = dynamicFieldsRepeater.itemAt(0);
|
const firstItem = dynamicFieldsRepeater.itemAt(0);
|
||||||
@@ -101,6 +112,7 @@ DankModal {
|
|||||||
promptToken = "";
|
promptToken = "";
|
||||||
promptReason = "";
|
promptReason = "";
|
||||||
promptFields = [];
|
promptFields = [];
|
||||||
|
promptHints = [];
|
||||||
promptSetting = "";
|
promptSetting = "";
|
||||||
isVpnPrompt = false;
|
isVpnPrompt = false;
|
||||||
connectionName = "";
|
connectionName = "";
|
||||||
@@ -127,6 +139,7 @@ DankModal {
|
|||||||
promptToken = "";
|
promptToken = "";
|
||||||
promptReason = "";
|
promptReason = "";
|
||||||
promptFields = [];
|
promptFields = [];
|
||||||
|
promptHints = [];
|
||||||
promptSetting = "";
|
promptSetting = "";
|
||||||
isVpnPrompt = false;
|
isVpnPrompt = false;
|
||||||
connectionName = "";
|
connectionName = "";
|
||||||
@@ -145,6 +158,7 @@ DankModal {
|
|||||||
promptToken = token;
|
promptToken = token;
|
||||||
promptReason = reason;
|
promptReason = reason;
|
||||||
promptFields = fields || [];
|
promptFields = fields || [];
|
||||||
|
promptHints = hints || [];
|
||||||
promptSetting = setting || "802-11-wireless-security";
|
promptSetting = setting || "802-11-wireless-security";
|
||||||
connectionType = connType || "802-11-wireless";
|
connectionType = connType || "802-11-wireless";
|
||||||
connectionName = connName || ssid || "";
|
connectionName = connName || ssid || "";
|
||||||
@@ -324,6 +338,8 @@ DankModal {
|
|||||||
text: {
|
text: {
|
||||||
if (promptReason === "pkcs11")
|
if (promptReason === "pkcs11")
|
||||||
return I18n.tr("Smartcard Authentication");
|
return I18n.tr("Smartcard Authentication");
|
||||||
|
if (isCertificatePrompt)
|
||||||
|
return I18n.tr("Untrusted VPN certificate", "Title for VPN server certificate trust confirmation");
|
||||||
if (isVpnPrompt)
|
if (isVpnPrompt)
|
||||||
return I18n.tr("Connect to VPN");
|
return I18n.tr("Connect to VPN");
|
||||||
if (isHiddenNetwork)
|
if (isHiddenNetwork)
|
||||||
@@ -343,6 +359,8 @@ DankModal {
|
|||||||
text: {
|
text: {
|
||||||
if (promptReason === "pkcs11")
|
if (promptReason === "pkcs11")
|
||||||
return I18n.tr("Enter PIN for ") + wifiPasswordSSID;
|
return I18n.tr("Enter PIN for ") + wifiPasswordSSID;
|
||||||
|
if (isCertificatePrompt)
|
||||||
|
return wifiPasswordSSID;
|
||||||
if (fieldsInfo.length > 0)
|
if (fieldsInfo.length > 0)
|
||||||
return I18n.tr("Enter credentials for ") + wifiPasswordSSID;
|
return I18n.tr("Enter credentials for ") + wifiPasswordSSID;
|
||||||
if (isVpnPrompt)
|
if (isVpnPrompt)
|
||||||
@@ -383,6 +401,45 @@ DankModal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: certificateWarningBox
|
||||||
|
|
||||||
|
readonly property color warningTone: isCertificateChangedPrompt ? Theme.error : Theme.warning
|
||||||
|
|
||||||
|
width: parent.width
|
||||||
|
height: certificateWarningHeight
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: Theme.withAlpha(warningTone, 0.12)
|
||||||
|
border.color: Theme.withAlpha(warningTone, 0.5)
|
||||||
|
border.width: 1
|
||||||
|
visible: isCertificatePrompt
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: certificateWarningColumn
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: Theme.spacingM
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
width: parent.width
|
||||||
|
text: isCertificateChangedPrompt ? I18n.tr("The server certificate has changed since it was last trusted. Only continue if you recognize the new fingerprint.", "Warning shown when a trusted VPN server certificate no longer matches") : I18n.tr("Only continue if you recognize this server certificate fingerprint.", "Warning shown before trusting an unverified VPN server certificate")
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceText
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
width: parent.width
|
||||||
|
text: serverCertificateFingerprint
|
||||||
|
wrapMode: Text.WrapAnywhere
|
||||||
|
font.family: SettingsData.monoFontFamily
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: certificateWarningBox.warningTone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: inputFieldHeight
|
height: inputFieldHeight
|
||||||
@@ -690,10 +747,15 @@ DankModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
id: connectButton
|
||||||
|
|
||||||
width: Math.max(80, connectText.contentWidth + Theme.spacingM * 2)
|
width: Math.max(80, connectText.contentWidth + Theme.spacingM * 2)
|
||||||
height: 36
|
height: 36
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: connectArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary
|
color: connectArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary
|
||||||
|
border.color: activeFocus ? Theme.surfaceText : "transparent"
|
||||||
|
border.width: activeFocus ? 2 : 0
|
||||||
|
activeFocusOnTab: true
|
||||||
enabled: {
|
enabled: {
|
||||||
if (fieldsInfo.length > 0) {
|
if (fieldsInfo.length > 0) {
|
||||||
for (var i = 0; i < fieldsInfo.length; i++) {
|
for (var i = 0; i < fieldsInfo.length; i++) {
|
||||||
@@ -705,6 +767,8 @@ DankModal {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (isCertificatePrompt)
|
||||||
|
return serverCertificateFingerprint.length > 0;
|
||||||
if (isVpnPrompt)
|
if (isVpnPrompt)
|
||||||
return passwordInput.text.length > 0;
|
return passwordInput.text.length > 0;
|
||||||
if (isHiddenNetwork)
|
if (isHiddenNetwork)
|
||||||
@@ -716,7 +780,7 @@ DankModal {
|
|||||||
StyledText {
|
StyledText {
|
||||||
id: connectText
|
id: connectText
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: I18n.tr("Connect")
|
text: isCertificatePrompt ? I18n.tr("Trust", "Button that approves a VPN server certificate fingerprint") : I18n.tr("Connect")
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.background
|
color: Theme.background
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
@@ -731,6 +795,22 @@ DankModal {
|
|||||||
onClicked: submitCredentialsAndClose()
|
onClicked: submitCredentialsAndClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onReturnPressed: event => {
|
||||||
|
if (enabled)
|
||||||
|
submitCredentialsAndClose();
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
Keys.onEnterPressed: event => {
|
||||||
|
if (enabled)
|
||||||
|
submitCredentialsAndClose();
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
Keys.onSpacePressed: event => {
|
||||||
|
if (enabled)
|
||||||
|
submitCredentialsAndClose();
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
|
||||||
Behavior on color {
|
Behavior on color {
|
||||||
ColorAnimation {
|
ColorAnimation {
|
||||||
duration: Theme.shortDuration
|
duration: Theme.shortDuration
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ import qs.Common
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
property var editingRule: null
|
property var editingRule: null
|
||||||
property bool isEditMode: editingRule !== null
|
property bool isEditMode: editingRule !== null
|
||||||
property bool isNiri: CompositorService.isNiri
|
property bool isNiri: CompositorService.isNiri
|
||||||
@@ -29,7 +28,6 @@ FloatingWindow {
|
|||||||
title: isEditMode ? I18n.tr("Edit Window Rule") : I18n.tr("Create Window Rule")
|
title: isEditMode ? I18n.tr("Edit Window Rule") : I18n.tr("Create Window Rule")
|
||||||
minimumSize: Qt.size(500, 600)
|
minimumSize: Qt.size(500, 600)
|
||||||
maximumSize: Qt.size(500, 600)
|
maximumSize: Qt.size(500, 600)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: hide()
|
onClosed: hide()
|
||||||
|
|||||||
@@ -4,18 +4,16 @@ import qs.Common
|
|||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
readonly property var log: Log.scoped("WorkspaceRenameModal")
|
readonly property var log: Log.scoped("WorkspaceRenameModal")
|
||||||
|
|
||||||
property bool disablePopupTransparency: true
|
|
||||||
readonly property int inputFieldHeight: Theme.fontSizeMedium + Theme.spacingL * 2
|
readonly property int inputFieldHeight: Theme.fontSizeMedium + Theme.spacingL * 2
|
||||||
|
|
||||||
objectName: "workspaceRenameModal"
|
objectName: "workspaceRenameModal"
|
||||||
title: I18n.tr("Rename Workspace")
|
title: I18n.tr("Rename Workspace")
|
||||||
minimumSize: Qt.size(400, 160)
|
minimumSize: Qt.size(400, 160)
|
||||||
maximumSize: Qt.size(400, 160)
|
maximumSize: Qt.size(400, 160)
|
||||||
color: Theme.surfaceContainer
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onClosed: hide()
|
onClosed: hide()
|
||||||
|
|||||||
@@ -469,6 +469,8 @@ PluginComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
id: peerMouseArea
|
||||||
|
|
||||||
z: -1
|
z: -1
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ Rectangle {
|
|||||||
property bool hasWifiAvailable: (NetworkService.wifiDevices?.length ?? 0) > 0
|
property bool hasWifiAvailable: (NetworkService.wifiDevices?.length ?? 0) > 0
|
||||||
property bool hasBothConnectionTypes: hasEthernetAvailable && hasWifiAvailable
|
property bool hasBothConnectionTypes: hasEthernetAvailable && hasWifiAvailable
|
||||||
property int maxPinnedNetworks: 3
|
property int maxPinnedNetworks: 3
|
||||||
readonly property int hotspotContentHeight: currentPreferenceIndex === 1 && NetworkService.hotspotAvailable ? 56 + Theme.spacingS : 0
|
// Hosting on the only wifi adapter with no ethernet uplink just drops connectivity,
|
||||||
|
// so the hotspot row only shows where sharing can actually work (or is already on).
|
||||||
|
readonly property bool hotspotRelevant: NetworkService.hotspotEnabled || NetworkService.hotspotActivating || NetworkService.hotspotBusy || NetworkService.ethernetConnected || (NetworkService.wifiDevices?.length ?? 0) > 1
|
||||||
|
readonly property bool showHotspotRow: currentPreferenceIndex === 1 && NetworkService.hotspotAvailable && hotspotRelevant
|
||||||
|
readonly property int hotspotContentHeight: showHotspotRow ? 56 + Theme.spacingS : 0
|
||||||
|
|
||||||
property var hotspotStartConfirm: ConfirmModal {}
|
property var hotspotStartConfirm: ConfirmModal {}
|
||||||
|
|
||||||
@@ -184,7 +188,7 @@ Rectangle {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.margins: Theme.spacingM
|
anchors.margins: Theme.spacingM
|
||||||
anchors.topMargin: Theme.spacingM
|
anchors.topMargin: Theme.spacingM
|
||||||
visible: currentPreferenceIndex === 1 && NetworkService.hotspotAvailable
|
visible: root.showHotspotRow
|
||||||
height: visible ? 56 : 0
|
height: visible ? 56 : 0
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|||||||
@@ -201,7 +201,16 @@ Item {
|
|||||||
direction: root.effectiveShadowDirection
|
direction: root.effectiveShadowDirection
|
||||||
fallbackOffset: 4
|
fallbackOffset: 4
|
||||||
targetRadius: root.rt
|
targetRadius: root.rt
|
||||||
targetColor: barWindow._bgColor
|
// wing-side body corners are square where the gothic fillets attach;
|
||||||
|
// rounding the shadow there leaves a shadow-filled notch under the
|
||||||
|
// translucent bar fill (#2975)
|
||||||
|
topLeftRadius: root.gothEnabled && (root.isBottom || root.isRight) ? 0 : root.rt
|
||||||
|
topRightRadius: root.gothEnabled && (root.isBottom || root.isLeft) ? 0 : root.rt
|
||||||
|
bottomLeftRadius: root.gothEnabled && (root.isTop || root.isRight) ? 0 : root.rt
|
||||||
|
bottomRightRadius: root.gothEnabled && (root.isTop || root.isLeft) ? 0 : root.rt
|
||||||
|
// barShape below is the sole painter of the bar; a fill here doubles
|
||||||
|
// the alpha of translucent bars while the wings stay single-painted
|
||||||
|
targetColor: "transparent"
|
||||||
|
|
||||||
shadowBlurPx: root.shadowBlurPx
|
shadowBlurPx: root.shadowBlurPx
|
||||||
shadowOffsetX: root.shadowOffsetX
|
shadowOffsetX: root.shadowOffsetX
|
||||||
|
|||||||
@@ -38,11 +38,10 @@ Item {
|
|||||||
readonly property real _barInsetPaddingRaw: SettingsData.barInsetPaddingSyncAll ? SettingsData.barInsetPaddingShared : (barConfig?.barInsetPadding ?? -1)
|
readonly property real _barInsetPaddingRaw: SettingsData.barInsetPaddingSyncAll ? SettingsData.barInsetPaddingShared : (barConfig?.barInsetPadding ?? -1)
|
||||||
readonly property real _barInsetPaddingAuto: _barIsVertical ? Theme.spacingXS : _edgeBaseMargin
|
readonly property real _barInsetPaddingAuto: _barIsVertical ? Theme.spacingXS : _edgeBaseMargin
|
||||||
readonly property real _barInsetPadding: _barInsetPaddingRaw < 0 ? _barInsetPaddingAuto : _barInsetPaddingRaw
|
readonly property real _barInsetPadding: _barInsetPaddingRaw < 0 ? _barInsetPaddingAuto : _barInsetPaddingRaw
|
||||||
// Connected-frame Bar Inset Padding: absolute free-end gap the hosted bar spans full-width into
|
// Hosted bars span their edge fully; frameBarContentGap is the free-end gap measured from the
|
||||||
// (auto < 0 = frameThickness so widgets align with the interior cutout, 0 = edge-to-edge). The extra
|
// screen edge (auto = frameThickness, aligning widgets with the interior cutout).
|
||||||
// beyond frameThickness is what an adjacent bar end adds on top of its corner alignment.
|
readonly property real _frameInsetResolved: SettingsData.frameBarContentGap
|
||||||
readonly property real _frameInsetResolved: SettingsData.frameBarInsetPadding < 0 ? SettingsData.frameThickness : SettingsData.frameBarInsetPadding
|
readonly property real _frameInsetExtra: SettingsData.frameBarContentGapExtra
|
||||||
readonly property real _frameInsetExtra: Math.max(0, _frameInsetResolved - SettingsData.frameThickness)
|
|
||||||
|
|
||||||
// Horizontal bars span the full width and own the corners; the perpendicular vertical bar
|
// Horizontal bars span the full width and own the corners; the perpendicular vertical bar
|
||||||
// tucks in below/above. Where they meet, inset the corner widget so it centres in the
|
// tucks in below/above. Where they meet, inset the corner widget so it centres in the
|
||||||
|
|||||||
@@ -609,7 +609,7 @@ Item {
|
|||||||
_closeHoverNotepad();
|
_closeHoverNotepad();
|
||||||
activeHoverTrigger = "";
|
activeHoverTrigger = "";
|
||||||
PopoutManager.dismissHoverPopoutForScreen(barWindow?.screen);
|
PopoutManager.dismissHoverPopoutForScreen(barWindow?.screen);
|
||||||
TrayMenuManager.closeAllMenus();
|
TrayMenuManager.closeHoverMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _beginSupersededCloseForActive() {
|
function _beginSupersededCloseForActive() {
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ BasePill {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.MiddleButton
|
acceptedButtons: Qt.MiddleButton
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: mouse => {
|
onPressed: mouse => {
|
||||||
root.triggerRipple(this, mouse.x, mouse.y);
|
root.triggerRipple(this, mouse.x, mouse.y);
|
||||||
SessionData.setDoNotDisturb(!SessionData.doNotDisturb);
|
SessionData.setDoNotDisturb(!SessionData.doNotDisturb);
|
||||||
|
|||||||
@@ -83,6 +83,22 @@ BasePill {
|
|||||||
root.showForTrayItem(trayItem, anchorItem, parentScreen, root.isAtBottom, root.isVerticalOrientation, root.axis);
|
root.showForTrayItem(trayItem, anchorItem, parentScreen, root.isAtBottom, root.isVerticalOrientation, root.axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: TrayMenuManager
|
||||||
|
|
||||||
|
function onOpenTrayMenuRequested() {
|
||||||
|
const request = TrayMenuManager.claimMenuRequest(root.parentScreen?.name);
|
||||||
|
if (!request)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const item = TrayMenuManager.findTrayItem(request.itemId);
|
||||||
|
if (!item || !item.hasMenu)
|
||||||
|
return;
|
||||||
|
|
||||||
|
root.showForTrayItem(item, root, parentScreen, root.isAtBottom, root.isVerticalOrientation, root.axis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openInlineTrayContextMenu(trayItem, areaItem, mouse, anchorItem) {
|
function openInlineTrayContextMenu(trayItem, areaItem, mouse, anchorItem) {
|
||||||
if (!trayItem) {
|
if (!trayItem) {
|
||||||
return;
|
return;
|
||||||
@@ -1484,6 +1500,7 @@ BasePill {
|
|||||||
property bool isVertical: false
|
property bool isVertical: false
|
||||||
property var axis: null
|
property var axis: null
|
||||||
property bool showMenu: false
|
property bool showMenu: false
|
||||||
|
property bool openedByHover: false
|
||||||
property var menuHandle: null
|
property var menuHandle: null
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
@@ -1493,7 +1510,8 @@ BasePill {
|
|||||||
return entryStack.count ? entryStack.get(entryStack.count - 1).handle : null;
|
return entryStack.count ? entryStack.get(entryStack.count - 1).handle : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showForTrayItem(item, anchor, screen, atBottom, vertical, axisObj) {
|
function showForTrayItem(item, anchor, screen, atBottom, vertical, axisObj, byHover) {
|
||||||
|
openedByHover = byHover === true;
|
||||||
trayItem = item;
|
trayItem = item;
|
||||||
anchorItem = anchor;
|
anchorItem = anchor;
|
||||||
parentScreen = screen;
|
parentScreen = screen;
|
||||||
@@ -2084,7 +2102,7 @@ BasePill {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showForTrayItem(item, anchor, screen, atBottom, vertical, axisObj) {
|
function showForTrayItem(item, anchor, screen, atBottom, vertical, axisObj, byHover) {
|
||||||
if (!screen)
|
if (!screen)
|
||||||
return;
|
return;
|
||||||
if (currentTrayMenu) {
|
if (currentTrayMenu) {
|
||||||
@@ -2099,7 +2117,7 @@ BasePill {
|
|||||||
currentTrayMenu = trayMenuComponent.createObject(null);
|
currentTrayMenu = trayMenuComponent.createObject(null);
|
||||||
if (!currentTrayMenu)
|
if (!currentTrayMenu)
|
||||||
return;
|
return;
|
||||||
currentTrayMenu.showForTrayItem(item, anchor, screen, atBottom, vertical ?? false, axisObj);
|
currentTrayMenu.showForTrayItem(item, anchor, screen, atBottom, vertical ?? false, axisObj, byHover === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _trayLayoutRoot() {
|
function _trayLayoutRoot() {
|
||||||
@@ -2147,7 +2165,7 @@ BasePill {
|
|||||||
if (!hit?.trayItem?.hasMenu)
|
if (!hit?.trayItem?.hasMenu)
|
||||||
return false;
|
return false;
|
||||||
const anchor = hit.children?.length > 0 ? hit.children[0] : hit;
|
const anchor = hit.children?.length > 0 ? hit.children[0] : hit;
|
||||||
showForTrayItem(hit.trayItem, anchor, parentScreen, isAtBottom, isVerticalOrientation, axis);
|
showForTrayItem(hit.trayItem, anchor, parentScreen, isAtBottom, isVerticalOrientation, axis, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: activePlayer?.trackAlbum || ""
|
text: MprisController.stableAlbum
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.surfaceTextSecondary
|
color: Theme.surfaceTextSecondary
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|||||||
@@ -21,11 +21,10 @@ QtObject {
|
|||||||
|
|
||||||
readonly property bool frameExclusionActive: CompositorService.frameWindowVisibleForScreen(screen)
|
readonly property bool frameExclusionActive: CompositorService.frameWindowVisibleForScreen(screen)
|
||||||
readonly property bool usesConnectedFrameChrome: CompositorService.usesConnectedFrameChromeForScreen(screen)
|
readonly property bool usesConnectedFrameChrome: CompositorService.usesConnectedFrameChromeForScreen(screen)
|
||||||
readonly property bool connectedBarActiveOnEdge: usesConnectedFrameChrome && !!screen && SettingsData.getActiveBarEdgesForScreen(screen).includes(edge)
|
|
||||||
|
|
||||||
readonly property real connectedJoinInset: {
|
readonly property real connectedJoinInset: {
|
||||||
if (usesConnectedFrameChrome)
|
if (usesConnectedFrameChrome)
|
||||||
return connectedBarActiveOnEdge ? SettingsData.frameBarSize : SettingsData.frameThickness;
|
return SettingsData.frameEdgeReservation(screen, edge);
|
||||||
if (frameExclusionActive)
|
if (frameExclusionActive)
|
||||||
return SettingsData.frameEdgeInsetForSide(screen, edge);
|
return SettingsData.frameEdgeInsetForSide(screen, edge);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function exclusionSizeForEdge(edge) {
|
function exclusionSizeForEdge(edge) {
|
||||||
return root.barEdges.includes(edge) ? SettingsData.frameBarSize : SettingsData.frameThickness;
|
return SettingsData.frameEdgeReservation(root.screen, edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
|
|||||||
@@ -262,10 +262,22 @@ PanelWindow {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property int cutoutTopInset: win._regionInt(barEdges.includes("top") ? SettingsData.frameBarSize : SettingsData.frameThickness)
|
readonly property int cutoutTopInset: {
|
||||||
readonly property int cutoutBottomInset: win._regionInt(barEdges.includes("bottom") ? SettingsData.frameBarSize : SettingsData.frameThickness)
|
SettingsData.barConfigs;
|
||||||
readonly property int cutoutLeftInset: win._regionInt(barEdges.includes("left") ? SettingsData.frameBarSize : SettingsData.frameThickness)
|
return win._regionInt(SettingsData.frameEdgeReservation(win.targetScreen, "top"));
|
||||||
readonly property int cutoutRightInset: win._regionInt(barEdges.includes("right") ? SettingsData.frameBarSize : SettingsData.frameThickness)
|
}
|
||||||
|
readonly property int cutoutBottomInset: {
|
||||||
|
SettingsData.barConfigs;
|
||||||
|
return win._regionInt(SettingsData.frameEdgeReservation(win.targetScreen, "bottom"));
|
||||||
|
}
|
||||||
|
readonly property int cutoutLeftInset: {
|
||||||
|
SettingsData.barConfigs;
|
||||||
|
return win._regionInt(SettingsData.frameEdgeReservation(win.targetScreen, "left"));
|
||||||
|
}
|
||||||
|
readonly property int cutoutRightInset: {
|
||||||
|
SettingsData.barConfigs;
|
||||||
|
return win._regionInt(SettingsData.frameEdgeReservation(win.targetScreen, "right"));
|
||||||
|
}
|
||||||
readonly property int cutoutWidth: Math.max(0, win._windowRegionWidth - win.cutoutLeftInset - win.cutoutRightInset)
|
readonly property int cutoutWidth: Math.max(0, win._windowRegionWidth - win.cutoutLeftInset - win.cutoutRightInset)
|
||||||
readonly property int cutoutHeight: Math.max(0, win._windowRegionHeight - win.cutoutTopInset - win.cutoutBottomInset)
|
readonly property int cutoutHeight: Math.max(0, win._windowRegionHeight - win.cutoutTopInset - win.cutoutBottomInset)
|
||||||
readonly property int cutoutRadius: {
|
readonly property int cutoutRadius: {
|
||||||
|
|||||||
@@ -66,9 +66,17 @@ Scope {
|
|||||||
IdleService.lockPowerOffRequested = false;
|
IdleService.lockPowerOffRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid startup lock when using dms-greeter (#2952)
|
||||||
|
function freshGreeterLogin() {
|
||||||
|
const authTime = Number(Quickshell.env("DMS_GREETER_AUTH_TIME") || 0);
|
||||||
|
if (!authTime)
|
||||||
|
return false;
|
||||||
|
return (Date.now() / 1000 - authTime) < 120;
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
IdleService.lockComponent = this;
|
IdleService.lockComponent = this;
|
||||||
if (SettingsData.lockAtStartup)
|
if (SettingsData.lockAtStartup && !freshGreeterLogin())
|
||||||
lock();
|
lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import qs.Services
|
|||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
import qs.DankCommon.Session
|
import qs.DankCommon.Session
|
||||||
import "../../DankCommon/Common/LayoutCodes.js" as LayoutCodes
|
import "../../DankCommon/Common/LayoutCodes.js" as LayoutCodes
|
||||||
|
import "../../Common/KeyUtils.js" as KeyUtils
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
@@ -98,6 +99,18 @@ Item {
|
|||||||
return !demoMode && pam && pam.u2f && pam.u2f.available && SettingsData.enableU2f && SettingsData.u2fMode === "or" && !pam.passwd.active && !pam.u2f.active && !pam.u2fPending && !root.unlocking;
|
return !demoMode && pam && pam.u2f && pam.u2f.available && SettingsData.enableU2f && SettingsData.u2fMode === "or" && !pam.passwd.active && !pam.u2f.active && !pam.u2fPending && !root.unlocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function triggerSecurityKeyUnlock() {
|
||||||
|
if (!canStartSecurityKeyUnlock())
|
||||||
|
return;
|
||||||
|
passwordField.clear();
|
||||||
|
pam.u2f.startForAlternativeAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
function securityKeyShortcutMatches(event) {
|
||||||
|
return SettingsData.lockScreenSecurityKeyShortcutEnabled
|
||||||
|
&& KeyUtils.eventMatchesCombo(event, SettingsData.lockScreenSecurityKeyShortcut);
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
WeatherService.addRef();
|
WeatherService.addRef();
|
||||||
UserInfoService.getUserInfo();
|
UserInfoService.getUserInfo();
|
||||||
@@ -932,7 +945,9 @@ Item {
|
|||||||
pam.passwd.start();
|
pam.passwd.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Keys.onPressed: event => {
|
Keys.onPressed: event => handleKey(event)
|
||||||
|
|
||||||
|
function handleKey(event) {
|
||||||
if (demoMode) {
|
if (demoMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -960,6 +975,12 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((event.modifiers & Qt.ControlModifier) && !(event.modifiers & (Qt.AltModifier | Qt.MetaModifier))) {
|
if ((event.modifiers & Qt.ControlModifier) && !(event.modifiers & (Qt.AltModifier | Qt.MetaModifier))) {
|
||||||
|
if (securityKeyShortcutMatches(event) && canStartSecurityKeyUnlock()) {
|
||||||
|
triggerSecurityKeyUnlock();
|
||||||
|
event.accepted = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case Qt.Key_A:
|
case Qt.Key_A:
|
||||||
cursorPosition = 0;
|
cursorPosition = 0;
|
||||||
@@ -1042,6 +1063,36 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wayland IMEs commit unconsumed printable keys as text-input text
|
||||||
|
// (ibus ibuswaylandim.c) instead of forwarding raw keys, so an active
|
||||||
|
// text input must exist to receive them; the hidden-text hints put
|
||||||
|
// fcitx5 into plain keyboard passthrough (CapabilityFlag::Password).
|
||||||
|
// Raw keys stay in handleKey (#2950).
|
||||||
|
TextInput {
|
||||||
|
id: imeCommitSink
|
||||||
|
|
||||||
|
focus: true
|
||||||
|
width: 1
|
||||||
|
height: 1
|
||||||
|
opacity: 0
|
||||||
|
echoMode: TextInput.Password
|
||||||
|
inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
|
||||||
|
Keys.onPressed: event => {
|
||||||
|
passwordField.handleKey(event);
|
||||||
|
if (!event.accepted && (event.modifiers & (Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier)))
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
onTextChanged: {
|
||||||
|
if (text.length === 0)
|
||||||
|
return;
|
||||||
|
const committed = text;
|
||||||
|
text = "";
|
||||||
|
if (demoMode || root.unlocking || pam.passwd.active)
|
||||||
|
return;
|
||||||
|
passwordField.insertText(committed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (!demoMode) {
|
if (!demoMode) {
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
@@ -1206,10 +1257,8 @@ Item {
|
|||||||
buttonSize: 32
|
buttonSize: 32
|
||||||
visible: root.canStartSecurityKeyUnlock()
|
visible: root.canStartSecurityKeyUnlock()
|
||||||
enabled: visible
|
enabled: visible
|
||||||
onClicked: {
|
tooltipText: SettingsData.lockScreenSecurityKeyShortcutEnabled ? I18n.tr("Security key (%1)", "lock screen security key button tooltip with shortcut").arg(SettingsData.lockScreenSecurityKeyShortcut) : I18n.tr("Security key", "lock screen security key button tooltip")
|
||||||
passwordField.clear();
|
onClicked: root.triggerSecurityKeyUnlock()
|
||||||
pam.u2f.startForAlternativeAuth();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DankActionButton {
|
DankActionButton {
|
||||||
id: virtualKeyboardButton
|
id: virtualKeyboardButton
|
||||||
@@ -1297,6 +1346,7 @@ Item {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height / 2
|
height: parent.height / 2
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
anchors.topMargin: -1
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
color: Theme.withAlpha(Theme.surfaceContainer, 0.9)
|
color: Theme.withAlpha(Theme.surfaceContainer, 0.9)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import qs.Services
|
|||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
import qs.Modules.Notepad
|
import qs.Modules.Notepad
|
||||||
|
|
||||||
FloatingWindow {
|
DankFloatingWindow {
|
||||||
id: win
|
id: win
|
||||||
|
|
||||||
property alias shouldBeVisible: win.visible
|
property alias shouldBeVisible: win.visible
|
||||||
@@ -27,7 +27,7 @@ FloatingWindow {
|
|||||||
minimumSize: Qt.size(360, 320)
|
minimumSize: Qt.size(360, 320)
|
||||||
implicitWidth: 640
|
implicitWidth: 640
|
||||||
implicitHeight: 760
|
implicitHeight: 760
|
||||||
color: Theme.surfaceContainer
|
surfaceColor: Theme.notepadWindowSurface
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
@@ -38,7 +38,6 @@ FloatingWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compositor close (e.g. niri close-window)
|
|
||||||
onClosed: win.visible = false
|
onClosed: win.visible = false
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
@@ -58,12 +57,6 @@ FloatingWindow {
|
|||||||
onDoubleClicked: windowControls.tryToggleMaximize()
|
onDoubleClicked: windowControls.tryToggleMaximize()
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
anchors.fill: parent
|
|
||||||
color: Theme.surfaceContainerHigh
|
|
||||||
opacity: 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: Theme.spacingM
|
anchors.leftMargin: Theme.spacingM
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ Item {
|
|||||||
anchors.leftMargin: -Theme.spacingM
|
anchors.leftMargin: -Theme.spacingM
|
||||||
width: parent.width + Theme.spacingM
|
width: parent.width + Theme.spacingM
|
||||||
text: I18n.tr("Surface Opacity")
|
text: I18n.tr("Surface Opacity")
|
||||||
description: I18n.tr("Override global transparency for Notepad")
|
description: I18n.tr("Override floating window transparency for Notepad")
|
||||||
checked: SettingsData.notepadTransparencyOverride >= 0
|
checked: SettingsData.notepadTransparencyOverride >= 0
|
||||||
onToggled: checked => {
|
onToggled: checked => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
@@ -370,7 +370,7 @@ Item {
|
|||||||
width: parent.width + Theme.spacingM
|
width: parent.width + Theme.spacingM
|
||||||
height: 24
|
height: 24
|
||||||
visible: SettingsData.notepadTransparencyOverride >= 0
|
visible: SettingsData.notepadTransparencyOverride >= 0
|
||||||
value: Math.round((SettingsData.notepadTransparencyOverride >= 0 ? SettingsData.notepadTransparencyOverride : SettingsData.popupTransparency) * 100)
|
value: Math.round(Theme.notepadTransparency * 100)
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 100
|
maximum: 100
|
||||||
unit: ""
|
unit: ""
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user