Formatting

This commit is contained in:
quadbyte 2025-08-12 08:14:04 -04:00
parent d17fb4c002
commit 934d4cc933
2 changed files with 314 additions and 329 deletions

View file

@ -16,7 +16,7 @@ ColumnLayout {
Component.onCompleted: { Component.onCompleted: {
// Initialize the Github service // Initialize the Github service
Github.init(); Github.init()
} }
spacing: 0 spacing: 0
@ -28,21 +28,21 @@ ColumnLayout {
command: ["sh", "-c", "cd " + Quickshell.shellDir + " && git describe --tags --abbrev=0 2>/dev/null || echo 'Unknown'"] command: ["sh", "-c", "cd " + Quickshell.shellDir + " && git describe --tags --abbrev=0 2>/dev/null || echo 'Unknown'"]
Component.onCompleted: { Component.onCompleted: {
running = true; running = true
} }
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
const version = text.trim(); const version = text.trim()
if (version && version !== "Unknown") { if (version && version !== "Unknown") {
root.currentVersion = version; root.currentVersion = version
} else { } else {
currentVersionProcess.command = ["sh", "-c", "cd " + Quickshell.shellDir + " && cat package.json 2>/dev/null | grep '\"version\"' | cut -d'\"' -f4 || echo 'Unknown'"]; currentVersionProcess.command = ["sh", "-c", "cd " + Quickshell.shellDir
currentVersionProcess.running = true; + " && cat package.json 2>/dev/null | grep '\"version\"' | cut -d'\"' -f4 || echo 'Unknown'"]
currentVersionProcess.running = true
} }
} }
} }
} }
ScrollView { ScrollView {
@ -110,7 +110,6 @@ ColumnLayout {
color: Colors.textPrimary color: Colors.textPrimary
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
} }
} }
Rectangle { Rectangle {
@ -124,21 +123,20 @@ ColumnLayout {
border.width: 1 border.width: 1
visible: { visible: {
if (root.currentVersion === "Unknown" || root.latestVersion === "Unknown") if (root.currentVersion === "Unknown" || root.latestVersion === "Unknown")
return false; return false
const latest = root.latestVersion.replace("v", "").split("."); const latest = root.latestVersion.replace("v", "").split(".")
const current = root.currentVersion.replace("v", "").split("."); const current = root.currentVersion.replace("v", "").split(".")
for (let i = 0; i < Math.max(latest.length, current.length); i++) { for (var i = 0; i < Math.max(latest.length, current.length); i++) {
const l = parseInt(latest[i] || "0"); const l = parseInt(latest[i] || "0")
const c = parseInt(current[i] || "0"); const c = parseInt(current[i] || "0")
if (l > c) if (l > c)
return true; return true
if (l < c) if (l < c)
return false; return false
} }
return false; return false
} }
RowLayout { RowLayout {
@ -159,7 +157,6 @@ ColumnLayout {
font.pointSize: 14 * Scaling.scale(screen) font.pointSize: 14 * Scaling.scale(screen)
color: updateArea.containsMouse ? Colors.backgroundPrimary : Colors.accentPrimary color: updateArea.containsMouse ? Colors.backgroundPrimary : Colors.accentPrimary
} }
} }
MouseArea { MouseArea {
@ -169,10 +166,9 @@ ColumnLayout {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
Quickshell.execDetached(["xdg-open", "https://github.com/Ly-sec/Noctalia/releases/latest"]); Quickshell.execDetached(["xdg-open", "https://github.com/Ly-sec/Noctalia/releases/latest"])
} }
} }
} }
// Separator // Separator
@ -252,7 +248,7 @@ ColumnLayout {
onStatusChanged: { onStatusChanged: {
if (status === Image.Error) { if (status === Image.Error) {
console.log("[About] Failed to load avatar for", modelData.login, "URL:", modelData.avatar_url); console.log("[About] Failed to load avatar for", modelData.login, "URL:", modelData.avatar_url)
} }
} }
} }
@ -285,7 +281,6 @@ ColumnLayout {
color: contributorArea.containsMouse ? Colors.backgroundPrimary : Colors.textPrimary color: contributorArea.containsMouse ? Colors.backgroundPrimary : Colors.textPrimary
visible: !avatarImage.source || avatarImage.status !== Image.Ready visible: !avatarImage.source || avatarImage.status !== Image.Ready
} }
} }
ColumnLayout { ColumnLayout {
@ -306,9 +301,7 @@ ColumnLayout {
font.pointSize: 11 * Scaling.scale(screen) font.pointSize: 11 * Scaling.scale(screen)
color: contributorArea.containsMouse ? Colors.backgroundPrimary : Colors.textSecondary color: contributorArea.containsMouse ? Colors.backgroundPrimary : Colors.textSecondary
} }
} }
} }
MouseArea { MouseArea {
@ -319,19 +312,12 @@ ColumnLayout {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
if (modelData.html_url) if (modelData.html_url)
Quickshell.execDetached(["xdg-open", modelData.html_url]); Quickshell.execDetached(["xdg-open", modelData.html_url])
} }
} }
} }
} }
} }
} }
} }
} }

View file

@ -32,7 +32,7 @@ Singleton {
onLoadFailed: function (error) { onLoadFailed: function (error) {
if (error.toString().includes("No such file") || error === 2) { if (error.toString().includes("No such file") || error === 2) {
// File doesn't exist, create it with default values // File doesn't exist, create it with default values
console.log("[Github] Creating new cache file..."); console.log("[Github] Creating new cache file...")
writeAdapter() writeAdapter()
// Fetch data after a short delay to ensure file is created // Fetch data after a short delay to ensure file is created
Qt.callLater(() => { Qt.callLater(() => {
@ -51,26 +51,25 @@ Singleton {
} }
// -------------------------------- // --------------------------------
function init() { function init() {// does nothing but ensure the singleton is created
// does nothing but ensure the singleton is created
// do not remove // do not remove
} }
// -------------------------------- // --------------------------------
function loadFromCache() { function loadFromCache() {
const now = Date.now(); const now = Date.now()
if (!data.timestamp || (now - data.timestamp > githubUpdateFrequency * 1000)) { if (!data.timestamp || (now - data.timestamp > githubUpdateFrequency * 1000)) {
console.log("[Github] Cache expired or missing, fetching new data from GitHub..."); console.log("[Github] Cache expired or missing, fetching new data from GitHub...")
fetchFromGitHub(); fetchFromGitHub()
return; return
} }
console.log("[Github] Loading cached GitHub data (age: " + Math.round((now - data.timestamp) / 60000) + " minutes)"); console.log("[Github] Loading cached GitHub data (age: " + Math.round((now - data.timestamp) / 60000) + " minutes)")
if (data.version) { if (data.version) {
root.latestVersion = data.version; root.latestVersion = data.version
} }
if (data.contributors) { if (data.contributors) {
root.contributors = data.contributors; root.contributors = data.contributors
} }
} }
@ -82,20 +81,20 @@ Singleton {
} }
isFetchingData = true isFetchingData = true
versionProcess.running = true; versionProcess.running = true
contributorsProcess.running = true; contributorsProcess.running = true
} }
// -------------------------------- // --------------------------------
function saveData() { function saveData() {
data.timestamp = Date.now(); data.timestamp = Date.now()
Qt.callLater(() => { Qt.callLater(() => {
// Access the FileView's writeAdapter method // Access the FileView's writeAdapter method
var fileView = root.children.find(child => child.objectName === "githubDataFileView"); var fileView = root.children.find(child => child.objectName === "githubDataFileView")
if (fileView) { if (fileView) {
fileView.writeAdapter(); fileView.writeAdapter()
} }
}); })
} }
// -------------------------------- // --------------------------------
@ -116,26 +115,26 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
try { try {
const response = text; const response = text
if (response && response.trim()) { if (response && response.trim()) {
const data = JSON.parse(response); const data = JSON.parse(response)
if (data.tag_name) { if (data.tag_name) {
const version = data.tag_name; const version = data.tag_name
root.data.version = version; root.data.version = version
root.latestVersion = version; root.latestVersion = version
console.log("[Github] Latest version fetched from GitHub:", version); console.log("[Github] Latest version fetched from GitHub:", version)
} else { } else {
console.log("[Github] No tag_name in GitHub response"); console.log("[Github] No tag_name in GitHub response")
} }
} else { } else {
console.log("[Github] Empty response from GitHub API"); console.log("[Github] Empty response from GitHub API")
} }
} catch (e) { } catch (e) {
console.error("[Github] Failed to parse version:", e); console.error("[Github] Failed to parse version:", e)
} }
// Check if both processes are done // Check if both processes are done
checkAndSaveData(); checkAndSaveData()
} }
} }
} }
@ -148,25 +147,25 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
try { try {
const response = text; const response = text
if (response && response.trim()) { if (response && response.trim()) {
const data = JSON.parse(response); const data = JSON.parse(response)
root.data.contributors = data || []; root.data.contributors = data || []
root.contributors = root.data.contributors; root.contributors = root.data.contributors
console.log("[Github] Contributors fetched from GitHub:", root.contributors.length); console.log("[Github] Contributors fetched from GitHub:", root.contributors.length)
} else { } else {
console.log("[Github] Empty response from GitHub API for contributors"); console.log("[Github] Empty response from GitHub API for contributors")
root.data.contributors = []; root.data.contributors = []
root.contributors = []; root.contributors = []
} }
} catch (e) { } catch (e) {
console.error("[Github] Failed to parse contributors:", e); console.error("[Github] Failed to parse contributors:", e)
root.data.contributors = []; root.data.contributors = []
root.contributors = []; root.contributors = []
} }
// Check if both processes are done // Check if both processes are done
checkAndSaveData(); checkAndSaveData()
} }
} }
} }
@ -175,8 +174,8 @@ Singleton {
function checkAndSaveData() { function checkAndSaveData() {
// Only save when both processes are finished // Only save when both processes are finished
if (!versionProcess.running && !contributorsProcess.running) { if (!versionProcess.running && !contributorsProcess.running) {
root.isFetchingData = false; root.isFetchingData = false
root.saveData(); root.saveData()
} }
} }
} }