Skip to content

Commit

Permalink
feat(developer): take screenshot (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Jul 29, 2024
1 parent 7e4aea7 commit c353a51
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { autoUpdater } = require('electron-updater');
const { onFirstRunMaybe } = require('./first-run');
const path = require('node:path');
const log = require('electron-log');
const fs = require('node:fs');
const os = require('node:os');

log.initialize();
autoUpdater.logger = log;
Expand Down Expand Up @@ -51,6 +53,11 @@ const contextMenu = Menu.buildFromTemplate([
accelerator:
process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I',
},
{
label: 'Take Screenshot',
accelerator: 'CommandOrControl+S',
click: () => takeScreenshot(),
},
{
label: 'Reset App',
click: () => {
Expand Down Expand Up @@ -176,6 +183,18 @@ app.whenReady().then(async () => {
});
});

function takeScreenshot() {
const date = new Date();
const dateStr = date.toISOString().replace(/:/g, '-');

const capturedPicFilePath = `${os.homedir()}/${dateStr}-gitify-screenshot.png`;
mb.window.capturePage().then((img) => {
fs.writeFile(capturedPicFilePath, img.toPNG(), () =>
log.info(`Screenshot saved ${capturedPicFilePath}`),
);
});
}

function resetApp() {
const cancelButtonId = 0;

Expand Down

0 comments on commit c353a51

Please sign in to comment.