mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
clipboard: single disable + read-only history option
This commit is contained in:
@@ -142,8 +142,6 @@ var (
|
|||||||
clipConfigNoClearStartup bool
|
clipConfigNoClearStartup bool
|
||||||
clipConfigDisabled bool
|
clipConfigDisabled bool
|
||||||
clipConfigEnabled bool
|
clipConfigEnabled bool
|
||||||
clipConfigDisableHistory bool
|
|
||||||
clipConfigEnableHistory bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -167,10 +165,8 @@ func init() {
|
|||||||
clipConfigSetCmd.Flags().IntVar(&clipConfigAutoClearDays, "auto-clear-days", -1, "Auto-clear entries older than N days (0 to disable)")
|
clipConfigSetCmd.Flags().IntVar(&clipConfigAutoClearDays, "auto-clear-days", -1, "Auto-clear entries older than N days (0 to disable)")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigClearAtStartup, "clear-at-startup", false, "Clear history on startup")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigClearAtStartup, "clear-at-startup", false, "Clear history on startup")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigNoClearStartup, "no-clear-at-startup", false, "Don't clear history on startup")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigNoClearStartup, "no-clear-at-startup", false, "Don't clear history on startup")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisabled, "disable", false, "Disable clipboard manager entirely")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisabled, "disable", false, "Disable clipboard tracking")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard manager")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard tracking")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisableHistory, "disable-history", false, "Disable clipboard history persistence")
|
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnableHistory, "enable-history", false, "Enable clipboard history persistence")
|
|
||||||
|
|
||||||
clipWatchCmd.Flags().BoolVarP(&clipWatchStore, "store", "s", false, "Store clipboard changes to history (no server required)")
|
clipWatchCmd.Flags().BoolVarP(&clipWatchStore, "store", "s", false, "Store clipboard changes to history (no server required)")
|
||||||
|
|
||||||
@@ -587,12 +583,6 @@ func runClipConfigSet(cmd *cobra.Command, args []string) {
|
|||||||
if clipConfigEnabled {
|
if clipConfigEnabled {
|
||||||
params["disabled"] = false
|
params["disabled"] = false
|
||||||
}
|
}
|
||||||
if clipConfigDisableHistory {
|
|
||||||
params["disableHistory"] = true
|
|
||||||
}
|
|
||||||
if clipConfigEnableHistory {
|
|
||||||
params["disableHistory"] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params) == 0 {
|
if len(params) == 0 {
|
||||||
fmt.Println("No config options specified")
|
fmt.Println("No config options specified")
|
||||||
|
|||||||
@@ -205,9 +205,6 @@ func handleSetConfig(conn net.Conn, req models.Request, m *Manager) {
|
|||||||
if v, ok := req.Params["disabled"].(bool); ok {
|
if v, ok := req.Params["disabled"].(bool); ok {
|
||||||
cfg.Disabled = v
|
cfg.Disabled = v
|
||||||
}
|
}
|
||||||
if v, ok := req.Params["disableHistory"].(bool); ok {
|
|
||||||
cfg.DisableHistory = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.SetConfig(cfg); err != nil {
|
if err := m.SetConfig(cfg); err != nil {
|
||||||
models.RespondError(conn, req.ID, err.Error())
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ var sensitiveMimeTypes = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error) {
|
func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error) {
|
||||||
if config.Disabled {
|
|
||||||
return nil, fmt.Errorf("clipboard disabled in config")
|
|
||||||
}
|
|
||||||
|
|
||||||
display := wlCtx.Display()
|
display := wlCtx.Display()
|
||||||
dbPath, err := getDBPath()
|
dbPath, err := getDBPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -61,16 +57,17 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
|
|||||||
dbPath: dbPath,
|
dbPath: dbPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !config.Disabled {
|
||||||
if err := m.setupRegistry(); err != nil {
|
if err := m.setupRegistry(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m.notifierWg.Add(1)
|
m.notifierWg.Add(1)
|
||||||
go m.notifier()
|
go m.notifier()
|
||||||
|
|
||||||
go m.watchConfig()
|
go m.watchConfig()
|
||||||
|
|
||||||
if !config.DisableHistory {
|
|
||||||
db, err := openDB(dbPath)
|
db, err := openDB(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open db: %w", err)
|
return nil, fmt.Errorf("failed to open db: %w", err)
|
||||||
@@ -81,6 +78,7 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
|
|||||||
log.Errorf("Failed to migrate hashes: %v", err)
|
log.Errorf("Failed to migrate hashes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !config.Disabled {
|
||||||
if config.ClearAtStartup {
|
if config.ClearAtStartup {
|
||||||
if err := m.clearHistoryInternal(); err != nil {
|
if err := m.clearHistoryInternal(); err != nil {
|
||||||
log.Errorf("Failed to clear history at startup: %v", err)
|
log.Errorf("Failed to clear history at startup: %v", err)
|
||||||
@@ -97,7 +95,7 @@ func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error)
|
|||||||
m.alive = true
|
m.alive = true
|
||||||
m.updateState()
|
m.updateState()
|
||||||
|
|
||||||
if m.dataControlMgr != nil && m.seat != nil {
|
if !config.Disabled && m.dataControlMgr != nil && m.seat != nil {
|
||||||
m.setupDataDeviceSync()
|
m.setupDataDeviceSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +324,7 @@ func (m *Manager) readAndStore(r *os.File, mimeType string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.DisableHistory && m.db != nil {
|
if !cfg.Disabled && m.db != nil {
|
||||||
m.storeClipboardEntry(data, mimeType)
|
m.storeClipboardEntry(data, mimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,23 +1209,13 @@ func (m *Manager) applyConfigChange(newCfg Config) {
|
|||||||
m.config = newCfg
|
m.config = newCfg
|
||||||
m.configMutex.Unlock()
|
m.configMutex.Unlock()
|
||||||
|
|
||||||
if newCfg.DisableHistory && !oldCfg.DisableHistory && m.db != nil {
|
switch {
|
||||||
log.Info("Clipboard history disabled, closing database")
|
case newCfg.Disabled && !oldCfg.Disabled:
|
||||||
m.db.Close()
|
log.Info("Clipboard tracking disabled")
|
||||||
m.db = nil
|
case !newCfg.Disabled && oldCfg.Disabled:
|
||||||
|
log.Info("Clipboard tracking enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !newCfg.DisableHistory && oldCfg.DisableHistory && m.db == nil {
|
|
||||||
log.Info("Clipboard history enabled, opening database")
|
|
||||||
if db, err := openDB(m.dbPath); err == nil {
|
|
||||||
m.db = db
|
|
||||||
} else {
|
|
||||||
log.Errorf("Failed to reopen database: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Clipboard config reloaded: disableHistory=%v", newCfg.DisableHistory)
|
|
||||||
|
|
||||||
m.updateState()
|
m.updateState()
|
||||||
m.notifySubscribers()
|
m.notifySubscribers()
|
||||||
}
|
}
|
||||||
@@ -1235,8 +1223,8 @@ func (m *Manager) applyConfigChange(newCfg Config) {
|
|||||||
func (m *Manager) StoreData(data []byte, mimeType string) error {
|
func (m *Manager) StoreData(data []byte, mimeType string) error {
|
||||||
cfg := m.getConfig()
|
cfg := m.getConfig()
|
||||||
|
|
||||||
if cfg.DisableHistory {
|
if cfg.Disabled {
|
||||||
return fmt.Errorf("clipboard history disabled")
|
return fmt.Errorf("clipboard tracking disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.db == nil {
|
if m.db == nil {
|
||||||
|
|||||||
@@ -457,7 +457,6 @@ func TestDefaultConfig(t *testing.T) {
|
|||||||
assert.Equal(t, 0, cfg.AutoClearDays)
|
assert.Equal(t, 0, cfg.AutoClearDays)
|
||||||
assert.False(t, cfg.ClearAtStartup)
|
assert.False(t, cfg.ClearAtStartup)
|
||||||
assert.False(t, cfg.Disabled)
|
assert.False(t, cfg.Disabled)
|
||||||
assert.False(t, cfg.DisableHistory)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManager_PostDelegatesToWlContext(t *testing.T) {
|
func TestManager_PostDelegatesToWlContext(t *testing.T) {
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ type Config struct {
|
|||||||
MaxEntrySize int64 `json:"maxEntrySize"`
|
MaxEntrySize int64 `json:"maxEntrySize"`
|
||||||
AutoClearDays int `json:"autoClearDays"`
|
AutoClearDays int `json:"autoClearDays"`
|
||||||
ClearAtStartup bool `json:"clearAtStartup"`
|
ClearAtStartup bool `json:"clearAtStartup"`
|
||||||
|
|
||||||
Disabled bool `json:"disabled"`
|
Disabled bool `json:"disabled"`
|
||||||
DisableHistory bool `json:"disableHistory"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() Config {
|
func DefaultConfig() Config {
|
||||||
|
|||||||
@@ -207,9 +207,6 @@ func handleClipboardSetConfig(conn net.Conn, req models.Request) {
|
|||||||
if v, ok := req.Params["disabled"].(bool); ok {
|
if v, ok := req.Params["disabled"].(bool); ok {
|
||||||
cfg.Disabled = v
|
cfg.Disabled = v
|
||||||
}
|
}
|
||||||
if v, ok := req.Params["disableHistory"].(bool); ok {
|
|
||||||
cfg.DisableHistory = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := clipboard.SaveConfig(cfg); err != nil {
|
if err := clipboard.SaveConfig(cfg); err != nil {
|
||||||
models.RespondError(conn, req.ID, err.Error())
|
models.RespondError(conn, req.ID, err.Error())
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ DankModal {
|
|||||||
property Component clipboardContent
|
property Component clipboardContent
|
||||||
property int activeImageLoads: 0
|
property int activeImageLoads: 0
|
||||||
readonly property int maxConcurrentLoads: 3
|
readonly property int maxConcurrentLoads: 3
|
||||||
readonly property bool clipboardAvailable: DMSService.isConnected && DMSService.capabilities.includes("clipboard")
|
readonly property bool clipboardAvailable: DMSService.isConnected && (DMSService.capabilities.length === 0 || DMSService.capabilities.includes("clipboard"))
|
||||||
property bool wtypeAvailable: false
|
property bool wtypeAvailable: false
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
|
|||||||
@@ -324,24 +324,14 @@ Item {
|
|||||||
expanded: false
|
expanded: false
|
||||||
visible: configLoaded
|
visible: configLoaded
|
||||||
|
|
||||||
SettingsToggleRow {
|
|
||||||
tab: "clipboard"
|
|
||||||
tags: ["clipboard", "disable", "manager"]
|
|
||||||
settingKey: "disabled"
|
|
||||||
text: I18n.tr("Disable Clipboard Manager")
|
|
||||||
description: I18n.tr("Disable clipboard manager entirely (requires restart)")
|
|
||||||
checked: root.config.disabled ?? false
|
|
||||||
onToggled: checked => root.saveConfig("disabled", checked)
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingsToggleRow {
|
SettingsToggleRow {
|
||||||
tab: "clipboard"
|
tab: "clipboard"
|
||||||
tags: ["clipboard", "disable", "history"]
|
tags: ["clipboard", "disable", "history"]
|
||||||
settingKey: "disableHistory"
|
settingKey: "disabled"
|
||||||
text: I18n.tr("Disable History Persistence")
|
text: I18n.tr("Disable History Persistence")
|
||||||
description: I18n.tr("Clipboard works but nothing saved to disk")
|
description: I18n.tr("Clipboard works but nothing saved to disk")
|
||||||
checked: root.config.disableHistory ?? false
|
checked: root.config.disabled ?? false
|
||||||
onToggled: checked => root.saveConfig("disableHistory", checked)
|
onToggled: checked => root.saveConfig("disabled", checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user