Use const instead of let when possible
This commit is contained in:
parent
ffc8a13db6
commit
cdb79d11aa
|
@ -27,7 +27,7 @@ Rectangle {
|
||||||
|
|
||||||
function enterClickButton() {
|
function enterClickButton() {
|
||||||
for (let i = 0; i < buttonModel.length; i++) {
|
for (let i = 0; i < buttonModel.length; i++) {
|
||||||
let btn = buttonRepeater.itemAt(i)
|
const btn = buttonRepeater.itemAt(i)
|
||||||
if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked()
|
if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ Menu {
|
||||||
let result = 0
|
let result = 0
|
||||||
|
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
let item = itemAt(i)
|
const item = itemAt(i)
|
||||||
if (! item.visible) continue
|
if (! item.visible) continue
|
||||||
|
|
||||||
result = Math.max(item.implicitWidth, result)
|
result = Math.max(item.implicitWidth, result)
|
||||||
|
|
|
@ -25,8 +25,8 @@ HImage {
|
||||||
function update() {
|
function update() {
|
||||||
if (! py) return // component was destroyed
|
if (! py) return // component was destroyed
|
||||||
|
|
||||||
let w = sourceSize.width || width
|
const w = sourceSize.width || width
|
||||||
let h = sourceSize.height || height
|
const h = sourceSize.height || height
|
||||||
|
|
||||||
if (! image.mxc || w < 1 || h < 1 ) {
|
if (! image.mxc || w < 1 || h < 1 ) {
|
||||||
show = false
|
show = false
|
||||||
|
@ -39,8 +39,8 @@ HImage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let method = image.thumbnail ? "get_thumbnail" : "get_media"
|
const method = image.thumbnail ? "get_thumbnail" : "get_media"
|
||||||
let args = image.thumbnail ?
|
const args = image.thumbnail ?
|
||||||
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
||||||
|
|
||||||
py.callCoro("media_cache." + method, args, path => {
|
py.callCoro("media_cache." + method, args, path => {
|
||||||
|
|
|
@ -25,9 +25,9 @@ FocusScope {
|
||||||
]
|
]
|
||||||
|
|
||||||
readonly property string joinedSelection: {
|
readonly property string joinedSelection: {
|
||||||
let toCopy = []
|
const toCopy = []
|
||||||
|
|
||||||
for (let key of Object.keys(selectedTexts).sort()) {
|
for (const key of Object.keys(selectedTexts).sort()) {
|
||||||
if (! selectedTexts[key]) continue
|
if (! selectedTexts[key]) continue
|
||||||
|
|
||||||
// For some dumb reason, Object.keys convert the floats to strings
|
// For some dumb reason, Object.keys convert the floats to strings
|
||||||
|
@ -53,7 +53,7 @@ FocusScope {
|
||||||
selecting = false
|
selecting = false
|
||||||
}
|
}
|
||||||
onDragPointChanged: {
|
onDragPointChanged: {
|
||||||
let pos = mapFromItem(
|
const pos = mapFromItem(
|
||||||
mainUI, eventPoint.scenePosition.x, eventPoint.scenePosition.y,
|
mainUI, eventPoint.scenePosition.x, eventPoint.scenePosition.y,
|
||||||
)
|
)
|
||||||
draggedItem.x = pos.x
|
draggedItem.x = pos.x
|
||||||
|
|
|
@ -26,7 +26,7 @@ HFileDialogOpener {
|
||||||
function exportKeys(file, passphrase) {
|
function exportKeys(file, passphrase) {
|
||||||
exporting = true
|
exporting = true
|
||||||
|
|
||||||
let path = file.toString().replace(/^file:\/\//, "")
|
const path = file.toString().replace(/^file:\/\//, "")
|
||||||
|
|
||||||
py.callClientCoro(userId, "export_keys", [path, passphrase], () => {
|
py.callClientCoro(userId, "export_keys", [path, passphrase], () => {
|
||||||
exporting = false
|
exporting = false
|
||||||
|
|
|
@ -30,7 +30,7 @@ HFileDialogOpener {
|
||||||
|
|
||||||
function verifyPassword(pass, callback) {
|
function verifyPassword(pass, callback) {
|
||||||
importing = true
|
importing = true
|
||||||
let path = file.toString().replace(/^file:\/\//, "")
|
const path = file.toString().replace(/^file:\/\//, "")
|
||||||
|
|
||||||
py.callClientCoro(userId, "import_keys", [path, pass], () => {
|
py.callClientCoro(userId, "import_keys", [path, pass], () => {
|
||||||
importing = false
|
importing = false
|
||||||
|
|
|
@ -9,8 +9,8 @@ HFileDialogOpener {
|
||||||
dialog.fileMode: FileDialog.OpenFiles
|
dialog.fileMode: FileDialog.OpenFiles
|
||||||
|
|
||||||
onFilesPicked: {
|
onFilesPicked: {
|
||||||
for (let file of files) {
|
for (const file of files) {
|
||||||
let path = Qt.resolvedUrl(file).replace(/^file:/, "")
|
const path = Qt.resolvedUrl(file).replace(/^file:/, "")
|
||||||
|
|
||||||
utils.sendFile(userId, roomId, path, () => {
|
utils.sendFile(userId, roomId, path, () => {
|
||||||
if (destroyWhenDone) destroy()
|
if (destroyWhenDone) destroy()
|
||||||
|
|
|
@ -73,14 +73,14 @@ HListView {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _previous() {
|
function _previous() {
|
||||||
let currentAccount = currentItem
|
const currentAccount = currentItem
|
||||||
|
|
||||||
// Nothing is selected
|
// Nothing is selected
|
||||||
if (! currentAccount) {
|
if (! currentAccount) {
|
||||||
decrementCurrentIndex()
|
decrementCurrentIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
let roomList = currentAccount.roomList
|
const roomList = currentAccount.roomList
|
||||||
|
|
||||||
// An account is selected
|
// An account is selected
|
||||||
if (! roomList.currentItem) {
|
if (! roomList.currentItem) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ HLoader {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let page = window.uiState.page
|
const page = window.uiState.page
|
||||||
let props = window.uiState.pageProperties
|
const props = window.uiState.pageProperties
|
||||||
|
|
||||||
if (page === "Pages/Chat/Chat.qml") {
|
if (page === "Pages/Chat/Chat.qml") {
|
||||||
pageLoader.showRoom(props.userId, props.roomId)
|
pageLoader.showRoom(props.userId, props.roomId)
|
||||||
|
@ -46,7 +46,7 @@ HLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPage(name, properties={}) {
|
function showPage(name, properties={}) {
|
||||||
let path = `Pages/${name}.qml`
|
const path = `Pages/${name}.qml`
|
||||||
_show(path, properties)
|
_show(path, properties)
|
||||||
|
|
||||||
window.uiState.page = path
|
window.uiState.page = path
|
||||||
|
@ -66,7 +66,7 @@ HLoader {
|
||||||
timesBack = Math.min(timesBack, history.length - 1)
|
timesBack = Math.min(timesBack, history.length - 1)
|
||||||
if (timesBack < 1) return false
|
if (timesBack < 1) return false
|
||||||
|
|
||||||
let [componentUrl, properties] = history[timesBack]
|
const [componentUrl, properties] = history[timesBack]
|
||||||
|
|
||||||
_show(componentUrl, properties)
|
_show(componentUrl, properties)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ HGridLayout {
|
||||||
if (avatar.changed) {
|
if (avatar.changed) {
|
||||||
saveButton.avatarChangeRunning = true
|
saveButton.avatarChangeRunning = true
|
||||||
|
|
||||||
let path =
|
const path =
|
||||||
Qt.resolvedUrl(avatar.sourceOverride).replace(/^file:/, "")
|
Qt.resolvedUrl(avatar.sourceOverride).replace(/^file:/, "")
|
||||||
|
|
||||||
py.callClientCoro(userId, "set_avatar_from_file", [path], () => {
|
py.callClientCoro(userId, "set_avatar_from_file", [path], () => {
|
||||||
|
|
|
@ -30,7 +30,7 @@ HBox {
|
||||||
|
|
||||||
errorMessage.text = ""
|
errorMessage.text = ""
|
||||||
|
|
||||||
let args = [
|
const args = [
|
||||||
idField.text.trim(), passwordField.text,
|
idField.text.trim(), passwordField.text,
|
||||||
undefined, serverField.text.trim(),
|
undefined, serverField.text.trim(),
|
||||||
]
|
]
|
||||||
|
|
|
@ -20,7 +20,7 @@ HBox {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
errorMessage.text = ""
|
errorMessage.text = ""
|
||||||
|
|
||||||
let args = [
|
const args = [
|
||||||
nameField.text,
|
nameField.text,
|
||||||
topicField.text,
|
topicField.text,
|
||||||
publicCheckBox.checked,
|
publicCheckBox.checked,
|
||||||
|
|
|
@ -25,7 +25,7 @@ HBox {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
errorMessage.text = ""
|
errorMessage.text = ""
|
||||||
|
|
||||||
let args = [userField.text.trim(), encryptCheckBox.checked]
|
const args = [userField.text.trim(), encryptCheckBox.checked]
|
||||||
|
|
||||||
py.callClientCoro(userId, "new_direct_chat", args, roomId => {
|
py.callClientCoro(userId, "new_direct_chat", args, roomId => {
|
||||||
button.loading = false
|
button.loading = false
|
||||||
|
|
|
@ -25,7 +25,7 @@ HBox {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
errorMessage.text = ""
|
errorMessage.text = ""
|
||||||
|
|
||||||
let args = [roomField.text.trim()]
|
const args = [roomField.text.trim()]
|
||||||
|
|
||||||
py.callClientCoro(userId, "room_join", args, roomId => {
|
py.callClientCoro(userId, "room_join", args, roomId => {
|
||||||
button.loading = false
|
button.loading = false
|
||||||
|
|
|
@ -101,7 +101,7 @@ Rectangle {
|
||||||
|
|
||||||
let foundAlias = null
|
let foundAlias = null
|
||||||
|
|
||||||
for (let [user, writing_alias] of Object.entries(aliases)) {
|
for (const [user, writing_alias] of Object.entries(aliases)) {
|
||||||
if (text.startsWith(writing_alias + " ")) {
|
if (text.startsWith(writing_alias + " ")) {
|
||||||
writingUserId = user
|
writingUserId = user
|
||||||
foundAlias = new RegExp("^" + writing_alias + " ")
|
foundAlias = new RegExp("^" + writing_alias + " ")
|
||||||
|
@ -119,15 +119,15 @@ Rectangle {
|
||||||
writingUserId = Qt.binding(() => chat.userId)
|
writingUserId = Qt.binding(() => chat.userId)
|
||||||
toSend = text
|
toSend = text
|
||||||
|
|
||||||
let vals = Object.values(aliases)
|
const vals = Object.values(aliases)
|
||||||
|
|
||||||
let longestAlias =
|
const longestAlias =
|
||||||
vals.reduce((a, b) => a.length > b.length ? a: b)
|
vals.reduce((a, b) => a.length > b.length ? a: b)
|
||||||
|
|
||||||
let textNotStartsWithAnyAlias =
|
const textNotStartsWithAnyAlias =
|
||||||
! vals.some(a => a.startsWith(text))
|
! vals.some(a => a.startsWith(text))
|
||||||
|
|
||||||
let textContainsCharNotInAnyAlias =
|
const textContainsCharNotInAnyAlias =
|
||||||
vals.every(a => text.split("").some(c => ! a.includes(c)))
|
vals.every(a => text.split("").some(c => ! a.includes(c)))
|
||||||
|
|
||||||
// Only set typing when it's sure that the user will not use
|
// Only set typing when it's sure that the user will not use
|
||||||
|
@ -162,21 +162,21 @@ Rectangle {
|
||||||
ev.modifiers & Qt.AltModifier)
|
ev.modifiers & Qt.AltModifier)
|
||||||
{
|
{
|
||||||
let indents = 0
|
let indents = 0
|
||||||
let parts = lineText.split(indent)
|
const parts = lineText.split(indent)
|
||||||
|
|
||||||
for (const [i, part] of parts.entries()) {
|
for (const [i, part] of parts.entries()) {
|
||||||
if (i === parts.length - 1 || part) { break }
|
if (i === parts.length - 1 || part) { break }
|
||||||
indents += 1
|
indents += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
let add = indent.repeat(indents)
|
const add = indent.repeat(indents)
|
||||||
textArea.insert(cursorPosition, "\n" + add)
|
textArea.insert(cursorPosition, "\n" + add)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textArea.text === "") { return }
|
if (textArea.text === "") { return }
|
||||||
|
|
||||||
let args = [chat.roomId, toSend]
|
const args = [chat.roomId, toSend]
|
||||||
py.callClientCoro(writingUserId, "send_text", args)
|
py.callClientCoro(writingUserId, "send_text", args)
|
||||||
|
|
||||||
area.clear()
|
area.clear()
|
||||||
|
|
|
@ -71,8 +71,8 @@ HMxcImage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let toOpen = loader.mediaUrl || loader.thumbnailMxc
|
const toOpen = loader.mediaUrl || loader.thumbnailMxc
|
||||||
let isMxc = toOpen.startsWith("mxc://")
|
const isMxc = toOpen.startsWith("mxc://")
|
||||||
|
|
||||||
isMxc ?
|
isMxc ?
|
||||||
py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) :
|
py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) :
|
||||||
|
|
|
@ -20,11 +20,11 @@ Rectangle {
|
||||||
target: null
|
target: null
|
||||||
onActiveChanged: if (! active) dragFlicker.speed = 0
|
onActiveChanged: if (! active) dragFlicker.speed = 0
|
||||||
onCentroidChanged: {
|
onCentroidChanged: {
|
||||||
let left = centroid.pressedButtons & Qt.LeftButton
|
const left = centroid.pressedButtons & Qt.LeftButton
|
||||||
let vel = centroid.velocity.y
|
const vel = centroid.velocity.y
|
||||||
let pos = centroid.position.y
|
const pos = centroid.position.y
|
||||||
let dist = Math.min(selectableLabelContainer.height / 4, 50)
|
const dist = Math.min(selectableLabelContainer.height / 4, 50)
|
||||||
let boost = 20 * (pos < dist ? -pos : -(height - pos))
|
const boost = 20 * (pos < dist ? -pos : -(height - pos))
|
||||||
|
|
||||||
dragFlicker.speed =
|
dragFlicker.speed =
|
||||||
left && vel && pos < dist ? 1000 + boost :
|
left && vel && pos < dist ? 1000 + boost :
|
||||||
|
|
|
@ -47,19 +47,19 @@ HLoader {
|
||||||
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
||||||
return EventDelegate.Media.Image
|
return EventDelegate.Media.Image
|
||||||
|
|
||||||
let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
const mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
||||||
|
|
||||||
if (mainType === "image") return EventDelegate.Media.Image
|
if (mainType === "image") return EventDelegate.Media.Image
|
||||||
if (mainType === "video") return EventDelegate.Media.Video
|
if (mainType === "video") return EventDelegate.Media.Video
|
||||||
if (mainType === "audio") return EventDelegate.Media.Audio
|
if (mainType === "audio") return EventDelegate.Media.Audio
|
||||||
|
|
||||||
let fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
const fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
||||||
|
|
||||||
if (fileEvents.includes(singleMediaInfo.event_type))
|
if (fileEvents.includes(singleMediaInfo.event_type))
|
||||||
return EventDelegate.Media.File
|
return EventDelegate.Media.File
|
||||||
|
|
||||||
// If this is a preview for a link in a normal message
|
// If this is a preview for a link in a normal message
|
||||||
let ext = utils.urlExtension(mediaUrl)
|
const ext = utils.urlExtension(mediaUrl)
|
||||||
|
|
||||||
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
|
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
|
||||||
if (videoExtensions.includes(ext)) return EventDelegate.Media.Video
|
if (videoExtensions.includes(ext)) return EventDelegate.Media.Video
|
||||||
|
|
|
@ -87,7 +87,7 @@ BoxPopup {
|
||||||
// TODO: handle these: real user not found
|
// TODO: handle these: real user not found
|
||||||
const lines = []
|
const lines = []
|
||||||
|
|
||||||
for (let [user, error] of failedInvites) {
|
for (const [user, error] of failedInvites) {
|
||||||
const type = py.getattr(
|
const type = py.getattr(
|
||||||
py.getattr(error, "__class__"), "__name__",
|
py.getattr(error, "__class__"), "__name__",
|
||||||
)
|
)
|
||||||
|
|
|
@ -35,7 +35,7 @@ BoxPopup {
|
||||||
|
|
||||||
box.buttonCallbacks: ({
|
box.buttonCallbacks: ({
|
||||||
ok: button => {
|
ok: button => {
|
||||||
let password = passwordField.text
|
const password = passwordField.text
|
||||||
okClicked = true
|
okClicked = true
|
||||||
button.loading = true
|
button.loading = true
|
||||||
errorMessage.text = ""
|
errorMessage.text = ""
|
||||||
|
|
|
@ -18,8 +18,8 @@ QtObject {
|
||||||
|
|
||||||
|
|
||||||
function onCoroutineDone(uuid, result, error, traceback) {
|
function onCoroutineDone(uuid, result, error, traceback) {
|
||||||
let onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
const onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
||||||
let onError = Globals.pendingCoroutines[uuid].onError
|
const onError = Globals.pendingCoroutines[uuid].onError
|
||||||
|
|
||||||
delete Globals.pendingCoroutines[uuid]
|
delete Globals.pendingCoroutines[uuid]
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ QtObject {
|
||||||
console.error("Failed creating component: ", comp.errorString())
|
console.error("Failed creating component: ", comp.errorString())
|
||||||
|
|
||||||
} else if (! ready && status === Component.Ready) {
|
} else if (! ready && status === Component.Ready) {
|
||||||
let incu = comp.incubateObject(
|
const incu = comp.incubateObject(
|
||||||
parent, properties, Qt.Asynchronous,
|
parent, properties, Qt.Asynchronous,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ QtObject {
|
||||||
text = text.toLowerCase()
|
text = text.toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let word of filter.split(" ")) {
|
for (const word of filter.split(" ")) {
|
||||||
if (word && ! text.includes(word)) {
|
if (word && ! text.includes(word)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ QtObject {
|
||||||
|
|
||||||
|
|
||||||
function filterMatchesAny(filter, ...texts) {
|
function filterMatchesAny(filter, ...texts) {
|
||||||
for (let text of texts) {
|
for (const text of texts) {
|
||||||
if (filterMatches(filter, text)) return true
|
if (filterMatches(filter, text)) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -184,11 +184,11 @@ QtObject {
|
||||||
|
|
||||||
function fitSize(minWidth, minHeight, width, height, maxWidth, maxHeight) {
|
function fitSize(minWidth, minHeight, width, height, maxWidth, maxHeight) {
|
||||||
if (width >= height) {
|
if (width >= height) {
|
||||||
let new_width = Math.min(Math.max(width, minWidth), maxWidth)
|
const new_width = Math.min(Math.max(width, minWidth), maxWidth)
|
||||||
return Qt.size(new_width, height / (width / new_width))
|
return Qt.size(new_width, height / (width / new_width))
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_height = Math.min(Math.max(height, minHeight), maxHeight)
|
const new_height = Math.min(Math.max(height, minHeight), maxHeight)
|
||||||
return Qt.size(width / (height / new_height), new_height)
|
return Qt.size(width / (height / new_height), new_height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,9 +231,9 @@ QtObject {
|
||||||
|
|
||||||
|
|
||||||
function formatDuration(milliseconds) {
|
function formatDuration(milliseconds) {
|
||||||
let totalSeconds = milliseconds / 1000
|
const totalSeconds = milliseconds / 1000
|
||||||
|
|
||||||
let hours = Math.floor(totalSeconds / 3600)
|
const hours = Math.floor(totalSeconds / 3600)
|
||||||
let minutes = Math.floor((totalSeconds % 3600) / 60)
|
let minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||||
let seconds = Math.floor(totalSeconds % 60)
|
let seconds = Math.floor(totalSeconds % 60)
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ ApplicationWindow {
|
||||||
if (! obj.saveName || ! obj.saveProperties ||
|
if (! obj.saveName || ! obj.saveProperties ||
|
||||||
obj.saveProperties.length < 1) return
|
obj.saveProperties.length < 1) return
|
||||||
|
|
||||||
let propertyValues = {}
|
const propertyValues = {}
|
||||||
|
|
||||||
for (let prop of obj.saveProperties) {
|
for (const prop of obj.saveProperties) {
|
||||||
propertyValues[prop] = obj[prop]
|
propertyValues[prop] = obj[prop]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user