Formatting

This commit is contained in:
quadbyte 2025-08-14 14:58:00 -04:00
parent 3f64bb1879
commit 151e2b6aaf
7 changed files with 869 additions and 840 deletions

View file

@ -6,134 +6,133 @@ import Quickshell.Io
import qs.Services
Singleton {
id: root
id: root
property var history: []
property bool initialized: false
property var history: []
property bool initialized: false
// Internal state
property bool _enabled: true
// Internal state
property bool _enabled: true
Timer {
interval: 1000
repeat: true
running: root._enabled
onTriggered: root.refresh()
}
Timer {
interval: 1000
repeat: true
running: root._enabled
onTriggered: root.refresh()
}
// Detect current clipboard types (text/image)
Process {
id: typeProcess
property bool isLoading: false
property var currentTypes: []
// Detect current clipboard types (text/image)
Process {
id: typeProcess
property bool isLoading: false
property var currentTypes: []
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
currentTypes = String(stdout.text).trim().split('\n').filter(t => t)
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
currentTypes = String(stdout.text).trim().split('\n').filter(t => t)
const imageType = currentTypes.find(t => t.startsWith('image/'))
if (imageType) {
imageProcess.mimeType = imageType
imageProcess.command = ["sh", "-c", `wl-paste -n -t "${imageType}" | base64 -w 0`]
imageProcess.running = true
} else {
textProcess.command = ["wl-paste", "-n", "--type", "text/plain"]
textProcess.running = true
}
} else {
typeProcess.isLoading = false
}
const imageType = currentTypes.find(t => t.startsWith('image/'))
if (imageType) {
imageProcess.mimeType = imageType
imageProcess.command = ["sh", "-c", `wl-paste -n -t "${imageType}" | base64 -w 0`]
imageProcess.running = true
} else {
textProcess.command = ["wl-paste", "-n", "--type", "text/plain"]
textProcess.running = true
}
stdout: StdioCollector {}
} else {
typeProcess.isLoading = false
}
}
// Read image data
Process {
id: imageProcess
property string mimeType: ""
stdout: StdioCollector {}
}
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
const base64 = stdout.text.trim()
if (base64) {
const entry = {
type: 'image',
mimeType: mimeType,
data: `data:${mimeType};base64,${base64}`,
timestamp: new Date().getTime()
}
// Read image data
Process {
id: imageProcess
property string mimeType: ""
const exists = root.history.find(item => item.type === 'image' && item.data === entry.data)
if (!exists) {
root.history = [entry, ...root.history].slice(0, 20)
}
}
}
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
const base64 = stdout.text.trim()
if (base64) {
const entry = {
"type": 'image',
"mimeType": mimeType,
"data": `data:${mimeType};base64,${base64}`,
"timestamp": new Date().getTime()
}
if (!textProcess.isLoading) {
root.initialized = true
}
typeProcess.isLoading = false
const exists = root.history.find(item => item.type === 'image' && item.data === entry.data)
if (!exists) {
root.history = [entry, ...root.history].slice(0, 20)
}
}
}
stdout: StdioCollector {}
if (!textProcess.isLoading) {
root.initialized = true
}
typeProcess.isLoading = false
}
// Read text data
Process {
id: textProcess
property bool isLoading: false
stdout: StdioCollector {}
}
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
const content = String(stdout.text).trim()
if (content) {
const entry = {
type: 'text',
content: content,
timestamp: new Date().getTime()
}
// Read text data
Process {
id: textProcess
property bool isLoading: false
const exists = root.history.find(item => {
if (item.type === 'text') {
return item.content === content
}
return item === content
})
onExited: (exitCode, exitStatus) => {
if (exitCode === 0) {
const content = String(stdout.text).trim()
if (content) {
const entry = {
"type": 'text',
"content": content,
"timestamp": new Date().getTime()
}
if (!exists) {
const newHistory = root.history.map(item => {
if (typeof item === 'string') {
return {
type: 'text',
content: item,
timestamp: new Date().getTime()
}
}
return item
})
const exists = root.history.find(item => {
if (item.type === 'text') {
return item.content === content
}
return item === content
})
root.history = [entry, ...newHistory].slice(0, 20)
}
}
} else {
textProcess.isLoading = false
}
if (!exists) {
const newHistory = root.history.map(item => {
if (typeof item === 'string') {
return {
"type": 'text',
"content": item,
"timestamp": new Date().getTime()
}
}
return item
})
root.initialized = true
typeProcess.isLoading = false
root.history = [entry, ...newHistory].slice(0, 20)
}
}
} else {
textProcess.isLoading = false
}
stdout: StdioCollector {}
root.initialized = true
typeProcess.isLoading = false
}
function refresh() {
if (!typeProcess.isLoading && !textProcess.isLoading) {
typeProcess.isLoading = true
typeProcess.command = ["wl-paste", "-l"]
typeProcess.running = true
}
stdout: StdioCollector {}
}
function refresh() {
if (!typeProcess.isLoading && !textProcess.isLoading) {
typeProcess.isLoading = true
typeProcess.command = ["wl-paste", "-l"]
typeProcess.running = true
}
}
}

View file

@ -82,10 +82,10 @@ Singleton {
data.timestamp = Time.timestamp
console.log("[GitHub] Saving data to cache file:", githubDataFile)
console.log("[GitHub] Data to save - version:", data.version, "contributors:", data.contributors.length)
// Ensure cache directory exists
Quickshell.execDetached(["mkdir", "-p", Settings.cacheDir])
Qt.callLater(() => {
// Use direct ID reference to the FileView
githubDataFileView.writeAdapter()
@ -147,7 +147,8 @@ Singleton {
console.log("[GitHub] Raw contributors response length:", response ? response.length : 0)
if (response && response.trim()) {
const data = JSON.parse(response)
console.log("[GitHub] Parsed contributors data type:", typeof data, "length:", Array.isArray(data) ? data.length : "not array")
console.log("[GitHub] Parsed contributors data type:", typeof data, "length:",
Array.isArray(data) ? data.length : "not array")
root.data.contributors = data || []
root.contributors = root.data.contributors
console.log("[GitHub] Contributors fetched from GitHub:", root.contributors.length)

View file

@ -160,6 +160,7 @@ Singleton {
running: false
stdout: StdioCollector {
onStreamFinished: {
// console.log(this.text)
}
}