Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ jobs:
--icon src/main/resources/BoatBookingSystem.ico `
--dest dist `
--win-dir-chooser `
--win-console `
--win-menu `
--win-menu-group "Boat Booking System - ${{ steps.release.outputs.tenantDisplayName }}" `
--win-shortcut `
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/boatticket/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
*/
public class ConfigManager {

// TVSE RP4230 at 203 dpi: an 80 mm roll with a 10 mm horizontal offset leaves 70 mm (560 dots)
// for ticket content. Normal ESC/POS font A fits 35 characters in that width.
private static final int DEFAULT_PRINTER_LEFT_MARGIN_DOTS = 80;
private static final int DEFAULT_PRINTER_WIDTH_DOTS = 560;
private static final int DEFAULT_PRINTER_CHARACTERS_PER_LINE = 35;
private static final int LEGACY_PRINTER_WIDTH_DOTS = 832;
private static final int LEGACY_PRINTER_CHARACTERS_PER_LINE = 52;

private static final String TENANT_ID = bundledTenantId();
private static final String APP_DIR =
System.getProperty("user.home")
Expand Down Expand Up @@ -180,6 +188,27 @@ public static String getPrinterName() {
return value == null ? "" : value.trim();
}

/** Printable width, in dots, used when sending raw ESC/POS tickets. */
public static int getPrinterWidthDots() {
if (usesLegacy108MmPrinterProfile()) {
return DEFAULT_PRINTER_WIDTH_DOTS;
}
return getInt("printer.width.dots", DEFAULT_PRINTER_WIDTH_DOTS);
}

/** Left margin, in dots, used when sending raw ESC/POS tickets. */
public static int getPrinterLeftMarginDots() {
return getInt("printer.left.margin.dots", DEFAULT_PRINTER_LEFT_MARGIN_DOTS);
}

/** Characters per line for the printer's normal font. */
public static int getPrinterCharactersPerLine() {
if (usesLegacy108MmPrinterProfile()) {
return DEFAULT_PRINTER_CHARACTERS_PER_LINE;
}
return getInt("printer.characters.per.line", DEFAULT_PRINTER_CHARACTERS_PER_LINE);
}

// ------------------------------------------------------------------
// Shared plumbing
// ------------------------------------------------------------------
Expand Down Expand Up @@ -214,6 +243,17 @@ private static int getInt(String key, int fallback) {
}
}

/**
* Existing installations keep their external configuration when the app is updated. Recognize
* only the old stock 108 mm values as a pair, so those installations automatically use the new 80
* mm profile without overriding deliberately customized settings.
*/
private static boolean usesLegacy108MmPrinterProfile() {
return LEGACY_PRINTER_WIDTH_DOTS == getInt("printer.width.dots", DEFAULT_PRINTER_WIDTH_DOTS)
&& LEGACY_PRINTER_CHARACTERS_PER_LINE
== getInt("printer.characters.per.line", DEFAULT_PRINTER_CHARACTERS_PER_LINE);
}

private static String getString(String key, String fallback) {
String value = getProperties().getProperty(key);
return value == null || value.isBlank() ? fallback : value.trim();
Expand Down Expand Up @@ -302,6 +342,11 @@ private static void writeHardcodedDefaults(Path configFilePath) throws IOExcepti
String.valueOf(DEFAULT_UPDATE_CONNECTION_TIMEOUT_SECONDS));
defaults.setProperty("dev.mode", String.valueOf(DEFAULT_DEV_MODE));
defaults.setProperty("printer.name", "");
defaults.setProperty(
"printer.left.margin.dots", String.valueOf(DEFAULT_PRINTER_LEFT_MARGIN_DOTS));
defaults.setProperty("printer.width.dots", String.valueOf(DEFAULT_PRINTER_WIDTH_DOTS));
defaults.setProperty(
"printer.characters.per.line", String.valueOf(DEFAULT_PRINTER_CHARACTERS_PER_LINE));

try (OutputStream outputStream = new FileOutputStream(configFilePath.toFile())) {
defaults.store(outputStream, "Boat Booking System - application configuration");
Expand Down
Loading
Loading