@esslassi/electron-printer 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
- #include "printer_factory.h"
2
-
3
- #ifdef _WIN32
4
- #include "windows_printer.h"
5
- #elif defined(__APPLE__)
6
- #include "mac_printer.h"
7
- #else
8
- #include "linux_printer.h"
9
- #endif
10
-
11
- std::unique_ptr<PrinterInterface> PrinterFactory::Create()
12
- {
13
- #ifdef _WIN32
14
- return std::make_unique<WindowsPrinter>();
15
- #elif defined(__APPLE__)
16
- return std::make_unique<MacPrinter>();
17
- #else
18
- return std::make_unique<LinuxPrinter>();
19
- #endif
1
+ #include "printer_factory.h"
2
+
3
+ #ifdef _WIN32
4
+ #include "windows_printer.h"
5
+ #elif defined(__APPLE__)
6
+ #include "mac_printer.h"
7
+ #else
8
+ #include "linux_printer.h"
9
+ #endif
10
+
11
+ std::unique_ptr<PrinterInterface> PrinterFactory::Create()
12
+ {
13
+ #ifdef _WIN32
14
+ return std::make_unique<WindowsPrinter>();
15
+ #elif defined(__APPLE__)
16
+ return std::make_unique<MacPrinter>();
17
+ #else
18
+ return std::make_unique<LinuxPrinter>();
19
+ #endif
20
20
  }
@@ -1,13 +1,13 @@
1
- #ifndef PRINTER_FACTORY_H
2
- #define PRINTER_FACTORY_H
3
-
4
- #include "printer_interface.h"
5
- #include <memory>
6
-
7
- class PrinterFactory
8
- {
9
- public:
10
- static std::unique_ptr<PrinterInterface> Create();
11
- };
12
-
1
+ #ifndef PRINTER_FACTORY_H
2
+ #define PRINTER_FACTORY_H
3
+
4
+ #include "printer_interface.h"
5
+ #include <memory>
6
+
7
+ class PrinterFactory
8
+ {
9
+ public:
10
+ static std::unique_ptr<PrinterInterface> Create();
11
+ };
12
+
13
13
  #endif
@@ -1,29 +1,67 @@
1
- #ifndef PRINTER_INTERFACE_H
2
- #define PRINTER_INTERFACE_H
3
-
4
- #include <string>
5
- #include <vector>
6
- #include <map>
7
- #include <cstdint>
8
-
9
- struct PrinterInfo
10
- {
11
- std::string name;
12
- bool isDefault;
13
- std::map<std::string, std::string> details;
14
- std::string status;
15
- };
16
-
17
- class PrinterInterface
18
- {
19
- public:
20
- virtual ~PrinterInterface() = default;
21
-
22
- virtual PrinterInfo GetPrinterDetails(const std::string &printerName, bool isDefault = false) = 0;
23
- virtual std::vector<PrinterInfo> GetPrinters() = 0;
24
- virtual PrinterInfo GetSystemDefaultPrinter() = 0;
25
- virtual bool PrintDirect(const std::string &printerName, const std::vector<uint8_t> &data, const std::string &dataType) = 0;
26
- virtual PrinterInfo GetStatusPrinter(const std::string &printerName) = 0;
27
- };
28
-
1
+ #ifndef PRINTER_INTERFACE_H
2
+ #define PRINTER_INTERFACE_H
3
+
4
+ #include <string>
5
+ #include <vector>
6
+ #include <map>
7
+ #include <cstdint>
8
+ #include <ctime>
9
+
10
+ using StringMap = std::map<std::string, std::string>;
11
+ using DriverOptions = std::map<std::string, std::map<std::string, bool>>;
12
+
13
+ struct PrinterDetailsNative {
14
+ std::string name;
15
+ bool isDefault = false;
16
+ StringMap options; // matches TS: options: { [k:string]: string }
17
+ };
18
+
19
+ struct JobDetailsNative {
20
+ int id = 0;
21
+ std::string name;
22
+ std::string printerName;
23
+ std::string user;
24
+ std::string format;
25
+ int priority = 0;
26
+ int size = 0;
27
+
28
+ std::vector<std::string> status; // TS: JobStatus[]
29
+ std::time_t completedTime = 0;
30
+ std::time_t creationTime = 0;
31
+ std::time_t processingTime = 0;
32
+ };
33
+
34
+ class PrinterInterface
35
+ {
36
+ public:
37
+ virtual ~PrinterInterface() = default;
38
+
39
+ // Printers
40
+ virtual std::vector<PrinterDetailsNative> GetPrinters() = 0;
41
+ virtual PrinterDetailsNative GetPrinter(const std::string &printerName) = 0;
42
+ virtual std::string GetDefaultPrinterName() = 0;
43
+
44
+ // Driver options & paper
45
+ virtual DriverOptions GetPrinterDriverOptions(const std::string &printerName) = 0;
46
+ virtual std::string GetSelectedPaperSize(const std::string &printerName) = 0;
47
+
48
+ // Printing
49
+ // return jobId (>0) or 0 on failure
50
+ virtual int PrintDirect(const std::string &printerName,
51
+ const std::vector<uint8_t> &data,
52
+ const std::string &type,
53
+ const StringMap &options) = 0;
54
+
55
+ virtual int PrintFile(const std::string &printerName,
56
+ const std::string &filename) = 0;
57
+
58
+ // Capabilities
59
+ virtual std::vector<std::string> GetSupportedPrintFormats() = 0;
60
+
61
+ // Jobs
62
+ virtual JobDetailsNative GetJob(const std::string &printerName, int jobId) = 0;
63
+ virtual void SetJob(const std::string &printerName, int jobId, const std::string &command) = 0;
64
+ virtual std::vector<std::string> GetSupportedJobCommands() = 0;
65
+ };
66
+
29
67
  #endif