2020-09-23 19:57:54 -04:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-17 18:07:38 -04:00
|
|
|
import QtQuick 2.12
|
2019-12-02 16:29:29 -04:00
|
|
|
import "../.."
|
2020-08-03 01:19:08 -04:00
|
|
|
import ".."
|
2019-12-17 18:07:38 -04:00
|
|
|
|
|
|
|
QtObject {
|
2020-07-08 17:26:52 -04:00
|
|
|
signal deviceUpdateSignal(string forAccount)
|
|
|
|
|
2020-11-03 07:29:32 -04:00
|
|
|
function onNotificationRequested(
|
|
|
|
id, critical, bubble, sound, urgencyHint, title, body, image,
|
|
|
|
) {
|
2020-09-17 18:16:54 -04:00
|
|
|
const level = window.notificationLevel
|
|
|
|
|
|
|
|
if (level === Window.NotificationLevel.None) return
|
2020-11-03 07:29:32 -04:00
|
|
|
if (level === Window.MentionsKeywords && ! critical) return
|
2020-09-19 15:42:25 -04:00
|
|
|
if (window.notifiedIds.has(id)) return
|
|
|
|
|
|
|
|
window.notifiedIds.add(id)
|
|
|
|
window.notifiedIdsChanged()
|
|
|
|
|
2020-11-03 07:29:32 -04:00
|
|
|
if (Qt.application.state === Qt.ApplicationActive)
|
|
|
|
return
|
2020-09-16 11:31:34 -04:00
|
|
|
|
2020-11-03 07:29:32 -04:00
|
|
|
if (bubble)
|
|
|
|
py.callCoro("desktop_notify", [title, body, image])
|
2020-09-16 11:31:34 -04:00
|
|
|
|
2020-11-03 07:29:32 -04:00
|
|
|
if (urgencyHint) {
|
|
|
|
const msec =
|
|
|
|
critical ?
|
|
|
|
window.settings.Notifications.urgent_alert_time * 1000 :
|
|
|
|
window.settings.Notifications.alert_time * 1000
|
2020-03-24 11:31:32 -04:00
|
|
|
|
2020-11-03 07:29:32 -04:00
|
|
|
// -1 ? 0 for no time out : msec
|
|
|
|
if (msec !== 0) window.alert(msec === -1 ? 0 : msec)
|
|
|
|
}
|
2019-12-17 18:07:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function onCoroutineDone(uuid, result, error, traceback) {
|
2020-10-29 04:40:15 -04:00
|
|
|
if (! Globals.pendingCoroutines[uuid]) return
|
|
|
|
|
2020-03-08 04:46:20 -04:00
|
|
|
const onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
|
|
|
const onError = Globals.pendingCoroutines[uuid].onError
|
2019-12-17 18:07:38 -04:00
|
|
|
|
2019-12-02 16:29:29 -04:00
|
|
|
delete Globals.pendingCoroutines[uuid]
|
2020-05-06 13:39:53 -04:00
|
|
|
Globals.pendingCoroutinesChanged()
|
2019-12-26 09:20:51 -04:00
|
|
|
|
2019-12-17 18:07:38 -04:00
|
|
|
if (error) {
|
2019-12-26 09:20:51 -04:00
|
|
|
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
|
|
|
const args = py.getattr(error, "args")
|
2019-12-17 18:07:38 -04:00
|
|
|
|
2020-03-13 02:52:38 -04:00
|
|
|
if (type === "CancelledError") return
|
2019-12-17 18:07:38 -04:00
|
|
|
|
2020-03-15 15:40:53 -04:00
|
|
|
onError ?
|
|
|
|
onError(type, args, error, traceback, uuid) :
|
2020-08-03 01:19:08 -04:00
|
|
|
py.showError(type, traceback, "", uuid)
|
2020-03-15 15:40:53 -04:00
|
|
|
|
|
|
|
return
|
2019-12-26 09:20:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (onSuccess) onSuccess(result)
|
2019-12-17 18:07:38 -04:00
|
|
|
}
|
|
|
|
|
2019-12-26 10:05:01 -04:00
|
|
|
function onLoopException(message, error, traceback) {
|
|
|
|
// No need to log these here, the asyncio exception handler does it
|
|
|
|
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
2020-10-07 19:38:14 -04:00
|
|
|
py.showError(type, traceback, "", message)
|
2019-12-26 10:05:01 -04:00
|
|
|
}
|
|
|
|
|
2021-01-19 13:22:29 -04:00
|
|
|
function onPre070SettingsDetected(path) {
|
|
|
|
window.makePopup("Popups/Pre070SettingsDetectedPopup.qml", {path})
|
|
|
|
}
|
|
|
|
|
2020-10-05 03:06:07 -04:00
|
|
|
function onUserFileChanged(type, newData) {
|
|
|
|
if (type === "Theme") {
|
|
|
|
window.theme = Qt.createQmlObject(newData, window, "theme")
|
|
|
|
utils.theme = window.theme
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type === "Settings" ? window.settings = newData :
|
2020-11-17 08:24:55 -04:00
|
|
|
type === "NewTheme" ? window.themeRules = newData :
|
2020-10-05 03:06:07 -04:00
|
|
|
type === "UIState" ? window.uiState = newData :
|
|
|
|
type === "History" ? window.history = newData :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
2020-09-02 13:38:11 -04:00
|
|
|
function onModelItemSet(syncId, indexThen, indexNow, changedFields) {
|
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
|
2020-04-07 11:58:26 -04:00
|
|
|
if (indexThen === undefined) {
|
2020-04-14 10:55:01 -04:00
|
|
|
// print("insert", syncId, indexThen, indexNow,
|
|
|
|
// JSON.stringify(changedFields))
|
2020-09-02 13:38:11 -04:00
|
|
|
model.insert(indexNow, changedFields)
|
|
|
|
model.idToItems[changedFields.id] = model.get(indexNow)
|
|
|
|
model.idToItemsChanged()
|
2020-04-07 11:58:26 -04:00
|
|
|
|
|
|
|
} else {
|
2020-04-14 10:55:01 -04:00
|
|
|
// print("set", syncId, indexThen, indexNow,
|
|
|
|
// JSON.stringify(changedFields))
|
2020-04-07 11:58:26 -04:00
|
|
|
model.set(indexThen, changedFields)
|
2020-05-01 00:30:26 -04:00
|
|
|
|
2020-04-07 11:58:26 -04:00
|
|
|
if (indexThen !== indexNow) model.move(indexThen, indexNow, 1)
|
2020-05-01 00:30:26 -04:00
|
|
|
|
|
|
|
model.fieldsChanged(indexNow, changedFields)
|
2020-04-07 11:58:26 -04:00
|
|
|
}
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
2020-09-02 13:38:11 -04:00
|
|
|
function onModelItemDeleted(syncId, index, count=1, ids=[]) {
|
|
|
|
// print("delete", syncId, index, count, ids)
|
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
model.remove(index, count)
|
|
|
|
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
delete model.idToItems[ids[i]]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ids.length) model.idToItemsChanged()
|
2019-12-02 16:29:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function onModelCleared(syncId) {
|
|
|
|
// print("clear", syncId)
|
2020-09-04 10:58:04 -04:00
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
model.clear()
|
2020-09-02 13:38:11 -04:00
|
|
|
model.idToItems = {}
|
2019-12-17 18:07:38 -04:00
|
|
|
}
|
2020-07-08 17:26:52 -04:00
|
|
|
|
|
|
|
function onDevicesUpdated(forAccount) {
|
|
|
|
deviceUpdateSignal(forAccount)
|
|
|
|
}
|
2020-09-04 11:21:36 -04:00
|
|
|
|
|
|
|
function onInvalidAccessToken(userId) {
|
|
|
|
window.makePopup("Popups/InvalidAccessTokenPopup.qml", {userId})
|
|
|
|
}
|
2019-12-17 18:07:38 -04:00
|
|
|
}
|