Skip to content

Commit

Permalink
New error screen, auto reports, inclusivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Sominemo committed May 7, 2020
1 parent 868f67e commit 4ac6826
Show file tree
Hide file tree
Showing 26 changed files with 784 additions and 60 deletions.
9 changes: 7 additions & 2 deletions src/app/loaders/Accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ import { CoreLoader, CoreLoaderSkip, CoreLoaderResult } from "@Core/Init/CoreLoa
import Listeners from "@Core/Services/Listeners"
import SettingsStorage from "@Core/Services/Settings/SettingsStorage"
import DOMController from "@DOMPath/DOM/Helpers/domController"
import { Scaffold } from "@Environment/Library/DOM/buildBlock"

CoreLoader.registerTask({
id: "accesibility",
presence: "Accesibility features",
async task() {
if (!await SettingsStorage.getFlag("enable_tab_navigation")) return new CoreLoaderSkip()
if (!await SettingsStorage.getFlag("enable_tab_navigation")) {
return new CoreLoaderSkip()
}

DOMController.setConfig({
eventsOnClickAutoTabIndex: true,
})

Listeners.add(document, "keypress", (a) => { if (a.code === "Enter") { document.activeElement.click() } })
Listeners.add(document, "keypress", (a) => { if (a.keyCode === 13 || a.which === 13) { document.activeElement.click() } })

Scaffold.accessibility = true

return new CoreLoaderResult()
},
Expand Down
18 changes: 2 additions & 16 deletions src/app/loaders/CrossMessenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import Listeners from "@Core/Services/Listeners"
import Auth from "@App/modules/mono/services/Auth"
import SettingsStorage from "@Core/Services/Settings/SettingsStorage"
import { CoreLoader, CoreLoaderSkip, CoreLoaderResult } from "@Core/Init/CoreLoader"
import resetApp from "@App/tools/interaction/resetApp"
import { Report } from "@Core/Services/Report"
import DBTool from "@Core/Tools/db/DBTool"
import ObjectStoreTool from "@Core/Tools/db/ObjectStoreTool"

const trustedOrigins = __TRUSTED_ORIGINS

Expand All @@ -19,20 +18,7 @@ async function messageListener(m) {

try {
if (m.data.command === "clear") {
let dbs = [{ name: "AuthStorage" }, { name: "OfflineCache" }, { name: "SettingsStorage" }, { name: "StatementStorage" }]
if ("databases" in indexedDB) {
dbs = await window.indexedDB.databases()
}
await Promise.all(dbs.map(async (db) => new Promise(async (resolve, reject) => {
try {
const dbase = new DBTool(db.name, null)
const osList = await dbase.getTablesList()
await Promise.all(osList.map((r) => new ObjectStoreTool(dbase, r).clear()))
resolve()
} catch (e) {
reject(e)
}
})))
await resetApp()
} else if (m.data.command === "import-accounts") {
const accounts = (await Auth.accountsDB())
await Promise.all(m.data.accounts.map((item) => accounts.put(item)))
Expand Down
49 changes: 49 additions & 0 deletions src/app/loaders/Presets/AutoErrorReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Report, ReportLogger, ReportStorage } from "@Core/Services/Report"
import errorToObject from "@Core/Tools/transformation/object/errorToObject"
import PWA from "@App/modules/main/PWA"
import DBUserPresence from "@Core/Services/DBUserPresence"

const beaconsAllowed = (
PWA.isWG
|| localStorage.getItem("beacon_error_reports") !== "0"
)

if (beaconsAllowed) {
Report.newHook((report) => {
if (report.level >= 3) {
navigator.sendBeacon("https://sominemo.com/mono/help/report/beacon",
JSON.stringify(
{
log: errorToObject(report.log),
v: `${PWA.version}/${PWA.branch}/${PWA.buildDate}`,
},
))
}
}, "errorReporting")
}

const autosendAllowed = (
PWA.isWG
|| localStorage.getItem("reports_auto_sending") === "1"
)

if (autosendAllowed) {
Report.newHook((report) => {
if (report.level >= 3) {
DBUserPresence.get("ReportData").functions.find((e) => e.name === "send").handler(report.log)
.then(() => {
Report.add("Report sent", ["report.storage"])
})
}
}, "reportAutoSend")
}

const extendedLoggingAllowed = (
PWA.buildFlag("local")
|| localStorage.getItem("reports_extended_logging") === "1"
)

if (extendedLoggingAllowed) {
ReportLogger.loggingLevel = -2
ReportStorage.loggingLevel = -2
}
Loading

0 comments on commit 4ac6826

Please sign in to comment.