complete settings view model for logs ui
This commit is contained in:
parent
69ada73dd4
commit
375d8b066c
4 changed files with 52 additions and 15 deletions
|
@ -52,6 +52,7 @@ export class SettingsViewModel extends ViewModel {
|
|||
this.maxSentImageSizeLimit = 4000;
|
||||
this.pushNotifications = new PushNotificationStatus();
|
||||
this._activeTheme = undefined;
|
||||
this._logsFeedbackMessage = undefined;
|
||||
}
|
||||
|
||||
get _session() {
|
||||
|
@ -153,19 +154,49 @@ export class SettingsViewModel extends ViewModel {
|
|||
this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`);
|
||||
}
|
||||
|
||||
get canSendLogsToServer() {
|
||||
return !!this.platform.config.bugReportEndpointUrl;
|
||||
}
|
||||
|
||||
get logsServer() {
|
||||
const {bugReportEndpointUrl} = this.platform.config;
|
||||
try {
|
||||
if (bugReportEndpointUrl) {
|
||||
return new URL(bugReportEndpointUrl).hostname;
|
||||
}
|
||||
} catch (e) {}
|
||||
return "";
|
||||
}
|
||||
|
||||
async sendLogsToServer() {
|
||||
const logExport = await this.logger.export();
|
||||
await submitLogsToRageshakeServer(
|
||||
{
|
||||
app: "hydrogen",
|
||||
userAgent: "<missing>",
|
||||
version: DEFINE_VERSION,
|
||||
text: "Submit logs from settings",
|
||||
},
|
||||
logExport.asBlob(),
|
||||
this.platform.config.bugReportEndpointUrl,
|
||||
this.platform.request
|
||||
);
|
||||
const {bugReportEndpointUrl} = this.platform.config;
|
||||
if (bugReportEndpointUrl) {
|
||||
this._logsFeedbackMessage = this.i18n`Sending logs…`;
|
||||
this.emitChange();
|
||||
try {
|
||||
const logExport = await this.logger.export();
|
||||
await submitLogsToRageshakeServer(
|
||||
{
|
||||
app: "hydrogen",
|
||||
userAgent: this.platform.description,
|
||||
version: DEFINE_VERSION,
|
||||
text: `Submit logs from settings for user ${this._session.userId} on device ${this._session.deviceId}`,
|
||||
},
|
||||
logExport.asBlob(),
|
||||
bugReportEndpointUrl,
|
||||
this.platform.request
|
||||
);
|
||||
this._logsFeedbackMessage = this.i18n`Logs sent succesfully!`;
|
||||
this.emitChange();
|
||||
} catch (err) {
|
||||
this._logsFeedbackMessage = err.message;
|
||||
this.emitChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get logsFeedbackMessage() {
|
||||
return this._logsFeedbackMessage;
|
||||
}
|
||||
|
||||
async togglePushNotifications() {
|
||||
|
|
|
@ -17,10 +17,12 @@ limitations under the License.
|
|||
|
||||
import {BlobHandle} from "../../platform/web/dom/BlobHandle.js";
|
||||
|
||||
export type RequestBody = BlobHandle | string | Map<string, string | {blob: BlobHandle, name: string}>;
|
||||
|
||||
export type EncodedBody = {
|
||||
mimeType: string;
|
||||
// the map gets transformed to a FormData object on the web
|
||||
body: BlobHandle | string | Map<string, string | {blob: BlobHandle, name: string}>;
|
||||
body: RequestBody
|
||||
}
|
||||
|
||||
export function encodeQueryParams(queryParams?: object): string {
|
||||
|
|
|
@ -15,13 +15,13 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import type {RequestResult} from "../web/dom/request/fetch.js";
|
||||
import type {EncodedBody} from "../../matrix/net/common";
|
||||
import type {RequestBody} from "../../matrix/net/common";
|
||||
import type {ILogItem} from "../../logging/types";
|
||||
|
||||
export interface IRequestOptions {
|
||||
uploadProgress?: (loadedBytes: number) => void;
|
||||
timeout?: number;
|
||||
body?: EncodedBody;
|
||||
body?: RequestBody;
|
||||
headers?: Map<string, string|number>;
|
||||
cache?: boolean;
|
||||
method?: string;
|
||||
|
|
|
@ -345,6 +345,10 @@ export class Platform {
|
|||
head.appendChild(styleTag);
|
||||
}
|
||||
|
||||
get description() {
|
||||
return navigator.userAgent ?? "<unknown>";
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._disposables.dispose();
|
||||
}
|
||||
|
|
Reference in a new issue