Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
artrz committed Sep 4, 2017
0 parents commit 5b93e31
Show file tree
Hide file tree
Showing 47 changed files with 2,826 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb-base",
"settings": {
"import/core-modules": [
"electron"
]
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
build/
dist/
*.tar.xz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Arturo Rodríguez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<h1 align="center">
<img src="https://raw.githubusercontent.com/arturock/basecamp-linux/master/resources/basecamp-full-stacked.png" width="466" height="390">
</h1>

# Basecamp Desktop for Linux

Unofficial [Basecamp](https://basecamp.com/) GNU/Linux desktop client built with [Electron](http://electron.atom.io/).

## Features

- Native notifications
- Context menu on links
- Basic UI settings
- Tray icon
- Unread count badge
- Left click to show / hide app
- Right click for tray menu

The application menu is hidden by default, to show it press the `alt` key.

## Privacy

No information is collected or tracked by the application, Electron however will save some data as with any webview. It is possible to purge that information with an in-app function: _menu -> file -> 'Clear data'_ will erase all stored information and cache (any open session will be lost).

## Prerequisites

As any GNU/Linux Electron application `libappindicator1` is required for [tray icon](https://github.com/electron/electron/blob/master/docs/api/tray.md) and `libnotify` for [notifications](https://github.com/electron/electron/blob/master/docs/tutorial/notifications.md) but most likely they are already installed.

## Installation

Download the [latest release](https://github.com/arturock/basecamp-linux/releases).

## Manual build

Required tools:
- Node
- Npm
- Yarn

Clone this repo, cd to the local copy and run
```sh
npm run build:64
# or npm run build:32
```

That will create a `dist/basecamp-linux-*` directory with the application.

## License

Check the [LICENSE](./LICENSE) file.

## Changelog

- 0.1.0
- First release

## Disclosure

This application is not affiliated, authorized, endorsed by or in any way officially connected with Basecamp.
283 changes: 283 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
const { app, BrowserWindow, dialog, Menu, shell, Tray } = require('electron');
const path = require('path');
const settings = require('electron-settings');
const menus = require('./menus');

const ELECTRON_VERSION = process.versions.electron;
const APP_NAME = app.getName();
const APP_VERSION = app.getVersion();
const APP_DESCRIPTION = 'Unofficial Basecamp GNU/Linux Desktop Client.';
const BASECAMP_URL = 'https://launchpad.37signals.com';
const USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36';
const ICONS_PATH = path.join(app.getAppPath(), '..', 'assets', 'icons');
const DEFAULTS = {
iconScheme: 'white',
showBadge: true,
};

let win;
let tray;
let unreadsNotified = false;

/**
* The app builder object.
*/
const basecamp = {
buildApp(url) {
basecamp.createWindow(url);
basecamp.addAppMenu();
basecamp.addContextMenu();
basecamp.addTrayIcon();
basecamp.setIcons();
},

/**
* Creates the app window.
*/
createWindow(url) {
win = new BrowserWindow({
y: settings.get('posY', 0),
x: settings.get('posX', 0),
width: settings.get('width', 770),
height: settings.get('height', 700),
title: APP_NAME,
icon: basecamp.getIcon('icon'),
autoHideMenuBar: true,
backgroundColor: '#f5efe6',
webPreferences: {
nodeIntegration: false,
preload: `${__dirname}/integration.js`,
},
});

if (settings.get('isMaximized', false)) {
win.maximize();
}

win.loadURL(url, { USER_AGENT });

win
.on('close', () => {
const bounds = win.getBounds();
settings.set('posX', bounds.x);
settings.set('posY', bounds.y);
settings.set('width', bounds.width);
settings.set('height', bounds.height);
settings.set('isMaximized', win.isMaximized());
})
.on('closed', () => {
tray = null;
win = null;
})
.on('page-title-updated', (event, title) => {
event.preventDefault();
basecamp.setTitles(title);
});

win.webContents
.on('new-window', (event, linkUrl) => {
const regex = /accounts.google.com/;

if (!linkUrl.match(regex)) {
event.preventDefault();
shell.openExternal(linkUrl);
}
})
.on('will-navigate', (event, linkUrl) => {
const regex = /(37signals.com|basecamp.com)/;

if (!linkUrl.match(regex)) {
event.preventDefault();
shell.openExternal(linkUrl);
}
});

return win;
},

/**
* Adds the app menu.
*/
addAppMenu() {
Menu.setApplicationMenu(menus.forApp(basecamp, settings, DEFAULTS));
},

/**
* Adds the app context menu.
*/
addContextMenu() {
win.webContents.on('context-menu', (event, params) => {
event.preventDefault();
const linkURL = params.linkURL;

if (linkURL) {
menus.forContext(linkURL).popup(win);
}
});
},

/**
* Adds the tray icon.
*/
addTrayIcon() {
tray = new Tray(basecamp.getIcon('tray'));
tray.setToolTip(APP_NAME);
tray.setContextMenu(menus.forTray());
tray.on('click', () => {
if (win.isVisible()) {
win.hide();
} else {
win.show();
}
});
},

/**
* Generates and displays a clear data dialog.
*/
showClearDataDialog() {
dialog.showMessageBox(win, {
type: 'warning',
buttons: ['Yes', 'Cancel'],
defaultId: 1,
title: 'Clear data',
message: 'This will clear all data.\n\nDo you want to proceed?',
}, (response) => {
if (response === 0) {
basecamp.clearData();
}
});
},

/**
* Generates and displays an about dialog.
*/
showAboutDialog() {
dialog.showMessageBox(win, {
type: 'info',
icon: basecamp.getIcon('logo'),
buttons: ['Ok'],
defaultId: 0,
title: 'About',
message: `${APP_NAME} ${APP_VERSION}\n\n${APP_DESCRIPTION}\n\nElectron ${ELECTRON_VERSION}`,
});
},

/**
* Sets the app & tray titles.
*
* @param {string} title The webpage title
*/
setTitles(title) {
let fixedTitle = title;

let match = /^\((\d+)\)(.+)/.exec(title);
if (match) {
fixedTitle = match[2].trim();
} else {
match = /^(•)(.+)/.exec(title);
if (match) {
fixedTitle = match[2].trim();
}
}

win.webContents.executeJavaScript('typeof BC === \'undefined\' ? 0 : BC.unreads.all', false, result => (result)).then((result) => {
const unreads = result.length;

win.setTitle(unreads > 0 ? `${fixedTitle}${unreads}` : fixedTitle);

tray.setToolTip(unreads > 0 ? `${APP_NAME}${unreads}` : APP_NAME);

if (unreads > 0) {
if (!unreadsNotified) {
const notification = `
new Notification(
'${APP_NAME}',
{ body: 'You have ${unreads} unread notifications' }
);`;

win.webContents.executeJavaScript(notification);

unreadsNotified = true;
}

if (settings.get('showBadge', DEFAULTS.showBadge)) {
basecamp.setIcons(`-unreads-${(unreads > 10 ? '10p' : unreads)}`);
} else {
basecamp.setIcons('-unreads');
}
} else {
basecamp.setIcons();
}
});
},

/**
* Sets the app & tray icons.
*/
setIcons(suffix) {
win.setIcon(basecamp.getIcon(`icon${suffix ? '-unreads' : ''}`));
tray.setImage(basecamp.getIcon(`tray${suffix || ''}`));
},

/**
* Gets the corresponding icon path.
*
* @param {string} icon
*
* @return {string}
*/
getIcon(icon) {
const iconScheme = settings.get('iconScheme', DEFAULTS.iconScheme);
return `${ICONS_PATH}/${iconScheme}/${icon}.png`;
},

/**
* Clears all the app data.
*/
clearData() {
const session = win.webContents.session;
session.clearStorageData(() => {
session.clearCache(() => {
win.loadURL(BASECAMP_URL);
});
});
},

/**
* Configures the icon scheme.
*
* @param {string} color
*/
configureIconScheme(color) {
settings.set('iconScheme', color);
win.reload();
},

/**
* Configures the icon badge showing.
*
* @param {string} color
*/
configureShowBadge(config) {
settings.set('showBadge', config);
win.reload();
},
};

// --- Build the app

app.disableHardwareAcceleration();

app
.on('window-all-closed', () => {
app.quit();
})
.on('ready', () => {
basecamp.buildApp(BASECAMP_URL);
})
.on('activate', () => {
if (win === null) {
basecamp.buildApp(BASECAMP_URL);
}
});
Loading

0 comments on commit 5b93e31

Please sign in to comment.