mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
clipboard: remove ownership option
This commit is contained in:
@@ -144,8 +144,6 @@ var (
|
|||||||
clipConfigEnabled bool
|
clipConfigEnabled bool
|
||||||
clipConfigDisableHistory bool
|
clipConfigDisableHistory bool
|
||||||
clipConfigEnableHistory bool
|
clipConfigEnableHistory bool
|
||||||
clipConfigDisablePersist bool
|
|
||||||
clipConfigEnablePersist bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -173,8 +171,6 @@ func init() {
|
|||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard manager")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnabled, "enable", false, "Enable clipboard manager")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisableHistory, "disable-history", false, "Disable clipboard history persistence")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisableHistory, "disable-history", false, "Disable clipboard history persistence")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnableHistory, "enable-history", false, "Enable clipboard history persistence")
|
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnableHistory, "enable-history", false, "Enable clipboard history persistence")
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigDisablePersist, "disable-persist", false, "Disable clipboard ownership persistence")
|
|
||||||
clipConfigSetCmd.Flags().BoolVar(&clipConfigEnablePersist, "enable-persist", false, "Enable clipboard ownership 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)")
|
||||||
|
|
||||||
@@ -597,12 +593,6 @@ func runClipConfigSet(cmd *cobra.Command, args []string) {
|
|||||||
if clipConfigEnableHistory {
|
if clipConfigEnableHistory {
|
||||||
params["disableHistory"] = false
|
params["disableHistory"] = false
|
||||||
}
|
}
|
||||||
if clipConfigDisablePersist {
|
|
||||||
params["disablePersist"] = true
|
|
||||||
}
|
|
||||||
if clipConfigEnablePersist {
|
|
||||||
params["disablePersist"] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params) == 0 {
|
if len(params) == 0 {
|
||||||
fmt.Println("No config options specified")
|
fmt.Println("No config options specified")
|
||||||
|
|||||||
@@ -208,9 +208,6 @@ func handleSetConfig(conn net.Conn, req models.Request, m *Manager) {
|
|||||||
if v, ok := req.Params["disableHistory"].(bool); ok {
|
if v, ok := req.Params["disableHistory"].(bool); ok {
|
||||||
cfg.DisableHistory = v
|
cfg.DisableHistory = v
|
||||||
}
|
}
|
||||||
if v, ok := req.Params["disablePersist"].(bool); ok {
|
|
||||||
cfg.DisablePersist = 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())
|
||||||
|
|||||||
@@ -319,10 +319,6 @@ func (m *Manager) readAndStore(r *os.File, mimeType string) {
|
|||||||
m.storeClipboardEntry(data, mimeType)
|
m.storeClipboardEntry(data, mimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.DisablePersist {
|
|
||||||
m.persistClipboard([]string{mimeType}, map[string][]byte{mimeType: data})
|
|
||||||
}
|
|
||||||
|
|
||||||
m.updateState()
|
m.updateState()
|
||||||
m.notifySubscribers()
|
m.notifySubscribers()
|
||||||
}
|
}
|
||||||
@@ -348,105 +344,6 @@ func (m *Manager) storeClipboardEntry(data []byte, mimeType string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) persistClipboard(mimeTypes []string, data map[string][]byte) {
|
|
||||||
m.persistMutex.Lock()
|
|
||||||
m.persistMimeTypes = mimeTypes
|
|
||||||
m.persistData = data
|
|
||||||
m.persistMutex.Unlock()
|
|
||||||
|
|
||||||
m.post(func() {
|
|
||||||
m.takePersistOwnership()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) takePersistOwnership() {
|
|
||||||
if m.dataControlMgr == nil || m.dataDevice == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if m.getConfig().DisablePersist {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.persistMutex.RLock()
|
|
||||||
mimeTypes := m.persistMimeTypes
|
|
||||||
m.persistMutex.RUnlock()
|
|
||||||
|
|
||||||
if len(mimeTypes) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dataMgr := m.dataControlMgr.(*ext_data_control.ExtDataControlManagerV1)
|
|
||||||
|
|
||||||
source, err := dataMgr.CreateDataSource()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to create persist source: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, mime := range mimeTypes {
|
|
||||||
if err := source.Offer(mime); err != nil {
|
|
||||||
log.Errorf("Failed to offer mime type %s: %v", mime, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
source.SetSendHandler(func(e ext_data_control.ExtDataControlSourceV1SendEvent) {
|
|
||||||
fd := e.Fd
|
|
||||||
defer syscall.Close(fd)
|
|
||||||
|
|
||||||
m.persistMutex.RLock()
|
|
||||||
d := m.persistData[e.MimeType]
|
|
||||||
m.persistMutex.RUnlock()
|
|
||||||
|
|
||||||
if len(d) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
file := os.NewFile(uintptr(fd), "clipboard-pipe")
|
|
||||||
defer file.Close()
|
|
||||||
file.Write(d)
|
|
||||||
})
|
|
||||||
|
|
||||||
source.SetCancelledHandler(func(e ext_data_control.ExtDataControlSourceV1CancelledEvent) {
|
|
||||||
m.ownerLock.Lock()
|
|
||||||
m.isOwner = false
|
|
||||||
m.ownerLock.Unlock()
|
|
||||||
})
|
|
||||||
|
|
||||||
if m.currentSource != nil {
|
|
||||||
oldSource := m.currentSource.(*ext_data_control.ExtDataControlSourceV1)
|
|
||||||
oldSource.Destroy()
|
|
||||||
}
|
|
||||||
m.currentSource = source
|
|
||||||
|
|
||||||
device := m.dataDevice.(*ext_data_control.ExtDataControlDeviceV1)
|
|
||||||
if err := device.SetSelection(source); err != nil {
|
|
||||||
log.Errorf("Failed to set persist selection: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.ownerLock.Lock()
|
|
||||||
m.isOwner = true
|
|
||||||
m.ownerLock.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) releaseOwnership() {
|
|
||||||
m.ownerLock.Lock()
|
|
||||||
m.isOwner = false
|
|
||||||
m.ownerLock.Unlock()
|
|
||||||
|
|
||||||
m.persistMutex.Lock()
|
|
||||||
m.persistData = nil
|
|
||||||
m.persistMimeTypes = nil
|
|
||||||
m.persistMutex.Unlock()
|
|
||||||
|
|
||||||
if m.currentSource != nil {
|
|
||||||
source := m.currentSource.(*ext_data_control.ExtDataControlSourceV1)
|
|
||||||
source.Destroy()
|
|
||||||
m.currentSource = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) storeEntry(entry Entry) error {
|
func (m *Manager) storeEntry(entry Entry) error {
|
||||||
if m.db == nil {
|
if m.db == nil {
|
||||||
return fmt.Errorf("database not available")
|
return fmt.Errorf("database not available")
|
||||||
@@ -495,6 +392,9 @@ func (m *Manager) deduplicateInTx(b *bolt.Bucket, hash uint64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) trimLengthInTx(b *bolt.Bucket) error {
|
func (m *Manager) trimLengthInTx(b *bolt.Bucket) error {
|
||||||
|
if m.config.MaxHistory < 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
c := b.Cursor()
|
c := b.Cursor()
|
||||||
var count int
|
var count int
|
||||||
for k, _ := c.Last(); k != nil; k, _ = c.Prev() {
|
for k, _ := c.Last(); k != nil; k, _ = c.Prev() {
|
||||||
@@ -1309,13 +1209,7 @@ func (m *Manager) applyConfigChange(newCfg Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if newCfg.DisablePersist && !oldCfg.DisablePersist {
|
log.Infof("Clipboard config reloaded: disableHistory=%v", newCfg.DisableHistory)
|
||||||
log.Info("Clipboard persist disabled, releasing ownership")
|
|
||||||
m.releaseOwnership()
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Clipboard config reloaded: disableHistory=%v disablePersist=%v",
|
|
||||||
newCfg.DisableHistory, newCfg.DisablePersist)
|
|
||||||
|
|
||||||
m.updateState()
|
m.updateState()
|
||||||
m.notifySubscribers()
|
m.notifySubscribers()
|
||||||
|
|||||||
@@ -458,7 +458,6 @@ func TestDefaultConfig(t *testing.T) {
|
|||||||
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)
|
assert.False(t, cfg.DisableHistory)
|
||||||
assert.True(t, cfg.DisablePersist)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManager_PostDelegatesToWlContext(t *testing.T) {
|
func TestManager_PostDelegatesToWlContext(t *testing.T) {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type Config struct {
|
|||||||
|
|
||||||
Disabled bool `json:"disabled"`
|
Disabled bool `json:"disabled"`
|
||||||
DisableHistory bool `json:"disableHistory"`
|
DisableHistory bool `json:"disableHistory"`
|
||||||
DisablePersist bool `json:"disablePersist"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() Config {
|
func DefaultConfig() Config {
|
||||||
@@ -30,7 +29,6 @@ func DefaultConfig() Config {
|
|||||||
MaxEntrySize: 5 * 1024 * 1024,
|
MaxEntrySize: 5 * 1024 * 1024,
|
||||||
AutoClearDays: 0,
|
AutoClearDays: 0,
|
||||||
ClearAtStartup: false,
|
ClearAtStartup: false,
|
||||||
DisablePersist: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,9 +204,6 @@ func handleClipboardSetConfig(conn net.Conn, req models.Request) {
|
|||||||
if v, ok := req.Params["disableHistory"].(bool); ok {
|
if v, ok := req.Params["disableHistory"].(bool); ok {
|
||||||
cfg.DisableHistory = v
|
cfg.DisableHistory = v
|
||||||
}
|
}
|
||||||
if v, ok := req.Params["disablePersist"].(bool); ok {
|
|
||||||
cfg.DisablePersist = 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())
|
||||||
|
|||||||
@@ -34,8 +34,36 @@ Item {
|
|||||||
value: 500
|
value: 500
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "1000",
|
text: "1,000",
|
||||||
value: 1000
|
value: 1000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "10,000",
|
||||||
|
value: 10000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "15,000",
|
||||||
|
value: 15000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "20,000",
|
||||||
|
value: 20000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "30,000",
|
||||||
|
value: 30000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "50,000",
|
||||||
|
value: 50000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "100,000",
|
||||||
|
value: 100000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "∞",
|
||||||
|
value: -1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -98,11 +126,13 @@ Item {
|
|||||||
]
|
]
|
||||||
|
|
||||||
function getMaxHistoryText(value) {
|
function getMaxHistoryText(value) {
|
||||||
|
if (value <= 0)
|
||||||
|
return "∞";
|
||||||
for (let opt of maxHistoryOptions) {
|
for (let opt of maxHistoryOptions) {
|
||||||
if (opt.value === value)
|
if (opt.value === value)
|
||||||
return opt.text;
|
return opt.text;
|
||||||
}
|
}
|
||||||
return String(value);
|
return value.toLocaleString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMaxEntrySizeText(value) {
|
function getMaxEntrySizeText(value) {
|
||||||
@@ -312,16 +342,6 @@ Item {
|
|||||||
checked: root.config.disableHistory ?? false
|
checked: root.config.disableHistory ?? false
|
||||||
onToggled: checked => root.saveConfig("disableHistory", checked)
|
onToggled: checked => root.saveConfig("disableHistory", checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsToggleRow {
|
|
||||||
tab: "clipboard"
|
|
||||||
tags: ["clipboard", "disable", "persist", "ownership"]
|
|
||||||
settingKey: "disablePersist"
|
|
||||||
text: I18n.tr("Disable Clipboard Ownership")
|
|
||||||
description: I18n.tr("Don't preserve clipboard when apps close")
|
|
||||||
checked: root.config.disablePersist ?? true
|
|
||||||
onToggled: checked => root.saveConfig("disablePersist", checked)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user