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