cache and clear
This commit is contained in:
1 parent
ca9047901a
commit
9472f380be
10 files changed
+110
-67
No files matched your search
+1
-2
@@ -43,9 +43,8 @@
|
||||
"INTRO_MESSAGE": "It's gettin' Flox in here"
|
||||
},
|
||||
"hook": {
|
||||
"on-activate": " export NIXPKGS_QT6_QML_IMPORT_PATH=\"$FLOX_ENV/lib/qt-6/qml${NIXPKGS_QT6_QML_IMPORT_PATH:+:$NIXPKGS_QT6_QML_IMPORT_PATH}\"\n export QTWEBENGINEPROCESS_PATH=\"$FLOX_ENV/libexec/QtWebEngineProcess\"\n export SKYG_APP_CAROUSEL=$FLOX_ENV_PROJECT/example.json\n"
|
||||
"on-activate": " export NIXPKGS_QT6_QML_IMPORT_PATH=\"$FLOX_ENV/lib/qt-6/qml${NIXPKGS_QT6_QML_IMPORT_PATH:+:$NIXPKGS_QT6_QML_IMPORT_PATH}\"\n export QTWEBENGINEPROCESS_PATH=\"$FLOX_ENV/libexec/QtWebEngineProcess\"\n export SKYG_APP_CAROUSEL=$FLOX_ENV_PROJECT/example.json\n alias skygqts = $FLOX_ENV_PROJECT/skygqts.nu\n"
|
||||
},
|
||||
"profile": {},
|
||||
"options": {}
|
||||
},
|
||||
"packages": [
|
||||
|
||||
Vendored
+1
-61
@@ -35,65 +35,5 @@ on-activate = '''
|
||||
export NIXPKGS_QT6_QML_IMPORT_PATH="$FLOX_ENV/lib/qt-6/qml${NIXPKGS_QT6_QML_IMPORT_PATH:+:$NIXPKGS_QT6_QML_IMPORT_PATH}"
|
||||
export QTWEBENGINEPROCESS_PATH="$FLOX_ENV/libexec/QtWebEngineProcess"
|
||||
export SKYG_APP_CAROUSEL=$FLOX_ENV_PROJECT/example.json
|
||||
alias skygqts = $FLOX_ENV_PROJECT/skygqts.nu
|
||||
'''
|
||||
|
||||
|
||||
## Profile script ----------------------------------------------------
|
||||
## ... sourced by _your shell_ when you run 'flox activate'.
|
||||
## -------------------------------------------------------------------
|
||||
[profile]
|
||||
# common = '''
|
||||
# gum style \
|
||||
# --foreground 212 --border-foreground 212 --border double \
|
||||
# --align center --width 50 --margin "1 2" --padding "2 4" \
|
||||
# $INTRO_MESSAGE
|
||||
# '''
|
||||
## Shell-specific customizations such as setting aliases go here:
|
||||
# bash = ...
|
||||
# zsh = ...
|
||||
# fish = ...
|
||||
|
||||
|
||||
## Services ---------------------------------------------------------
|
||||
## $ flox services start <- Starts all services
|
||||
## $ flox services status <- Status of running services
|
||||
## $ flox activate --start-services <- Activates & starts all
|
||||
## ------------------------------------------------------------------
|
||||
[services]
|
||||
# myservice.command = "python3 -m http.server"
|
||||
|
||||
|
||||
## Include ----------------------------------------------------------
|
||||
## ... environments to create a composed environment
|
||||
## ------------------------------------------------------------------
|
||||
[include]
|
||||
# environments = [
|
||||
# { dir = "../common" }
|
||||
# ]
|
||||
|
||||
|
||||
## Build and publish your own packages ------------------------------
|
||||
## $ flox build
|
||||
## $ flox publish
|
||||
## ------------------------------------------------------------------
|
||||
[build]
|
||||
# [build.myproject]
|
||||
# description = "The coolest project ever"
|
||||
# version = "0.0.1"
|
||||
# command = """
|
||||
# mkdir -p $out/bin
|
||||
# cargo build --release
|
||||
# cp target/release/myproject $out/bin/myproject
|
||||
# """
|
||||
|
||||
|
||||
## Other Environment Options -----------------------------------------
|
||||
[options]
|
||||
# Systems that environment is compatible with
|
||||
# systems = [
|
||||
# "aarch64-darwin",
|
||||
# "aarch64-linux",
|
||||
# "x86_64-linux",
|
||||
# ]
|
||||
# Uncomment to disable CUDA detection.
|
||||
# cuda-detection = false
|
||||
@@ -8,6 +8,7 @@ Rectangle {
|
||||
required property var theme
|
||||
required property var app
|
||||
required property bool selected
|
||||
required property bool enableCacheFolder
|
||||
|
||||
signal activated
|
||||
|
||||
@@ -19,6 +20,12 @@ Rectangle {
|
||||
border.color: selected ? theme.selectedBorder : theme.cardBorder
|
||||
clip: true
|
||||
|
||||
HttpImageCache {
|
||||
id: httpCache
|
||||
url: root.app.isIcon ? "" : String(root.app.image)
|
||||
cacheEnabled: root.enableCacheFolder
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
spacing: 10
|
||||
width: root.theme.cardWidth
|
||||
@@ -30,9 +37,9 @@ Rectangle {
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
source: root.app.isIcon ? Quickshell.iconPath(root.app.image) : root.app.image
|
||||
sourceSize.width: root.app.isIcon ? root.app.dims[0] : undefined
|
||||
sourceSize.height: root.app.isIcon ? root.app.dims[1] : undefined
|
||||
source: root.app.isIcon ? Quickshell.iconPath(root.app.image) : httpCache.source
|
||||
sourceSize.width: root.app.isIcon ? root.app.dims[0] : 0
|
||||
sourceSize.height: root.app.isIcon ? root.app.dims[1] : 0
|
||||
}
|
||||
Text {
|
||||
id: label
|
||||
|
||||
@@ -7,6 +7,7 @@ Item {
|
||||
|
||||
readonly property string appConfigPath: Quickshell.env("SKYG_APP_CAROUSEL")
|
||||
property list<var> appConfig: []
|
||||
property bool enableCacheFolder: false
|
||||
|
||||
FileView {
|
||||
id: configFile
|
||||
@@ -27,12 +28,27 @@ Item {
|
||||
}
|
||||
const isBoolean = isOf('boolean')
|
||||
const isString = isOf('string')
|
||||
const resolveImagePath = (image) => {
|
||||
if (image.startsWith('http://') || image.startsWith('https://') || image.startsWith('file://'))
|
||||
return image
|
||||
let path = image
|
||||
if (path.startsWith('~/'))
|
||||
path = Quickshell.env('HOME') + path.slice(1)
|
||||
if (!path.startsWith('/')) {
|
||||
const cfg = root.appConfigPath
|
||||
const i = cfg.lastIndexOf('/')
|
||||
path = (i >= 0 ? cfg.substring(0, i) : '.') + '/' + path
|
||||
}
|
||||
return 'file://' + path
|
||||
}
|
||||
let parsed = JSON.parse(configFile.text());
|
||||
let apps = parsed.apps;
|
||||
if (!Array.isArray(apps)) {
|
||||
throw new Error(`Invalid app config: expected a JSON array, got ${typeof apps}`);
|
||||
}
|
||||
isBoolean('autoStart', parsed.autoStart, true)
|
||||
isBoolean('enableCacheFolder', parsed.enableCacheFolder, true)
|
||||
root.enableCacheFolder = !!parsed.enableCacheFolder
|
||||
for (const elm of apps) {
|
||||
isString('name', elm.name)
|
||||
isString('image', elm.image)
|
||||
@@ -47,6 +63,8 @@ Item {
|
||||
}
|
||||
testIt(Array.isArray(elm.exec) && elm.exec.length > 0, `expected exec to be a non-empty array, got ${elm.exec}`)
|
||||
testIt(elm.exec.every(arg => typeof arg === 'string'), 'expected all exec entries to be strings')
|
||||
if (!elm.isIcon)
|
||||
elm.image = resolveImagePath(elm.image)
|
||||
}
|
||||
console.log("Loaded Config", configFile.__data);
|
||||
root.appConfig = apps;
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property string url
|
||||
required property bool cacheEnabled
|
||||
|
||||
property string source: url
|
||||
property string dest: ""
|
||||
|
||||
readonly property string cacheDir: Quickshell.env("HOME") + "/.config/skygqts/carousel-image-cache"
|
||||
|
||||
function cachePathFor(imageUrl) {
|
||||
let h = 5381
|
||||
for (let i = 0; i < imageUrl.length; i++)
|
||||
h = ((h << 5) + h) + imageUrl.charCodeAt(i)
|
||||
h = h >>> 0
|
||||
const m = imageUrl.match(/\.([A-Za-z0-9]+)(?:[?#]|$)/)
|
||||
let ext = m ? m[1].toLowerCase() : "img"
|
||||
if (ext === "jpeg")
|
||||
ext = "jpg"
|
||||
const allowed = ["png", "jpg", "gif", "webp", "svg", "ico", "bmp"]
|
||||
if (allowed.indexOf(ext) < 0)
|
||||
ext = "img"
|
||||
return root.cacheDir + "/" + h.toString(16) + "." + ext
|
||||
}
|
||||
|
||||
function isHttp(s) {
|
||||
return s.startsWith("http://") || s.startsWith("https://")
|
||||
}
|
||||
|
||||
function start() {
|
||||
root.source = root.url
|
||||
check.running = false
|
||||
downloader.running = false
|
||||
if (!root.cacheEnabled || !root.url || !isHttp(root.url))
|
||||
return
|
||||
root.dest = cachePathFor(root.url)
|
||||
check.running = true
|
||||
}
|
||||
|
||||
Component.onCompleted: start()
|
||||
onUrlChanged: start()
|
||||
onCacheEnabledChanged: start()
|
||||
|
||||
Process {
|
||||
id: check
|
||||
command: ["test", "-f", root.dest]
|
||||
onExited: code => {
|
||||
if (code === 0)
|
||||
root.source = "file://" + root.dest
|
||||
else
|
||||
downloader.running = true
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: downloader
|
||||
command: ["curl", "-fsSL", "--create-dirs", "-o", root.dest, root.url]
|
||||
onExited: code => {
|
||||
if (code === 0)
|
||||
root.source = "file://" + root.dest
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ PanelWindow {
|
||||
|
||||
required property bool shellOpen
|
||||
required property list<var> apps
|
||||
required property bool enableCacheFolder
|
||||
|
||||
signal requestClose
|
||||
|
||||
@@ -145,6 +146,7 @@ PanelWindow {
|
||||
theme: root.theme
|
||||
app: modelData
|
||||
selected: index === root.selectedIndex
|
||||
enableCacheFolder: root.enableCacheFolder
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
AppConfig 1.0 AppConfig.qml
|
||||
AppButton 1.0 AppButton.qml
|
||||
HttpImageCache 1.0 HttpImageCache.qml
|
||||
LauncherWindow 1.0 LauncherWindow.qml
|
||||
Theme 1.0 Theme.qml
|
||||
@@ -26,5 +26,6 @@ ShellRoot {
|
||||
shellOpen: shell.launcherOpen
|
||||
onRequestClose: shell.launcherOpen = false
|
||||
apps: shell.config.appConfig
|
||||
enableCacheFolder: shell.config.enableCacheFolder
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"autoStart": true,
|
||||
"enableCacheFolder": true,
|
||||
"apps": [
|
||||
{
|
||||
"name": "Chromium",
|
||||
@@ -17,6 +18,11 @@
|
||||
"image": "system-settings",
|
||||
"isIcon": true,
|
||||
"exec": ["dms", "ipc", "call", "settings", "toggle"]
|
||||
},
|
||||
{
|
||||
"name": "Photos",
|
||||
"image": "~/Pictures/me.JPEG",
|
||||
"exec": ["imv"]
|
||||
}
|
||||
]
|
||||
}
|
||||
+2
-1
@@ -4,6 +4,7 @@
|
||||
makeWrapper,
|
||||
quickshell,
|
||||
nushell,
|
||||
curl,
|
||||
}:
|
||||
|
||||
stdenvNoCC.mkDerivation {
|
||||
@@ -30,7 +31,7 @@ stdenvNoCC.mkDerivation {
|
||||
mkdir -p $out/bin
|
||||
makeWrapper ${lib.getExe nushell} $out/bin/skygqts \
|
||||
--add-flags "$out/share/skygqts/skygqts.nu" \
|
||||
--prefix PATH : ${lib.makeBinPath [ quickshell ]}
|
||||
--prefix PATH : ${lib.makeBinPath [ quickshell curl ]}
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
|
||||
Reference in new issue
Block a user