-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add system tray support #886
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
const electron = require('electron'); | ||
const app = electron.app; | ||
const Menu = electron.Menu; | ||
const Tray = electron.Tray; | ||
const menuTemplate = require('./menutemplate'); | ||
const BrowserWindow = electron.BrowserWindow; | ||
const path = require('path'); | ||
const url = require('url'); | ||
const instagram = require('./instagram'); | ||
const autoUpdater = require('./autoupdater'); | ||
const utils = require('./utils'); | ||
|
||
// fixes electron's timeout inconsistency | ||
// not doing this on windows because the fix doesn't work for windows. | ||
if (process.platform != 'win32') { | ||
// fixes electron's timeout inconsistency | ||
// not doing this on windows because the fix doesn't work for windows. | ||
require('./timeout-shim').fix(); | ||
} | ||
|
||
|
||
const RATE_LIMIT_DELAY = 60000; | ||
let pollingInterval = 10000; | ||
|
||
|
@@ -45,7 +48,19 @@ function createWindow () { | |
})) | ||
}) | ||
|
||
mainWindow.on('closed', () => mainWindow = null) | ||
mainWindow.on('close', function (event) { | ||
if (!app.isQuiting) { | ||
event.preventDefault(); | ||
mainWindow.hide(); | ||
} else { | ||
mainWidnow = null; | ||
} | ||
}) | ||
|
||
mainWindow.on('minimize', function (event) { | ||
event.preventDefault(); | ||
mainWindow.hide(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this functionality should probably only apply to a windows machine. Also, what is the difference between "minimize" and "hide"? 🤔 |
||
}) | ||
} | ||
|
||
function createCheckpointWindow() { | ||
|
@@ -71,14 +86,43 @@ function getChatList () { | |
} | ||
instagram.getChatList(session).then((chats) => { | ||
mainWindow.webContents.send('chatList', chats) | ||
|
||
if (chatListTimeoutObj) { | ||
clearTimeout(chatListTimeoutObj) | ||
} | ||
chatListTimeoutObj = setTimeout(getChatList, pollingInterval); | ||
}).catch(() => setTimeout(getChatList, RATE_LIMIT_DELAY)) | ||
} | ||
|
||
function createTray() { | ||
let tray = new Tray(utils.getTrayImagePath()); | ||
|
||
const contextMenu = Menu.buildFromTemplate([ | ||
{ label: 'Toggle Show', click: function(menuItem, BrowserWindow, event) { | ||
if (mainWindow.isVisible()) { | ||
mainWindow.hide(); | ||
} else { | ||
mainWindow.show(); | ||
} | ||
} }, | ||
{ label: 'Light Icon', type : 'checkbox', checked : utils.isTrayIconLight(), click: function(item) { | ||
if (item.checked) { | ||
utils.setTrayImageLight(); | ||
} else { | ||
utils.setTrayImageDark(); | ||
} | ||
tray.setImage(utils.getTrayImagePath()); | ||
} }, | ||
{ label: 'Quit', click: function() { | ||
app.isQuiting = true; | ||
tray.destroy(); | ||
app.quit(); | ||
} } | ||
]); | ||
|
||
tray.setContextMenu(contextMenu); | ||
} | ||
|
||
let chatTimeoutObj; | ||
let messagesThread; | ||
function getChat (evt, id) { | ||
|
@@ -118,11 +162,12 @@ app.setAppUserModelId('com.ifedapoolarewaju.desktop.igdm') | |
|
||
app.on('ready', () => { | ||
createWindow(); | ||
createTray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this functionality should probably only apply to a windows machine |
||
// only set the menu template when in production mode/ | ||
// this also leaves the dev console enabled when in dev mode. | ||
if (!process.defaultApp) { | ||
const menu = Menu.buildFromTemplate(menuTemplate); | ||
Menu.setApplicationMenu(menu); | ||
Menu.setApplicationMenu(menu); | ||
} | ||
autoUpdater.init(); | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,8 @@ | |
"description": "Desktop application for Instagram DMs", | ||
"main": "main/main.js", | ||
"scripts": { | ||
"start": "gulp build && electron .", | ||
"pack": "gulp build && build --dir", | ||
"dist": "gulp build && build -mwl --x64" | ||
"pack": "electron-builder --dir", | ||
"dist": "electron-builder" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you explain the reason for this change? Why are we now running the command this way? |
||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -29,7 +28,8 @@ | |
"fb": "^2.0.0", | ||
"instagram-private-api": "github:ifedapoolarewaju/instagram-private-api#a66fd1c1a15297877a66ac10f41de70432bd11f4", | ||
"node-notifier": "^5.1.2", | ||
"nojs": "^0.1.1" | ||
"nojs": "^0.1.1", | ||
"electron-json-config": "^1.5.3" | ||
}, | ||
"devDependencies": { | ||
"electron": "2.0.12", | ||
|
@@ -39,7 +39,8 @@ | |
"gulp": "^4.0.0", | ||
"gulp-htmlmin": "^4.0.0", | ||
"gulp-pug": "^3.3.0", | ||
"jstransformer-markdown-it": "^2.0.0" | ||
"jstransformer-markdown-it": "^2.0.0", | ||
"electron-json-config": "^1.5.3" | ||
}, | ||
"build": { | ||
"publish": [ | ||
|
@@ -51,28 +52,9 @@ | |
], | ||
"appId": "com.ifedapoolarewaju.desktop.igdm", | ||
"copyright": "ifedapo Olarewaju 2018", | ||
"mac": { | ||
"target": [ | ||
"dmg", | ||
"zip" | ||
], | ||
"publish": "github", | ||
"category": "public.app-category.social-networking" | ||
}, | ||
"win": { | ||
"target": [ | ||
"nsis", | ||
"portable" | ||
], | ||
"publish": "github", | ||
"publisherName": "ifedapoolarewaju" | ||
}, | ||
"linux": { | ||
"target": [ | ||
"snap", | ||
"AppImage", | ||
"zip", | ||
"deb" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the reason for removing the build config? |
||
"AppImage" | ||
], | ||
"publish": "github", | ||
"maintainer": "Ifedapo Olarewaju <[email protected]>" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just use this clause instead, or not?