fix(log): make export work better for android

This commit is contained in:
Johannes Millan 2025-07-10 16:29:05 +02:00
parent 0ca5723ad0
commit a64b592705
4 changed files with 20 additions and 5 deletions

View file

@ -271,4 +271,10 @@ export const IssueLog = Log.withContext('issue');
export const DroidLog = Log.withContext('droid');
export const TaskLog = Log.withContext('task');
export const downloadLogs = (): void => download('SP-logs', Log.exportLogHistory());
export const downloadLogs = async (): Promise<void> => {
try {
await download('SP-logs.json', Log.exportLogHistory());
} catch (error) {
Log.err('Failed to download logs:', error);
}
};

View file

@ -101,7 +101,7 @@
>
<a
(click)="downloadLogs()"
(click)="downloadLogs(); $event?.preventDefault()"
href="#"
>Logs</a
>

View file

@ -44,6 +44,7 @@ import { PluginService } from '../../plugins/plugin.service';
import { PluginShortcutCfg } from '../../plugins/plugin-api.model';
import { ThemeSelectorComponent } from '../../core/theme/theme-selector/theme-selector.component';
import { downloadLogs, Log } from '../../core/log';
import { SnackService } from '../../core/snack/snack.service';
@Component({
selector: 'config-page',
@ -68,6 +69,7 @@ export class ConfigPageComponent implements OnInit, OnDestroy {
readonly globalThemeService = inject(GlobalThemeService);
private readonly _pluginBridgeService = inject(PluginBridgeService);
private readonly _pluginService = inject(PluginService);
private readonly _snackService = inject(SnackService);
T: typeof T = T;
globalConfigFormCfg: ConfigFormConfig;
@ -229,5 +231,12 @@ export class ConfigPageComponent implements OnInit, OnDestroy {
return (this.globalCfg as any)[sectionKey];
}
protected readonly downloadLogs = downloadLogs;
async downloadLogs(): Promise<void> {
try {
await downloadLogs();
this._snackService.open('Logs downloaded to android documents folder');
} catch (error) {
this._snackService.open('Failed to download logs');
}
}
}

View file

@ -3,10 +3,10 @@ import { Directory, Encoding, Filesystem, WriteFileResult } from '@capacitor/fil
import { IS_ANDROID_WEB_VIEW } from './is-android-web-view';
import { Log } from '../core/log';
export const download = (filename: string, stringData: string): void => {
export const download = async (filename: string, stringData: string): Promise<void> => {
const blob = new Blob([stringData], { type: 'text/plain;charset=utf-8' });
if (IS_ANDROID_WEB_VIEW) {
saveStringAsFile(filename, stringData);
await saveStringAsFile(filename, stringData);
} else {
saveAs(blob, filename);
}