-
-
Save sindresorhus/19d537009a8f776cc357a23149a77d65 to your computer and use it in GitHub Desktop.
Caprine vs Passerine diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/caprine.js b/caprine.js | |
index 6cc808a..719c301 100644 | |
--- a/caprine.js | |
+++ b/caprine.js | |
@@ -10,16 +10,16 @@ const {autoUpdater} = require('electron-updater'); | |
const isDev = require('electron-is-dev'); | |
const appMenu = require('./menu'); | |
const config = require('./config'); | |
-const tray = require('./tray'); | |
+// const tray = require('./tray'); | |
require('electron-debug')({enabled: true}); | |
require('electron-dl')(); | |
require('electron-context-menu')(); | |
-const domain = config.get('useWorkChat') ? 'facebook.com' : 'messenger.com'; | |
+const domain = 'producthunt.com' ; | |
const {app, ipcMain, Menu} = electron; | |
-app.setAppUserModelId('com.sindresorhus.caprine'); | |
+app.setAppUserModelId('com.gauthamzz.legacy'); | |
app.disableHardwareAcceleration(); | |
if (!isDev) { | |
@@ -47,122 +47,13 @@ if (isAlreadyRunning) { | |
app.quit(); | |
} | |
-function updateBadge(title, titlePrefix) { | |
- // ignore `Sindre messaged you` blinking | |
- if (title.indexOf(titlePrefix) === -1) { | |
- return; | |
- } | |
- | |
- let messageCount = (/\((\d+)\)/).exec(title); | |
- messageCount = messageCount ? Number(messageCount[1]) : 0; | |
- | |
- if (process.platform === 'darwin' || process.platform === 'linux') { | |
- if (config.get('showUnreadBadge')) { | |
- app.setBadgeCount(messageCount); | |
- } | |
- if (process.platform === 'darwin' && config.get('bounceDockOnMessage') && prevMessageCount !== messageCount) { | |
- app.dock.bounce('informational'); | |
- prevMessageCount = messageCount; | |
- } | |
- } | |
- | |
- if ((process.platform === 'linux' || process.platform === 'win32') && config.get('showUnreadBadge')) { | |
- tray.setBadge(messageCount); | |
- } | |
- | |
- if (process.platform === 'win32') { | |
- if (config.get('showUnreadBadge')) { | |
- if (messageCount === 0) { | |
- mainWindow.setOverlayIcon(null, ''); | |
- } else { | |
- // Delegate drawing of overlay icon to renderer process | |
- mainWindow.webContents.send('render-overlay-icon', messageCount); | |
- } | |
- } | |
- | |
- if (config.get('flashWindowOnMessage')) { | |
- mainWindow.flashFrame(messageCount !== 0); | |
- } | |
- } | |
-} | |
- | |
-ipcMain.on('update-overlay-icon', (event, data, text) => { | |
- const img = electron.nativeImage.createFromDataURL(data); | |
- mainWindow.setOverlayIcon(img, text); | |
-}); | |
- | |
-function enableHiresResources() { | |
- const scaleFactor = Math.max(...electron.screen.getAllDisplays().map(x => x.scaleFactor)); | |
- if (scaleFactor === 1) { | |
- return; | |
- } | |
- | |
- const filter = {urls: [`*://*.${domain}/`]}; | |
- electron.session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => { | |
- let cookie = details.requestHeaders.Cookie; | |
- | |
- if (cookie && details.method === 'GET') { | |
- if (/(; )?dpr=\d/.test(cookie)) { | |
- cookie = cookie.replace(/dpr=\d/, `dpr=${scaleFactor}`); | |
- } else { | |
- cookie = `${cookie}; dpr=${scaleFactor}`; | |
- } | |
- | |
- details.requestHeaders.Cookie = cookie; | |
- } | |
- | |
- callback({ | |
- cancel: false, | |
- requestHeaders: details.requestHeaders | |
- }); | |
- }); | |
-} | |
- | |
-function setUpPrivacyBlocking() { | |
- const ses = electron.session.defaultSession; | |
- const filter = {urls: [`*://*.${domain}/*typ.php*`, `*://*.${domain}/*change_read_status.php*`]}; | |
- ses.webRequest.onBeforeRequest(filter, (details, callback) => { | |
- let blocking = false; | |
- if (details.url.includes('typ.php')) { | |
- blocking = config.get('block.typingIndicator'); | |
- } else { | |
- blocking = config.get('block.chatSeen'); | |
- } | |
- callback({cancel: blocking}); | |
- }); | |
-} | |
- | |
-function setUserLocale() { | |
- const facebookLocales = require('facebook-locales'); | |
- const userLocale = facebookLocales.bestFacebookLocaleFor(app.getLocale()); | |
- const cookie = { | |
- url: 'https://www.messenger.com/', | |
- name: 'locale', | |
- value: userLocale | |
- }; | |
- electron.session.defaultSession.cookies.set(cookie, () => {}); | |
-} | |
- | |
-function setNotificationsMute(status) { | |
- const label = 'Mute Notifications'; | |
- const muteMenuItem = Menu.getApplicationMenu().items[0].submenu.items | |
- .find(x => x.label === label); | |
- | |
- config.set('notificationsMuted', status); | |
- muteMenuItem.checked = status; | |
- | |
- if (process.platform === 'darwin') { | |
- const item = dockMenu.items.find(x => x.label === label); | |
- item.checked = status; | |
- } | |
-} | |
function createMainWindow() { | |
const lastWindowState = config.get('lastWindowState'); | |
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 titlePrefix = config.get('useWorkChat') ? 'Workplace Chat' : 'Messenger'; | |
+ const mainURL = 'https://www.producthunt.com'; | |
+ const titlePrefix = 'Product Hunt'; | |
const win = new electron.BrowserWindow({ | |
title: app.getName(), | |
@@ -185,8 +76,6 @@ function createMainWindow() { | |
plugins: true | |
} | |
}); | |
- setUserLocale(); | |
- setUpPrivacyBlocking(); | |
if (process.platform === 'darwin') { | |
win.setSheetOffset(40); | |
@@ -211,7 +100,7 @@ function createMainWindow() { | |
win.on('page-title-updated', (e, title) => { | |
e.preventDefault(); | |
- updateBadge(title, titlePrefix); | |
+ | |
}); | |
win.on('focus', () => { | |
@@ -228,7 +117,7 @@ app.on('ready', () => { | |
const trackingUrlPrefix = `https://l.${domain}/l.php`; | |
electron.Menu.setApplicationMenu(appMenu); | |
mainWindow = createMainWindow(); | |
- tray.create(mainWindow); | |
+ // tray.create(mainWindow); | |
if (process.platform === 'darwin') { | |
dockMenu = electron.Menu.buildFromTemplate([ | |
@@ -244,41 +133,14 @@ app.on('ready', () => { | |
app.dock.setMenu(dockMenu); | |
} | |
- enableHiresResources(); | |
const {webContents} = mainWindow; | |
- // Disabled because of #258 | |
- // electronLocalShortcut.register(mainWindow, 'CmdOrCtrl+V', () => { | |
- // const clipboardHasImage = electron.clipboard.availableFormats().some(type => type.includes('image')); | |
- | |
- // if (clipboardHasImage && config.get('confirmImagePaste')) { | |
- // electron.dialog.showMessageBox(mainWindow, { | |
- // type: 'info', | |
- // buttons: ['Send', 'Cancel'], | |
- // message: 'Are you sure you want to send the image in the clipboard?', | |
- // icon: electron.clipboard.readImage(), | |
- // checkboxLabel: 'Don\'t ask me again', | |
- // checkboxChecked: false | |
- // }, (resp, checkboxChecked) => { | |
- // if (resp === 0) { | |
- // // User selected send | |
- // webContents.paste(); | |
- // config.set('confirmImagePaste', !checkboxChecked); | |
- // } | |
- // }); | |
- // } else { | |
- // webContents.paste(); | |
- // } | |
- // }); | |
webContents.on('dom-ready', () => { | |
webContents.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); | |
webContents.insertCSS(fs.readFileSync(path.join(__dirname, 'dark-mode.css'), 'utf8')); | |
- webContents.insertCSS(fs.readFileSync(path.join(__dirname, 'vibrancy.css'), 'utf8')); | |
- if (config.get('useWorkChat')) { | |
- webContents.insertCSS(fs.readFileSync(path.join(__dirname, 'workchat.css'), 'utf8')); | |
- } | |
+ | |
if (config.get('launchMinimized')) { | |
mainWindow.hide(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment