Skip to content

Commit 459a2a3

Browse files
committed
Ready to print
1 parent aa3b445 commit 459a2a3

File tree

3 files changed

+75
-33
lines changed

3 files changed

+75
-33
lines changed

src/App.global.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
@apply outline-none hover:opacity-80 active:text-gray-300 active:outline-none focus:outline-none;
1212
}
1313

14-
input[type='text'] {
15-
@apply rounded focus:ring-blue-500 focus:outline-none focus:ring-2 focus:ring-inset;
14+
input[type='number'] {
15+
@apply px-1 py-0.5 rounded focus:ring-blue-500 focus:outline-none focus:ring-2 focus:ring-inset;
1616
}
1717

1818
input[type='radio'] {

src/components/printer/Main.tsx

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface Coord {
1212
const Main = () => {
1313
const [frameCoord, setFrameCoord] = useState<Coord>();
1414
const [nextCoord, setNextCoord] = useState<Coord>();
15+
const [pages, setPages] = useState(0);
1516

1617
const handleCloseScreen = (c: Coord) => {
1718
if (c.select === 'frame') {
@@ -31,46 +32,75 @@ const Main = () => {
3132
ipcRenderer.invoke('open-screen', { select });
3233
};
3334

35+
const handlePrint = () => {
36+
ipcRenderer.invoke('start-printing', { frameCoord, nextCoord, pages });
37+
};
38+
3439
ipcRenderer.on('close-screen', (_, c: Coord) => {
3540
handleCloseScreen(c);
3641
});
3742

3843
return (
39-
<section className="flex flex-col items-start justify-center p-8 space-y-8">
40-
<section className="flex items-center justify-start">
41-
<button
42-
type="button"
43-
onClick={() => handleOpenScreen('frame')}
44-
className="btn"
45-
>
46-
Select screenshot frame...
47-
</button>
48-
{frameCoord ? (
49-
<p>
50-
Frame: ({frameCoord.x0}, {frameCoord.y0}) and ({frameCoord.x1},{' '}
51-
{frameCoord.y1})
52-
</p>
53-
) : (
54-
<p />
55-
)}
44+
<section className="absolute inset-0 flex flex-col items-stretch justify-center p-8 space-y-8 bg-gray-100">
45+
<section className="flex flex-col items-stretch flex-1 p-4 border rounded space-y-7">
46+
<section className="flex items-center justify-start space-x-4">
47+
<button
48+
type="button"
49+
onClick={() => handleOpenScreen('frame')}
50+
className="btn"
51+
>
52+
Select screenshot frame...
53+
</button>
54+
{frameCoord ? (
55+
<p>
56+
Rect: ({frameCoord.x0}, {frameCoord.y0}) and ({frameCoord.x1},{' '}
57+
{frameCoord.y1})
58+
</p>
59+
) : (
60+
<p />
61+
)}
62+
</section>
63+
64+
<section className="flex items-center justify-start space-x-4">
65+
<button
66+
type="button"
67+
onClick={() => handleOpenScreen('next')}
68+
className="btn"
69+
>
70+
Select next button...
71+
</button>
72+
{nextCoord ? (
73+
<p>
74+
Point: ({(nextCoord.x0 + nextCoord.x1) / 2},{' '}
75+
{(nextCoord.y0 + nextCoord.y1) / 2})
76+
</p>
77+
) : (
78+
<p />
79+
)}
80+
</section>
81+
82+
<section className="flex items-center justify-start ml-1 space-x-4">
83+
<p>Total pages:</p>
84+
<input
85+
value={pages}
86+
onChange={(e) => setPages(parseInt(e.target.value, 10))}
87+
type="number"
88+
/>
89+
</section>
5690
</section>
5791

58-
<section className="flex items-center justify-start">
92+
<section className="flex flex-col items-center space-y-4">
5993
<button
6094
type="button"
61-
onClick={() => handleOpenScreen('next')}
62-
className="btn"
95+
onClick={handlePrint}
96+
className="w-full py-2 text-base btn"
97+
disabled={!frameCoord || !nextCoord || !pages}
6398
>
64-
Select next button...
99+
Start printing
65100
</button>
66-
{nextCoord ? (
67-
<p>
68-
Next button: ({(nextCoord.x0 + nextCoord.x1) / 2},{' '}
69-
{(nextCoord.y0 + nextCoord.y1) / 2})
70-
</p>
71-
) : (
72-
<p />
73-
)}
101+
<p className="opacity-50">
102+
You can stop printing anytime by pressing the &quot;ESC&quot; button
103+
</p>
74104
</section>
75105
</section>
76106
);

src/main.dev.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const installExtensions = async () => {
7171
.catch(console.log);
7272
};
7373

74+
let stopPrinting = false;
75+
7476
const createWindow = async () => {
7577
if (
7678
process.env.NODE_ENV === 'development' ||
@@ -89,8 +91,8 @@ const createWindow = async () => {
8991

9092
mainWindow = new BrowserWindow({
9193
show: false,
92-
width: 1024,
93-
height: 728,
94+
width: 512,
95+
height: 364,
9496
icon: getAssetPath('icon.png'),
9597
webPreferences: {
9698
nodeIntegration: true,
@@ -113,6 +115,12 @@ const createWindow = async () => {
113115
}
114116
});
115117

118+
mainWindow.webContents.on('before-input-event', (event, ipnut) => {
119+
if (ipnut.key === 'Escape') {
120+
stopPrinting = true;
121+
}
122+
});
123+
116124
mainWindow.on('closed', () => {
117125
mainWindow = null;
118126
});
@@ -224,6 +232,10 @@ ipcMain.handle('close-screen', (_, coord) => {
224232
screenWindow?.close();
225233
});
226234

235+
ipcMain.handle('start-printing', (_, { frameCoord, nextCoord, pages }) => {
236+
console.log('Print with params', frameCoord, nextCoord, pages);
237+
});
238+
227239
/**
228240
* Add event listeners...
229241
*/

0 commit comments

Comments
 (0)