Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
talyguryn committed Aug 6, 2018
1 parent 03c22e2 commit 46c2ef4
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.DS_Store
.idea
electron-builder.yml
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tray-icon-Template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tray-icon-Template@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icon.icns
Binary file not shown.
56 changes: 35 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
const {app, Tray: Index, Menu, BrowserWindow, globalShortcut} = require('electron');
const makeScreenshot = require('./shot');
const { app, Tray: Index, Menu, BrowserWindow, globalShortcut, shell } = require('electron');
const makeScreenshot = require('./src/shot');
const shortcut = require('./src/shortcut');
const path = require('path');
const fs = require('fs');

const iconPath = path.join(__dirname, 'assets', 'icon.png');
let appIcon = null;
let window = null;
app.on('ready', () => {
try {
/**
* Do not show app in Dock
*/
app.dock.hide();

app.on('ready', function(){
app.dock.hide();
/**
* Create hidden app window
*/
let window = new BrowserWindow({show: false});

window = new BrowserWindow({show: false});
appIcon = new Index(iconPath);
/**
* Set up icon
*/
const iconPath = path.join(__dirname, 'assets', 'tray-icon-Template.png'),
appIcon = new Index(iconPath);

const contextMenu = Menu.buildFromTemplate([
{
label: 'Quit',
accelerator: 'Command+Q',
selector: 'terminate:',
}
]);
appIcon.setContextMenu(contextMenu);
/**
* Prepare context menu
*/
const menuItems = require('./src/menu'),
contextMenu = Menu.buildFromTemplate(menuItems);

appIcon.setToolTip('Upload a shot to capella.pics: CMD+SHIFT+CTRL+5');
appIcon.setContextMenu(contextMenu);

globalShortcut.register('Command+Shift+Control+5', () => {
makeScreenshot();
})
/**
* Define global shortcut
*/
globalShortcut.register(shortcut, () => {
makeScreenshot();
});
} catch (e) {
console.log('e', e);
app.quit();
}
});
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 25 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
{
"name": "shotcapella",
"version": "1.0.0",
"description": "",
"description": "Upload screenshot to Capella and get a link to uploaded image into your clipboard",
"main": "index.js",
"scripts": {
"start": "electron .",
"build": "electron-builder"
"build": "electron-builder",
"ship": "electron-builder -m -p always"
},
"keywords": [],
"author": "",
"license": "ISC",
"author": {
"name": "Taly Guryn",
"url": "https://github.com/talyguryn"
},
"repository": {
"url": "https://github.com/codex-team/shotcapella"
},
"bugs": "https://github.com/codex-team/shotcapella/issues/new",
"license": "MIT",
"dependencies": {
"@codexteam/capella-pics": "^1.0.1",
"about-window": "^1.12.1",
"auto-launch": "^5.0.5",
"copy-paste": "^1.3.0",
"shelljs": "^0.8.2"
},
"devDependencies": {
"electron": "^2.0.6",
"electron-builder": "^20.26.1"
},
"publish": [
{
"provider": "github",
"owner": "codex-team",
"repo": "shotcapella"
}
],
"build": {
"appId": "pics.capella.mac-app"
"appId": "pics.capella.mac-app",
"dmg": {
"title": "shotcapella"
}
}
}
23 changes: 0 additions & 23 deletions shot.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/about-window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const openAboutWindow = require('about-window').default;
const path = require('path');

module.exports = () => {
openAboutWindow({
icon_path: path.join(__dirname, 'assets', 'icon.png'),
bug_report_url: process.env.npm_package_bugs_url,
bug_link_text: 'Report a bug',
description: process.env.npm_package_description,
license: 'MIT',
});
};
27 changes: 27 additions & 0 deletions src/auto-launch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const AutoLaunch = require('auto-launch');
const { app } = require('electron');

/**
* Compose path to app
*/
const appPath = app.getPath('exe').replace(/\.app\/Content.*/, '.app');

/**
* Get launch instance
*/
let launch = new AutoLaunch({ name: 'shotcapella', path: appPath, isHidden: false });

/**
* State toggler
*/
const launchToggle = () => {
launch.isEnabled().then(enabled => {
if (!enabled) {
launch.enable()
} else {
launch.disable()
}
})
};

module.exports = launchToggle;
44 changes: 44 additions & 0 deletions src/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require('path');
const { app } = require('electron');
const openAboutWindow = require('./about-window');
const makeScreenshot = require('./shot');
const shortcut = require('./shortcut');
const launchToggle = require('./auto-launch');

let launch;

module.exports = [
// {
// label: 'About',
// click() {
// shell.openExternal(process.env.npm_package_repository_url);
// }
// },
// {
// type: 'separator'
// },
{
label: 'Make a shot',
accelerator: shortcut,
click() {
makeScreenshot();
}
},
{
type: 'separator'
},
{
label: 'Open at Login',
type: 'checkbox',
checked: app.getLoginItemSettings().openAtLogin,
click: launchToggle,
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
selector: 'terminate:',
}
];
38 changes: 38 additions & 0 deletions src/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { Notification } = require('electron');

/**
* {@link https://electronjs.org/docs/api/notification#new-notificationoptions-experimental}
*
* @typedef {Object} notificationOptions
* @property {string} title - A title for the notification, which will be shown at the top of the notification window when it is shown.
* @property {string} [subtitle] - A subtitle for the notification, which will be displayed below the title.
* @property {string} body - The body text of the notification, which will be displayed below the title or subtitle.
* @property {boolean} [silent] - Whether or not to emit an OS notification noise when showing the notification.
* @property {string|NativeImage} [icon] - An icon to use in the notification.
* @property {boolean} [hasReply] - Whether or not to add an inline reply option to the notification.
* @property {string} [replyPlaceholder] - The placeholder to write in the inline reply input field.
* @property {string} [sound] - The name of the sound file to play when the notification is shown.
* @property {NotificationAction[]} [actions] - Actions to add to the notification. Please read the available actions and limitations in the NotificationAction documentation.
* @property {string} [closeButtonText] - A custom title for the close button of an alert. An empty string will cause the default localized text to be used.
*/

/**
* Wrapper for showing notifications
*
* @param {notificationOptions} options
* @param {function|null} callback
*/
const showNotification = (options, callback) => {
/**
* Show notification
*/
let notification = new Notification(options);

if (callback) {
notification.on('click', callback);
}

notification.show();
};

module.exports = showNotification;
1 change: 1 addition & 0 deletions src/shortcut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'Command+Shift+Control+5';
Loading

0 comments on commit 46c2ef4

Please sign in to comment.