mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-08 04:09:15 -04:00
fix(ClipboardEditor): Support legacy QT 6.xx decoding & large clipboard data
This commit is contained in:
@@ -418,6 +418,7 @@ func handleConnection(conn net.Conn) {
|
|||||||
conn.Write(capsData)
|
conn.Write(capsData)
|
||||||
conn.Write([]byte("\n"))
|
conn.Write([]byte("\n"))
|
||||||
scanner := bufio.NewScanner(conn)
|
scanner := bufio.NewScanner(conn)
|
||||||
|
scanner.Buffer(make([]byte, bufio.MaxScanTokenSize), 64*1024*1024) // grow up to 64 MB for large clipboard payloads
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Bytes()
|
line := scanner.Bytes()
|
||||||
|
|
||||||
|
|||||||
@@ -29,32 +29,29 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const chars = new Array(sanitized.length);
|
const decoded = Qt.atob(sanitized);
|
||||||
for (let i = 0; i < sanitized.length; i++) {
|
if (!decoded) {
|
||||||
chars[i] = sanitized.charAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
let buffer = null;
|
|
||||||
if (typeof Qt !== "undefined" && typeof Qt.atob === "function") {
|
|
||||||
buffer = Qt.atob(chars);
|
|
||||||
} else if (typeof atob === "function") {
|
|
||||||
const binary = atob(sanitized);
|
|
||||||
const bytes = new Uint8Array(binary.length);
|
|
||||||
for (let i = 0; i < binary.length; i++) {
|
|
||||||
bytes[i] = binary.charCodeAt(i);
|
|
||||||
}
|
|
||||||
buffer = bytes.buffer;
|
|
||||||
}
|
|
||||||
if (!buffer || buffer.byteLength === 0) {
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes = new Uint8Array(buffer);
|
|
||||||
let binary = "";
|
let binary = "";
|
||||||
for (let i = 0; i < bytes.length; i++) {
|
if (typeof decoded === "string") {
|
||||||
binary += String.fromCharCode(bytes[i]);
|
// Pre-6.11 Qt.atob returns a binary string directly
|
||||||
|
binary = decoded;
|
||||||
|
} else {
|
||||||
|
// Qt 6.11+ Qt.atob returns an ArrayBuffer — convert to avoid O(n²) concat/stack limits
|
||||||
|
const bytes = new Uint8Array(decoded);
|
||||||
|
const chunkSize = 8192;
|
||||||
|
const chunks = [];
|
||||||
|
for (let i = 0; i < bytes.length; i += chunkSize) {
|
||||||
|
chunks.push(String.fromCharCode.apply(null, bytes.subarray(i, i + chunkSize)));
|
||||||
|
}
|
||||||
|
binary = chunks.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!binary) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return decodeURIComponent(escape(binary));
|
return decodeURIComponent(escape(binary));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -74,6 +71,7 @@ Item {
|
|||||||
Qt.callLater(function () {
|
Qt.callLater(function () {
|
||||||
if (editField) {
|
if (editField) {
|
||||||
editField.forceActiveFocus();
|
editField.forceActiveFocus();
|
||||||
|
editField.cursorPosition = editField.text.length;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -104,7 +102,17 @@ Item {
|
|||||||
}
|
}
|
||||||
root.editorText = fullText;
|
root.editorText = fullText;
|
||||||
if (editField) {
|
if (editField) {
|
||||||
editField.text = fullText;
|
if (fullText.length > 50000) {
|
||||||
|
Qt.callLater(function () {
|
||||||
|
if (editField) {
|
||||||
|
editField.text = fullText;
|
||||||
|
editField.cursorPosition = fullText.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
editField.text = fullText;
|
||||||
|
editField.cursorPosition = fullText.length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -252,7 +260,6 @@ Item {
|
|||||||
id: editField
|
id: editField
|
||||||
width: editScroll.width
|
width: editScroll.width
|
||||||
height: Math.max(editScroll.height, contentHeight)
|
height: Math.max(editScroll.height, contentHeight)
|
||||||
text: root.editorText
|
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
wrapMode: TextEdit.Wrap
|
wrapMode: TextEdit.Wrap
|
||||||
|
|||||||
Reference in New Issue
Block a user