Skip to content

Commit c353a51

Browse files
authored
feat(developer): take screenshot (#1404)
1 parent 7e4aea7 commit c353a51

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/electron/main.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const { autoUpdater } = require('electron-updater');
1111
const { onFirstRunMaybe } = require('./first-run');
1212
const path = require('node:path');
1313
const log = require('electron-log');
14+
const fs = require('node:fs');
15+
const os = require('node:os');
1416

1517
log.initialize();
1618
autoUpdater.logger = log;
@@ -51,6 +53,11 @@ const contextMenu = Menu.buildFromTemplate([
5153
accelerator:
5254
process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I',
5355
},
56+
{
57+
label: 'Take Screenshot',
58+
accelerator: 'CommandOrControl+S',
59+
click: () => takeScreenshot(),
60+
},
5461
{
5562
label: 'Reset App',
5663
click: () => {
@@ -176,6 +183,18 @@ app.whenReady().then(async () => {
176183
});
177184
});
178185

186+
function takeScreenshot() {
187+
const date = new Date();
188+
const dateStr = date.toISOString().replace(/:/g, '-');
189+
190+
const capturedPicFilePath = `${os.homedir()}/${dateStr}-gitify-screenshot.png`;
191+
mb.window.capturePage().then((img) => {
192+
fs.writeFile(capturedPicFilePath, img.toPNG(), () =>
193+
log.info(`Screenshot saved ${capturedPicFilePath}`),
194+
);
195+
});
196+
}
197+
179198
function resetApp() {
180199
const cancelButtonId = 0;
181200

0 commit comments

Comments
 (0)