Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 4, 2016
0 parents commit 23f6e98
Show file tree
Hide file tree
Showing 25 changed files with 2,277 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.ai binary
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
/dist
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 'node'
23 changes: 23 additions & 0 deletions browser.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* navbar */
/* TODO: use wider values on non-OSX as they don't have the inline traffic lights */
#react-root header .WBlUyLoP {
max-width: 60% !important;
width: 60% !important;
}

/* main */
#react-root main .WBlUyLoP {
max-width: 90% !important;
width: 90% !important;
}

/* push the compose modal down */
/* TODO: only needed on OS X */
#react-root .SaRmWN__._3tixQkQf {
top: 40px !important;
}

/* push the login navbar down */
.ResponsiveLayout {
padding-top: 40px !important;
}
59 changes: 59 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';
const electron = require('electron');
const ipc = electron.ipcRenderer;
const storage = electron.remote.require('./storage');

ipc.on('compose-tweet', () => {
document.querySelector('a[href$="/compose/tweet"]').click();
});

ipc.on('log-out', () => {
window.location.href = '/logout';
});

ipc.on('zoom-reset', () => {
setZoom(1.0);
});

ipc.on('zoom-in', () => {
const zoomFactor = storage.get('zoomFactor') + 0.1;

if (zoomFactor < 1.6) {
setZoom(zoomFactor);
}
});

ipc.on('zoom-out', () => {
const zoomFactor = storage.get('zoomFactor') - 0.1;

if (zoomFactor >= 0.8) {
setZoom(zoomFactor);
}
});

function setZoom(zoomFactor) {
const node = document.getElementById('zoomFactor');
node.textContent = `body {zoom: ${zoomFactor} !important}`;
storage.set('zoomFactor', zoomFactor);
}

// Inject a global style node to maintain zoom factor after conversation change.
// Also set the zoom factor if it was set before quitting.
function zoomInit() {
const zoomFactor = storage.get('zoomFactor') || 1.0;
const style = document.createElement('style');
style.id = 'zoomFactor';

document.body.appendChild(style);
setZoom(zoomFactor);
}

document.addEventListener('DOMContentLoaded', () => {
zoomInit();

// hide navbar profile link
// TODO: figure out a better way to detect when React is done
setTimeout(() => {
document.querySelector('header a[href$="/account"]').parentNode.style.display = 'none';
}, 200);
});
101 changes: 101 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';
const path = require('path');
const fs = require('fs');
const electron = require('electron');
const app = electron.app;
const appMenu = require('./menu');
const storage = require('./storage');
const tray = require('./tray');

require('electron-debug')();
require('electron-dl')();

let mainWindow;
let isQuitting = false;

const isAlreadyRunning = app.makeSingleInstance(() => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}

mainWindow.show();
}
});

if (isAlreadyRunning) {
app.quit();
}

function createMainWindow() {
const lastWindowState = storage.get('lastWindowState') || {width: 500, height: 600};

const win = new electron.BrowserWindow({
title: app.getName(),
show: false,
x: lastWindowState.x,
y: lastWindowState.y,
width: lastWindowState.width,
height: lastWindowState.height,
icon: process.platform === 'linux' && path.join(__dirname, 'media', 'Icon.png'),
minWidth: 340,
minHeight: 260,
titleBarStyle: 'hidden-inset',
webPreferences: {
preload: path.join(__dirname, 'browser.js'),
nodeIntegration: false,
webSecurity: false,
plugins: true
}
});

if (process.platform === 'darwin') {
win.setSheetOffset(40);
}

win.loadURL('https://mobile.twitter.com/home');

win.on('close', e => {
if (!isQuitting) {
e.preventDefault();

if (process.platform === 'darwin') {
app.hide();
} else {
win.hide();
}
}
});

return win;
}

app.on('ready', () => {
electron.Menu.setApplicationMenu(appMenu);
mainWindow = createMainWindow();
tray.create(mainWindow);

const page = mainWindow.webContents;

page.on('dom-ready', () => {
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));
mainWindow.show();
});

page.on('new-window', (e, url) => {
e.preventDefault();
electron.shell.openExternal(url);
});
});

app.on('activate', () => {
mainWindow.show();
});

app.on('before-quit', () => {
isQuitting = true;

if (!mainWindow.isFullScreen()) {
storage.set('lastWindowState', mainWindow.getBounds());
}
});
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) Sindre Sorhus <[email protected]> (sindresorhus.com)

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.
Loading

0 comments on commit 23f6e98

Please sign in to comment.