fixed some clipurr issues
This commit is contained in:
parent
0b19f47483
commit
1da85e522d
1 changed files with 12 additions and 8 deletions
|
@ -1,11 +1,10 @@
|
|||
import ../../globurrl
|
||||
import std/[strutils,os,db_sqlite,osproc]
|
||||
|
||||
const CLIP_DB = WM_TOOLS_DIR & ".clipurr_cache.sqlite"
|
||||
const CLIP_DB = WM_TOOLS_DIR & "clipurr_cache.sqlite"
|
||||
const KEEP_ITEMS = 20
|
||||
|
||||
proc openDBConn(): DBConn
|
||||
let db = openDBConn()
|
||||
|
||||
proc addClip(str: var string)
|
||||
|
||||
|
@ -45,9 +44,8 @@ proc openDBConn(): DBConn =
|
|||
return db
|
||||
|
||||
proc clearHistory() =
|
||||
# let db = openDBConn()
|
||||
let db = openDBConn()
|
||||
|
||||
defer: db.close()
|
||||
try:
|
||||
db.exec(sql"drop table if exists clip_items")
|
||||
except:
|
||||
|
@ -56,8 +54,9 @@ proc clearHistory() =
|
|||
proc maintainDB() =
|
||||
return # order by and offset doesn't work unless certain sqlite compile time options set
|
||||
# will create a different way to do this
|
||||
let db = openDBConn()
|
||||
try:
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
db.exec(sql"""BEGIN""")
|
||||
db.exec(sql"delete from clip_items order by timestamp desc offset ?", KEEP_ITEMS)
|
||||
db.exec(sql"""COMMIT""")
|
||||
|
@ -67,6 +66,7 @@ proc maintainDB() =
|
|||
proc escapeClip(str: string): string =
|
||||
var clip = str
|
||||
clip = clip.replace("`","\\`")
|
||||
clip = clip.replace("\\n`","\\\\n`")
|
||||
clip = escape(clip)
|
||||
return strip(clip)
|
||||
|
||||
|
@ -82,8 +82,9 @@ proc unescapeClip(str: string): string =
|
|||
proc readClipFile(): seq[string] =
|
||||
var clips: seq[string] = @[]
|
||||
# let db = openDBConn()
|
||||
defer: db.close()
|
||||
try:
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
for row in db.fastRows(sql"select distinct(clip) from clip_items order by timestamp desc LIMIT ?", KEEP_ITEMS):
|
||||
var str = unescapeClip(row[0])
|
||||
clips.add(str)
|
||||
|
@ -98,12 +99,15 @@ proc addClip(str: var string) =
|
|||
var t = str[1..3]
|
||||
echo "Is a ", $t, " file , not storing"
|
||||
str = "[" & t & " Image] (not stored)"
|
||||
defer: db.close()
|
||||
try:
|
||||
str = escapeClip(str)
|
||||
echo "clipboard content : ", str
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
db.exec(sql"""BEGIN""")
|
||||
db.exec(sql"""insert into clip_items (timestamp, clip)
|
||||
values (CURRENT_TIMESTAMP, ?)
|
||||
""", escapeClip(str))
|
||||
""", str)
|
||||
db.exec(sql"""COMMIT""")
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
|
Loading…
Reference in a new issue