2023-10-24 13:20:54 +02:00
|
|
|
import { PluginSettings } from './services/plugins/PluginService';
|
|
|
|
import type PluginService from './services/plugins/PluginService';
|
2023-11-11 19:38:16 +02:00
|
|
|
import versionInfo, { PackageInfo } from './versionInfo';
|
2023-10-24 13:20:54 +02:00
|
|
|
|
|
|
|
const renderErrorBlock = (errors: any[]): string => {
|
|
|
|
if (!errors.length) return '';
|
|
|
|
return `\`\`\`\n${errors.map(e => typeof e === 'string' ? e.trim() : e.message.trim())}\n\`\`\``;
|
|
|
|
};
|
|
|
|
|
2023-11-11 19:38:16 +02:00
|
|
|
const getOsName = (platform: typeof process.platform) => {
|
|
|
|
if (platform === 'win32') return 'Windows';
|
|
|
|
if (platform === 'darwin') return 'macOS';
|
|
|
|
if (platform === 'linux') return 'Linux';
|
|
|
|
if (platform === 'android') return 'Android';
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (title: string, body: string, errors: any[], packageInfo: PackageInfo, pluginService: PluginService, pluginSettings: PluginSettings) => {
|
2023-10-24 13:20:54 +02:00
|
|
|
const v = versionInfo(packageInfo, pluginService.enabledPlugins(pluginSettings));
|
|
|
|
|
|
|
|
const errorBlock = renderErrorBlock(errors);
|
|
|
|
|
|
|
|
const query: Record<string, string> = {
|
|
|
|
title,
|
|
|
|
category: 'support',
|
2023-11-11 19:38:16 +02:00
|
|
|
version: packageInfo.version,
|
|
|
|
os: getOsName(process.platform),
|
|
|
|
'desktop-about-content': v.body,
|
|
|
|
content: `#### Body\n\n${body}${errorBlock ? `\n\n#### Errors\n\n${errorBlock}` : ''}`,
|
2023-10-24 13:20:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const queryString = Object.keys(query).map(k => `${k}=${encodeURIComponent(query[k])}`).join('&');
|
|
|
|
|
|
|
|
const url = `https://discourse.joplinapp.org/new-topic?${queryString}`;
|
|
|
|
return url;
|
|
|
|
};
|