changed cache location to be local hdd rather than nextcloud

This commit is contained in:
Paul Wilde 2022-08-26 08:47:40 +01:00
parent 72f27e56db
commit 0b19f47483
6 changed files with 1577 additions and 5 deletions

View file

@ -4,6 +4,9 @@ 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
let db = openDBConn()
proc addClip(str: var string) proc addClip(str: var string)
proc killOldRunningProcesses() = proc killOldRunningProcesses() =
@ -42,7 +45,8 @@ proc openDBConn(): DBConn =
return db return db
proc clearHistory() = proc clearHistory() =
let db = openDBConn() # let db = openDBConn()
defer: db.close() defer: db.close()
try: try:
db.exec(sql"drop table if exists clip_items") db.exec(sql"drop table if exists clip_items")
@ -50,6 +54,8 @@ proc clearHistory() =
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()
proc maintainDB() = 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() let db = openDBConn()
try: try:
db.exec(sql"""BEGIN""") db.exec(sql"""BEGIN""")
@ -75,10 +81,10 @@ 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() defer: db.close()
try: try:
for row in db.fastRows(sql"select distinct(clip) from clip_items order by timestamp desc"): 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)
except: except:
@ -92,7 +98,6 @@ 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)"
let db = openDBConn()
defer: db.close() defer: db.close()
try: try:
db.exec(sql"""BEGIN""") db.exec(sql"""BEGIN""")

View file

@ -34,7 +34,7 @@ type
x*: int x*: int
y*: int y*: int
const WM_TOOLS_DIR* = getHomeDir() & "Nextcloud/.wm_tools/" const WM_TOOLS_DIR* = getHomeDir() & ".wm_tools/"
const background* = "#000000" const background* = "#000000"
const backgroundalt* = "#bb222222" const backgroundalt* = "#bb222222"
const backgroundalt2* = "#bb333333" const backgroundalt2* = "#bb333333"

1567
i3-tree-example.txt Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.