mirror of
https://github.com/MultiMote/niimblue
synced 2026-01-19 19:37:11 +03:00
Print tasks rework
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource-variable/noto-sans": "^5.0.5",
|
||||
"@mmote/niimbluelib": "0.0.1-alpha.8",
|
||||
"@mmote/niimbluelib": "0.0.1-alpha.9",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"bootstrap": "5.3.3",
|
||||
"d3-dsv": "^3.0.1",
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
type EncodedImage,
|
||||
ImageEncoder,
|
||||
LabelType,
|
||||
PrintTaskVersion,
|
||||
printTaskNames,
|
||||
type PrintProgressEvent,
|
||||
type PrintTaskName,
|
||||
} from "@mmote/niimbluelib";
|
||||
import type { LabelProps, PostProcessType, FabricJson, PreviewProps } from "../types";
|
||||
import ParamLockButton from "./ParamLockButton.svelte";
|
||||
@@ -39,11 +40,11 @@
|
||||
let thresholdValue: number = 140;
|
||||
let originalImage: ImageData;
|
||||
let previewContext: CanvasRenderingContext2D;
|
||||
let printTaskVersion: PrintTaskVersion = PrintTaskVersion.V3;
|
||||
let printTaskName: PrintTaskName = "D110";
|
||||
let labelType: LabelType = LabelType.WithGaps;
|
||||
let statusTimer: NodeJS.Timeout | undefined = undefined;
|
||||
let error: string = "";
|
||||
let taskVer = $printerClient?.getPrintTaskVersion();
|
||||
let detectedPrintTaskName: PrintTaskName | undefined = $printerClient?.getPrintTaskType();
|
||||
let csvParsed: DSVRowArray<string>;
|
||||
let page = 0;
|
||||
let pagesTotal = 1;
|
||||
@@ -72,8 +73,16 @@
|
||||
error = "";
|
||||
$printerClient.stopHeartbeat();
|
||||
|
||||
// do it in a stupid way (library not supports multi-page print yet)
|
||||
// do it in a stupid way (multi-page print not finished yet)
|
||||
for (let curPage = 0; curPage < pagesTotal; curPage++) {
|
||||
const printTask = $printerClient.abstraction.newPrintTask(printTaskName, {
|
||||
totalPages: quantity,
|
||||
density,
|
||||
labelType,
|
||||
statusPollIntervalMs: 100,
|
||||
statusTimeoutMs: 8_000
|
||||
})
|
||||
|
||||
page = curPage;
|
||||
console.log("Printing page", page);
|
||||
|
||||
@@ -81,7 +90,8 @@
|
||||
const encoded: EncodedImage = ImageEncoder.encodeCanvas(previewCanvas, labelProps.printDirection);
|
||||
|
||||
try {
|
||||
await $printerClient.abstraction.print(printTaskVersion, encoded, { quantity, density, labelType });
|
||||
await printTask.printInit();
|
||||
await printTask.printPage(encoded, quantity);
|
||||
} catch (e) {
|
||||
error = `${e}`;
|
||||
console.error(e);
|
||||
@@ -97,9 +107,7 @@
|
||||
$printerClient.addEventListener("printprogress", listener);
|
||||
|
||||
try {
|
||||
await $printerClient.abstraction.waitUntilPrintFinished(printTaskVersion, quantity, {
|
||||
pollIntervalMs: 100, timeoutMs: 8_000
|
||||
});
|
||||
await printTask.waitForFinished();
|
||||
} catch (e) {
|
||||
error = `${e}`;
|
||||
console.error(e);
|
||||
@@ -110,6 +118,7 @@
|
||||
await endPrint();
|
||||
}
|
||||
|
||||
|
||||
printState = "idle";
|
||||
$printerClient.startHeartbeat();
|
||||
|
||||
@@ -169,7 +178,7 @@
|
||||
if (saved.quantity) quantity = saved.quantity;
|
||||
if (saved.density) density = saved.density;
|
||||
if (saved.labelType) labelType = saved.labelType;
|
||||
if (saved.printTaskVersion) printTaskVersion = saved.printTaskVersion;
|
||||
if (saved.printTaskName) printTaskName = saved.printTaskName;
|
||||
} catch (e) {
|
||||
Toasts.zodErrors(e, "Preview parameters load error:");
|
||||
}
|
||||
@@ -242,9 +251,9 @@
|
||||
onClosed();
|
||||
});
|
||||
|
||||
if (taskVer !== undefined) {
|
||||
console.log(`Detected print task version: ${PrintTaskVersion[taskVer]}`);
|
||||
printTaskVersion = taskVer;
|
||||
if (detectedPrintTaskName !== undefined) {
|
||||
console.log(`Detected print task version: ${detectedPrintTaskName}`);
|
||||
printTaskName = detectedPrintTaskName;
|
||||
}
|
||||
|
||||
loadProps();
|
||||
@@ -394,32 +403,22 @@
|
||||
</div>
|
||||
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text">{$tr("preview.print_task_version")}</span>
|
||||
<span class="input-group-text">{$tr("preview.print_task")}</span>
|
||||
<select
|
||||
class="form-select"
|
||||
bind:value={printTaskVersion}
|
||||
on:change={() => updateSavedProp("printTaskVersion", printTaskVersion)}>
|
||||
<option value={PrintTaskVersion.V1}>
|
||||
{#if taskVer === PrintTaskVersion.V1}✔{/if} V1 - D11/B21
|
||||
</option>
|
||||
<option value={PrintTaskVersion.V2}>
|
||||
{#if taskVer === PrintTaskVersion.V2}✔{/if} V2
|
||||
</option>
|
||||
<option value={PrintTaskVersion.V3}>
|
||||
{#if taskVer === PrintTaskVersion.V3}✔{/if} V3 - D110
|
||||
</option>
|
||||
<option value={PrintTaskVersion.V4}>
|
||||
{#if taskVer === PrintTaskVersion.V4}✔{/if} V4 - B1
|
||||
</option>
|
||||
<option value={PrintTaskVersion.V5}>
|
||||
{#if taskVer === PrintTaskVersion.V5}✔{/if} V5
|
||||
</option>
|
||||
bind:value={printTaskName}
|
||||
on:change={() => updateSavedProp("printTaskName", printTaskName)}>
|
||||
{#each printTaskNames as name}
|
||||
<option value={name}>
|
||||
{#if detectedPrintTaskName === name}✔{/if} {name}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<ParamLockButton
|
||||
propName="printTaskVersion"
|
||||
value={printTaskVersion}
|
||||
savedValue={savedProps.printTaskVersion}
|
||||
propName="printTaskName"
|
||||
value={printTaskName}
|
||||
savedValue={savedProps.printTaskName}
|
||||
onClick={toggleSavedProp} />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export const translation_en = {
|
||||
"preview.postprocess.atkinson": "Dither (Atkinson)",
|
||||
"preview.postprocess.threshold": "Threshold",
|
||||
"preview.postprocess": "Post-process",
|
||||
"preview.print_task_version": "Print task version",
|
||||
"preview.print_task": "Print task",
|
||||
"preview.print": "Print",
|
||||
"preview.threshold": "Threshold",
|
||||
"preview.title": "Print preview",
|
||||
|
||||
@@ -33,7 +33,7 @@ export const translation_ru: Record<TranslationKey, string> = {
|
||||
"preview.threshold": "Порог",
|
||||
"preview.copies": "Копии",
|
||||
"preview.density": "Плотность",
|
||||
"preview.print_task_version": "Версия задачи печати",
|
||||
"preview.print_task": "Задача печати",
|
||||
"preview.not_implemented": "НЕ РЕАЛИЗОВАНО",
|
||||
"preview.close": "Закрыть",
|
||||
"preview.print": "Печать",
|
||||
|
||||
@@ -109,7 +109,7 @@ export const translation_zh_cn: Partial<Record<TranslationKey, string>> = {
|
||||
"preview.postprocess.atkinson": "抖动(Atkinson)",
|
||||
"preview.postprocess.threshold": "阈值化",
|
||||
"preview.postprocess": "前置处理器",
|
||||
"preview.print_task_version": "打印接口版本",
|
||||
"preview.print_task": "打印接口",
|
||||
"preview.print": "打印",
|
||||
"preview.threshold": "阈值",
|
||||
"preview.title": "打印预览",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LabelType, PrintTaskVersion } from "@mmote/niimbluelib";
|
||||
import { LabelType, printTaskNames } from "@mmote/niimbluelib";
|
||||
import { fabric } from "fabric";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -41,13 +41,15 @@ export const ExportedLabelTemplateSchema = z.object({
|
||||
label: LabelPropsSchema,
|
||||
});
|
||||
|
||||
const [firstTask, ...otherTasks] = printTaskNames;
|
||||
|
||||
export const PreviewPropsSchema = z.object({
|
||||
postProcess: z.enum(["threshold", "dither"]).optional(),
|
||||
threshold: z.number().gte(1).lte(255).optional(),
|
||||
quantity: z.number().gte(1).optional(),
|
||||
density: z.number().gte(1).optional(),
|
||||
labelType: z.nativeEnum(LabelType).optional(),
|
||||
printTaskVersion: z.nativeEnum(PrintTaskVersion).optional(),
|
||||
printTaskName: z.enum([firstTask, ...otherTasks]).optional(),
|
||||
});
|
||||
|
||||
export type LabelProps = z.infer<typeof LabelPropsSchema>;
|
||||
|
||||
@@ -162,10 +162,10 @@
|
||||
"@jridgewell/resolve-uri" "^3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||
|
||||
"@mmote/niimbluelib@0.0.1-alpha.8":
|
||||
version "0.0.1-alpha.8"
|
||||
resolved "https://registry.yarnpkg.com/@mmote/niimbluelib/-/niimbluelib-0.0.1-alpha.8.tgz#960e0d46accc5490901f605defc46520fd03e3bb"
|
||||
integrity sha512-g8+c3eTbe8M5OIeVrrdHbG1JnX+izLHgnsUcatm+SlPEatHK8dWyT8zpae+0Fj+bg6mpwlPjLaR/FGYjx3Mt3g==
|
||||
"@mmote/niimbluelib@0.0.1-alpha.9":
|
||||
version "0.0.1-alpha.9"
|
||||
resolved "https://registry.yarnpkg.com/@mmote/niimbluelib/-/niimbluelib-0.0.1-alpha.9.tgz#ada0039701c7a33ee04bc86b3ffae6ec7e4eba57"
|
||||
integrity sha512-ajgNq0nkV5borEWdTTWuxs/i6rFeB16XBsVmvbZR8Pfdm+56yQXS/tURthsvgrTwaKbtV1/606SXPwbONY59OA==
|
||||
dependencies:
|
||||
async-mutex "^0.5.0"
|
||||
typescript-event-target "^1.1.1"
|
||||
|
||||
Reference in New Issue
Block a user