Skip to content

Commit

Permalink
Settings to open in browser or copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pablopunk committed Jun 1, 2019
1 parent 90300d2 commit f34cd68
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

It will only work on macOS as the drag-and-drop feature doesn't work on Linux and Windows.

## Performance

I know, it's build on electron. You're probably thinking *"Yet another RAM eating small app"*. **NO!** Even though it is an electron app, there's no browser running, so the RAM usage is really small:

![ram](https://github.com/pablopunk/art/raw/master/serve-bar/ram.png)

It is also really **fast**. You can easily drag like 50 items into the topbar and they will be instantly shared (and without consuming a lot of RAM). Obviously you will have 50 tabs open in your browser so be careful trying this!

## Build

If you just wanna change the code and run the app:
Expand Down
36 changes: 28 additions & 8 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path')
const {app, clipboard, shell, Menu, Tray} = require('electron')
const { app, clipboard, shell, Menu, Tray } = require('electron')
const notifier = require('node-notifier')
const {createServer} = require('./server')
const { createServer } = require('./server')
const settings = require('./settings')

const iconPath = path.join(__dirname, '..', 'assets/iconTemplate.png')

Expand All @@ -14,8 +15,8 @@ const getMenuItemForServer = (server, pathname, port) => ({
pathname,
label: getLabelForServer(pathname, port),
type: 'normal',
click() {
server.close();
click () {
server.close()
removeServerFromMenu(pathname)
}
})
Expand All @@ -25,6 +26,22 @@ const getMenu = serversSubMenu => Menu.buildFromTemplate([
label: 'Servers',
submenu: serversSubMenu
},
{
label: 'Open in browser',
type: 'checkbox',
checked: settings.get('openInBrowser'),
click () {
settings.set('openInBrowser', !settings.get('openInBrowser'))
}
},
{
label: 'Copy to clipboard',
type: 'checkbox',
checked: settings.get('copyToClipboard'),
click () {
settings.set('copyToClipboard', !settings.get('copyToClipboard'))
}
},
{
label: 'View on Github',
type: 'normal',
Expand Down Expand Up @@ -57,7 +74,7 @@ const reloadMenu = () => tray.setContextMenu(getMenu(serversSubMenu))

const notifyServerSuccess = pathname => {
notifier.notify({
title: 'On browser and clipboard!',
title: 'Shared successfully!',
message: `Now you are sharing "${path.basename(pathname)}"`,
wait: false,
icon: path.join(__dirname, '..', 'assets', 'icon.png')
Expand All @@ -73,7 +90,6 @@ const notifyServerAlreadyExists = pathname => {
})
}


const newServerEvent = pathname => {
if (serverExistsInMenu(pathname)) {
notifyServerAlreadyExists(pathname)
Expand All @@ -82,8 +98,12 @@ const newServerEvent = pathname => {

createServer(pathname, (server, ip, port) => {
const sharedUrl = `http://${ip}:${port}/`
clipboard.writeText(sharedUrl)
shell.openExternal(sharedUrl)
if (settings.get('copyToClipboard')) {
clipboard.writeText(sharedUrl)
}
if (settings.get('openInBrowser')) {
shell.openExternal(sharedUrl)
}
addServerToMenu(server, pathname, port)
notifyServerSuccess(pathname)
reloadMenu()
Expand Down
14 changes: 14 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const settings = {
openInBrowser: true,
copyToClipboard: true
}

module.exports.set = function (setting, value) {
if (settings.hasOwnProperty(setting)) {
settings[setting] = value
}
}

module.exports.get = function (setting) {
return settings[setting]
}

0 comments on commit f34cd68

Please sign in to comment.