mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 13:06:01 +02:00
feat(print): add printer descriptions
This commit is contained in:
@@ -22,8 +22,19 @@ const DESTINATION_PDF = "__pdf__";
|
||||
interface PrinterInfo {
|
||||
name: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
location: string;
|
||||
isDefault: boolean;
|
||||
}
|
||||
|
||||
/** Builds the description line shown under a printer in the dropdown. */
|
||||
function buildPrinterDescription(printer: PrinterInfo): string | undefined {
|
||||
const parts: string[] = [];
|
||||
if (printer.isDefault) parts.push(t("print_preview.destination_default"));
|
||||
if (printer.location) parts.push(printer.location);
|
||||
else if (printer.description) parts.push(printer.description);
|
||||
return parts.length ? parts.join(" · ") : undefined;
|
||||
}
|
||||
const MARGIN_PRESETS = ["default", "none", "minimum"] as const;
|
||||
type MarginPreset = typeof MARGIN_PRESETS[number];
|
||||
|
||||
@@ -313,7 +324,7 @@ export default function PrintPreviewDialog() {
|
||||
icon="bx bx-printer"
|
||||
selected={destination === printer.name}
|
||||
onClick={() => setDestination(printer.name)}
|
||||
description={printer.isDefault ? t("print_preview.destination_default") : undefined}
|
||||
description={buildPrinterDescription(printer)}
|
||||
>
|
||||
{printer.displayName || printer.name}
|
||||
</FormListItem>
|
||||
|
||||
@@ -277,7 +277,18 @@ interface PrintFromPreviewOpts extends ExportAsPdfOpts {
|
||||
|
||||
electron.ipcMain.handle("get-printers", async (e) => {
|
||||
try {
|
||||
return await e.sender.getPrintersAsync();
|
||||
const printers = await e.sender.getPrintersAsync();
|
||||
return printers.map((p) => {
|
||||
// Platform-specific: CUPS uses "printer-location", Windows/mac often expose "location".
|
||||
const opts = (p.options ?? {}) as Record<string, string>;
|
||||
return {
|
||||
name: p.name,
|
||||
displayName: p.displayName,
|
||||
description: p.description,
|
||||
location: opts["printer-location"] || opts.location || "",
|
||||
isDefault: (p as unknown as { isDefault?: boolean }).isDefault ?? false
|
||||
};
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user