formatting
This commit is contained in:
parent
c0a068ddc0
commit
0fca050ce3
8 changed files with 93 additions and 103 deletions
|
|
@ -36,18 +36,13 @@ QtObject {
|
||||||
console.log("AdvancedMath not available, using basic eval")
|
console.log("AdvancedMath not available, using basic eval")
|
||||||
|
|
||||||
// Basic preprocessing for common functions
|
// Basic preprocessing for common functions
|
||||||
var processed = expression.trim()
|
var processed = expression.trim(
|
||||||
.replace(/\bpi\b/gi, Math.PI)
|
).replace(/\bpi\b/gi,
|
||||||
.replace(/\be\b/gi, Math.E)
|
Math.PI).replace(/\be\b/gi,
|
||||||
.replace(/\bsqrt\s*\(/g, 'Math.sqrt(')
|
Math.E).replace(/\bsqrt\s*\(/g,
|
||||||
.replace(/\bsin\s*\(/g, 'Math.sin(')
|
'Math.sqrt(').replace(/\bsin\s*\(/g,
|
||||||
.replace(/\bcos\s*\(/g, 'Math.cos(')
|
'Math.sin(').replace(/\bcos\s*\(/g,
|
||||||
.replace(/\btan\s*\(/g, 'Math.tan(')
|
'Math.cos(').replace(/\btan\s*\(/g, 'Math.tan(').replace(/\blog\s*\(/g, 'Math.log10(').replace(/\bln\s*\(/g, 'Math.log(').replace(/\bexp\s*\(/g, 'Math.exp(').replace(/\bpow\s*\(/g, 'Math.pow(').replace(/\babs\s*\(/g, 'Math.abs(')
|
||||||
.replace(/\blog\s*\(/g, 'Math.log10(')
|
|
||||||
.replace(/\bln\s*\(/g, 'Math.log(')
|
|
||||||
.replace(/\bexp\s*\(/g, 'Math.exp(')
|
|
||||||
.replace(/\bpow\s*\(/g, 'Math.pow(')
|
|
||||||
.replace(/\babs\s*\(/g, 'Math.abs(')
|
|
||||||
|
|
||||||
// Sanitize and evaluate
|
// Sanitize and evaluate
|
||||||
if (!/^[0-9+\-*/().\s\w,]+$/.test(processed)) {
|
if (!/^[0-9+\-*/().\s\w,]+$/.test(processed)) {
|
||||||
|
|
@ -90,15 +85,13 @@ QtObject {
|
||||||
"name": "Invalid expression",
|
"name": "Invalid expression",
|
||||||
"content": evaluation.error,
|
"content": evaluation.error,
|
||||||
"icon": "error",
|
"icon": "error",
|
||||||
"execute": function () {
|
"execute": function () {// Do nothing for invalid expressions
|
||||||
// Do nothing for invalid expressions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayName = searchContext === "calc"
|
const displayName = searchContext
|
||||||
? `${expression} = ${evaluation.displayResult}`
|
=== "calc" ? `${expression} = ${evaluation.displayResult}` : `${expression} = ${evaluation.displayResult}`
|
||||||
: `${expression} = ${evaluation.displayResult}`
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"isCalculator": true,
|
"isCalculator": true,
|
||||||
|
|
@ -110,12 +103,10 @@ QtObject {
|
||||||
"execute": function () {
|
"execute": function () {
|
||||||
Quickshell.clipboardText = evaluation.displayResult
|
Quickshell.clipboardText = evaluation.displayResult
|
||||||
// Also copy using shell command for better compatibility
|
// Also copy using shell command for better compatibility
|
||||||
Quickshell.execDetached(["sh", "-lc", `printf %s ${evaluation.displayResult} | wl-copy -t text/plain;charset=utf-8`])
|
Quickshell.execDetached(
|
||||||
Quickshell.execDetached([
|
["sh", "-lc", `printf %s ${evaluation.displayResult} | wl-copy -t text/plain;charset=utf-8`])
|
||||||
"notify-send",
|
Quickshell.execDetached(
|
||||||
"Calculator",
|
["notify-send", "Calculator", `${expression} = ${evaluation.displayResult} (copied to clipboard)`])
|
||||||
`${expression} = ${evaluation.displayResult} (copied to clipboard)`
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,8 +118,7 @@ QtObject {
|
||||||
"name": "Calculator",
|
"name": "Calculator",
|
||||||
"content": "Try: sqrt(16), sin(1), cos(0), pi*2, exp(1), pow(2,8), abs(-5)",
|
"content": "Try: sqrt(16), sin(1), cos(0), pi*2, exp(1), pow(2,8), abs(-5)",
|
||||||
"icon": "calculate",
|
"icon": "calculate",
|
||||||
"execute": function () {
|
"execute": function () {// Do nothing for placeholder
|
||||||
// Do nothing for placeholder
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,9 @@ QtObject {
|
||||||
"type": 'text',
|
"type": 'text',
|
||||||
"timestamp": clip.timestamp,
|
"timestamp": clip.timestamp,
|
||||||
"index": index,
|
"index": index,
|
||||||
"textData": textContent, // Store the text data for the execute function
|
"textData": textContent,
|
||||||
"execute": function () {
|
"execute"// Store the text data for the execute function
|
||||||
|
: function () {
|
||||||
const text = this.textData || clip.content || clip
|
const text = this.textData || clip.content || clip
|
||||||
Quickshell.clipboardText = String(text)
|
Quickshell.clipboardText = String(text)
|
||||||
copyText(String(text))
|
copyText(String(text))
|
||||||
|
|
@ -77,8 +78,7 @@ QtObject {
|
||||||
"name": "No clipboard history",
|
"name": "No clipboard history",
|
||||||
"content": "No matching clipboard entries found",
|
"content": "No matching clipboard entries found",
|
||||||
"icon": "content_paste_off",
|
"icon": "content_paste_off",
|
||||||
"execute": function () {
|
"execute": function () {// Do nothing for empty state
|
||||||
// Do nothing for empty state
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,8 +122,7 @@ QtObject {
|
||||||
"name": ">clip",
|
"name": ">clip",
|
||||||
"content": "Clipboard history - browse and restore clipboard items",
|
"content": "Clipboard history - browse and restore clipboard items",
|
||||||
"icon": "content_paste",
|
"icon": "content_paste",
|
||||||
"execute": function () {
|
"execute": function () {// This should be handled by the parent component
|
||||||
// This should be handled by the parent component
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,8 @@ Singleton {
|
||||||
return {
|
return {
|
||||||
"type": 'text',
|
"type": 'text',
|
||||||
"content": item,
|
"content": item,
|
||||||
"timestamp": new Date().getTime() - 1000 // Make it slightly older
|
"timestamp": new Date().getTime(
|
||||||
|
) - 1000 // Make it slightly older
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
|
|
@ -158,7 +159,8 @@ Singleton {
|
||||||
return {
|
return {
|
||||||
"type": 'text',
|
"type": 'text',
|
||||||
"content": item,
|
"content": item,
|
||||||
"timestamp": new Date().getTime() - 1000 // Make it slightly older
|
"timestamp": new Date().getTime(
|
||||||
|
) - 1000 // Make it slightly older
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ Singleton {
|
||||||
Logger.log("IdleInhibitor", "Using systemd-inhibit strategy")
|
Logger.log("IdleInhibitor", "Using systemd-inhibit strategy")
|
||||||
return
|
return
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
// systemd-inhibit not found, try Wayland tools
|
// systemd-inhibit not found, try Wayland tools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,6 +47,7 @@ Singleton {
|
||||||
Logger.log("IdleInhibitor", "Using wayhibitor strategy")
|
Logger.log("IdleInhibitor", "Using wayhibitor strategy")
|
||||||
return
|
return
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
// wayhibitor not found
|
// wayhibitor not found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +88,8 @@ Singleton {
|
||||||
const shouldInhibit = activeInhibitors.length > 0
|
const shouldInhibit = activeInhibitors.length > 0
|
||||||
|
|
||||||
if (shouldInhibit === isInhibited) {
|
if (shouldInhibit === isInhibited) {
|
||||||
return // No change needed
|
return
|
||||||
|
// No change needed
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInhibit) {
|
if (shouldInhibit) {
|
||||||
|
|
@ -115,7 +118,8 @@ Singleton {
|
||||||
|
|
||||||
// Stop system inhibition
|
// Stop system inhibition
|
||||||
function stopInhibition() {
|
function stopInhibition() {
|
||||||
if (!isInhibited) return
|
if (!isInhibited)
|
||||||
|
return
|
||||||
|
|
||||||
if (inhibitorProcess.running) {
|
if (inhibitorProcess.running) {
|
||||||
inhibitorProcess.signal(15) // SIGTERM
|
inhibitorProcess.signal(15) // SIGTERM
|
||||||
|
|
@ -127,13 +131,8 @@ Singleton {
|
||||||
|
|
||||||
// Systemd inhibition using systemd-inhibit
|
// Systemd inhibition using systemd-inhibit
|
||||||
function startSystemdInhibition() {
|
function startSystemdInhibition() {
|
||||||
inhibitorProcess.command = [
|
inhibitorProcess.command = ["systemd-inhibit", "--what=idle:sleep:handle-lid-switch", "--why="
|
||||||
"systemd-inhibit",
|
+ reason, "--mode=block", "sleep", "infinity"]
|
||||||
"--what=idle:sleep:handle-lid-switch",
|
|
||||||
"--why=" + reason,
|
|
||||||
"--mode=block",
|
|
||||||
"sleep", "infinity"
|
|
||||||
]
|
|
||||||
inhibitorProcess.running = true
|
inhibitorProcess.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue