Skip to content

Commit

Permalink
Use Prettier
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
sindresorhus committed Jan 20, 2019
1 parent 00746cf commit 98dabe1
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 70 deletions.
76 changes: 45 additions & 31 deletions browser.js
Expand Up @@ -46,7 +46,7 @@ ipc.on('show-preferences', async () => {
});

ipc.on('new-conversation', () => {
document.querySelector('._30yy[data-href$=\'/new\']').click();
document.querySelector("._30yy[data-href$='/new']").click();
});

ipc.on('log-out', () => {
Expand Down Expand Up @@ -124,7 +124,10 @@ ipc.on('toggle-mute-notifications', async (event, defaultStatus) => {

if (defaultStatus === undefined) {
notificationCheckbox.click();
} else if ((defaultStatus && notificationCheckbox.checked) || (!defaultStatus && !notificationCheckbox.checked)) {
} else if (
(defaultStatus && notificationCheckbox.checked) ||
(!defaultStatus && !notificationCheckbox.checked)
) {
notificationCheckbox.click();
}

Expand Down Expand Up @@ -213,7 +216,11 @@ ipc.on('update-vibrancy', () => {
});

ipc.on('render-overlay-icon', (event, messageCount) => {
ipc.send('update-overlay-icon', renderOverlayIcon(messageCount).toDataURL(), String(messageCount));
ipc.send(
'update-overlay-icon',
renderOverlayIcon(messageCount).toDataURL(),
String(messageCount)
);
});

ipc.on('zoom-reset', () => {
Expand Down Expand Up @@ -347,30 +354,31 @@ function closePreferences() {
}
async function sendConversationList() {
const conversations = await Promise.all(
[...document.querySelector(listSelector).children]
.splice(0, 10)
.map(async el => {
const profilePic = el.querySelector('._55lt img');
const groupPic = el.querySelector('._4ld- div');

// This is only for group chats
if (groupPic) {
// Slice image source from background-image style property of div
groupPic.src = groupPic.style.backgroundImage.slice(5, groupPic.style.backgroundImage.length - 2);
}

const isConversationMuted = el.classList.contains('_569x');

return {
label: el.querySelector('._1ht6').textContent,
selected: el.classList.contains('_1ht2'),
unread: el.classList.contains('_1ht3') && !isConversationMuted,
icon: await getDataUrlFromImg(
profilePic ? profilePic : groupPic,
el.classList.contains('_1ht3')
)
};
})
[...document.querySelector(listSelector).children].splice(0, 10).map(async el => {
const profilePic = el.querySelector('._55lt img');
const groupPic = el.querySelector('._4ld- div');

// This is only for group chats
if (groupPic) {
// Slice image source from background-image style property of div
groupPic.src = groupPic.style.backgroundImage.slice(
5,
groupPic.style.backgroundImage.length - 2
);
}

const isConversationMuted = el.classList.contains('_569x');

return {
label: el.querySelector('._1ht6').textContent,
selected: el.classList.contains('_1ht2'),
unread: el.classList.contains('_1ht3') && !isConversationMuted,
icon: await getDataUrlFromImg(
profilePic ? profilePic : groupPic,
el.classList.contains('_1ht3')
)
};
})
);

ipc.send('conversations', conversations);
Expand All @@ -397,7 +405,7 @@ function urlToCanvas(url, size) {

ctx.save();
ctx.beginPath();
ctx.arc((size / 2) + padding.left, (size / 2) + padding.top, size / 2, 0, Math.PI * 2, true);
ctx.arc(size / 2 + padding.left, size / 2 + padding.top, size / 2, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();

Expand Down Expand Up @@ -495,7 +503,7 @@ window.addEventListener('load', () => {
// so this needs to be done the old-school way
document.addEventListener('keydown', event => {
// The `!event.altKey` part is a workaround for https://github.com/electron/electron/issues/13895
const combineKey = is.macos ? event.metaKey : (event.ctrlKey && !event.altKey);
const combineKey = is.macos ? event.metaKey : event.ctrlKey && !event.altKey;

if (!combineKey) {
return;
Expand Down Expand Up @@ -525,7 +533,7 @@ window.addEventListener('message', ({data: {type, data}}) => {

function showNotification({id, title, body, icon, silent}) {
body = body.props ? body.props.content[0] : body;
title = (typeof title === 'object' && title.props) ? title.props.content[0] : title;
title = typeof title === 'object' && title.props ? title.props.content[0] : title;

const img = new Image();
img.crossOrigin = 'anonymous';
Expand All @@ -540,7 +548,13 @@ function showNotification({id, title, body, icon, silent}) {

ctx.drawImage(img, 0, 0, img.width, img.height);

ipc.send('notification', {id, title, body, icon: canvas.toDataURL(), silent});
ipc.send('notification', {
id,
title,
body,
icon: canvas.toDataURL(),
silent
});
});
}

Expand Down
3 changes: 2 additions & 1 deletion emoji.js
Expand Up @@ -251,7 +251,8 @@ module.exports = {

const emojiSetPrefix = 'emoji.php/v9/';
const emojiSetIndex = url.indexOf(emojiSetPrefix) + emojiSetPrefix.length;
const newURL = url.slice(0, emojiSetIndex) + emojiSetCode + url.slice(emojiSetIndex + 1) + '#replaced';
const newURL =
url.slice(0, emojiSetIndex) + emojiSetCode + url.slice(emojiSetIndex + 1) + '#replaced';

return {redirectURL: newURL};
},
Expand Down
21 changes: 12 additions & 9 deletions index.js
Expand Up @@ -186,7 +186,9 @@ function createMainWindow() {
const isDarkMode = config.get('darkMode');

// Messenger or Work Chat
const mainURL = config.get('useWorkChat') ? 'https://work.facebook.com/chat' : 'https://www.messenger.com/login/';
const mainURL = config.get('useWorkChat')
? 'https://work.facebook.com/chat'
: 'https://www.messenger.com/login/';

const win = new electron.BrowserWindow({
title: app.getName(),
Expand Down Expand Up @@ -304,7 +306,9 @@ function createMainWindow() {
}

if (fs.existsSync(path.join(app.getPath('userData'), 'custom.css'))) {
webContents.insertCSS(fs.readFileSync(path.join(app.getPath('userData'), 'custom.css'), 'utf8'));
webContents.insertCSS(
fs.readFileSync(path.join(app.getPath('userData'), 'custom.css'), 'utf8')
);
}

if (config.get('launchMinimized') || app.getLoginItemSettings().wasOpenedAsHidden) {
Expand All @@ -316,14 +320,17 @@ function createMainWindow() {
webContents.send('toggle-mute-notifications', config.get('notificationsMuted'));
webContents.send('toggle-message-buttons', config.get('showMessageButtons'));

webContents.executeJavaScript(fs.readFileSync(path.join(__dirname, 'notifications-isolated.js'), 'utf8'));
webContents.executeJavaScript(
fs.readFileSync(path.join(__dirname, 'notifications-isolated.js'), 'utf8')
);
});

webContents.on('new-window', (event, url, frameName, disposition, options) => {
event.preventDefault();

if (url === 'about:blank') {
if (frameName !== 'about:blank') { // Voice/video call popup
if (frameName !== 'about:blank') {
// Voice/video call popup
options.show = true;
options.titleBarStyle = 'default';
options.webPreferences.nodeIntegration = false;
Expand Down Expand Up @@ -372,11 +379,7 @@ function createMainWindow() {
return false;
};

if (
isMessengerDotCom(url) ||
isTwoFactorAuth(url) ||
isWorkChat(url)
) {
if (isMessengerDotCom(url) || isTwoFactorAuth(url) || isWorkChat(url)) {
return;
}

Expand Down
4 changes: 1 addition & 3 deletions menu.js
Expand Up @@ -526,9 +526,7 @@ ${debugInfo()}`;
]),
{
label: 'File',
submenu: [
newConversationItem
]
submenu: [newConversationItem]
},
{
role: 'editMenu'
Expand Down
23 changes: 13 additions & 10 deletions notifications-isolated.js
@@ -1,4 +1,4 @@
(function (window) {
(window => {
const notifications = new Map();

// Handle events sent from the browser process
Expand All @@ -19,15 +19,18 @@

let counter = 1;

window.Notification = Object.assign(class {
constructor(title, options) {
this.id = counter++;
notifications.set(this.id, this);
window.Notification = Object.assign(
class {
constructor(title, options) {
this.id = counter++;
notifications.set(this.id, this);

window.postMessage({type: 'notification', data: {title, id: this.id, ...options}}, '*');
}
window.postMessage({type: 'notification', data: {title, id: this.id, ...options}}, '*');
}

// No-op, but Messenger expects this method to be present
close() {}
}, window.Notification);
// No-op, but Messenger expects this method to be present
close() {}
},
window.Notification
);
})(window);
13 changes: 11 additions & 2 deletions package.json
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"postinstall": "electron-builder install-app-deps",
"lint": "xo && stylelint '*.css'",
"lint": "xo --fix && stylelint --fix '*.css'",
"test": "npm run lint",
"start": "electron .",
"pack": "electron-builder --dir",
Expand Down Expand Up @@ -48,7 +48,8 @@
"envs": [
"node",
"browser"
]
],
"prettier": true
},
"stylelint": {
"extends": "stylelint-config-xo",
Expand All @@ -60,6 +61,14 @@
"rule-empty-line-before": null
}
},
"prettier": {
"printWidth": 100,
"useTabs": true,
"singleQuote": true,
"bracketSpacing": false,
"proseWrap": "never",
"endOfLine": "lf"
},
"build": {
"files": [
"**/*",
Expand Down
28 changes: 14 additions & 14 deletions util.js
Expand Up @@ -17,21 +17,21 @@ function sendAction(action, ...args) {
}

function showRestartDialog(message) {
return dialog.showMessageBox({
message,
detail: 'Do you want to restart the app now?',
buttons: [
'Restart',
'Ignore'
],
defaultId: 0,
cancelId: 1
}, response => {
if (response === 0) {
app.relaunch();
app.quit();
return dialog.showMessageBox(
{
message,
detail: 'Do you want to restart the app now?',
buttons: ['Restart', 'Ignore'],
defaultId: 0,
cancelId: 1
},
response => {
if (response === 0) {
app.relaunch();
app.quit();
}
}
});
);
}

exports.getWindow = getWindow;
Expand Down

0 comments on commit 98dabe1

Please sign in to comment.