Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jalenng committed Jun 9, 2021
2 parents 740fc92 + df20027 commit b171891
Show file tree
Hide file tree
Showing 97 changed files with 685 additions and 947 deletions.
309 changes: 30 additions & 279 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twenty",
"productName": "Twenty",
"description": "Customizable timer that reminds you to take eye breaks",
"version": "0.1.7",
"version": "0.1.8",
"repository": "https://github.com/jalenng/twenty",
"url": "https://github.com/jalenng/twenty#readme",
"author": {
Expand Down Expand Up @@ -42,10 +42,7 @@
"dependencies": {
"@fluentui/react": "^8.8.0",
"electron-is-dev": "^2.0.0",
"electron-log": "^4.3.5",
"electron-store": "^7.0.2",
"electron-unhandled": "^3.0.2",
"electron-updater": "^4.3.9",
"electron-window-state": "^5.0.3",
"hazardous": "^0.3.0",
"node-powershell": "^4.0.0",
Expand Down Expand Up @@ -83,8 +80,7 @@
"build": "npm run react-build && npm run electron-build",
"dev": "concurrently \"npm:react-start\" \"npm:electron-watch\"",
"test": "concurrently -s first -k \"npm:react-start\" \"npm:electron-test\"",
"lint": "standard --fix",
"win-cert": "electron-builder create-self-signed-cert -p jalenng"
"lint": "standard --fix"
},
"browserslist": {
"production": [
Expand Down
20 changes: 0 additions & 20 deletions public/app/InstanceEnforcer.js

This file was deleted.

37 changes: 16 additions & 21 deletions public/app/createWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* @author jalenng
*/

const { BrowserWindow, screen, app, Menu } = require('electron')
const { BrowserWindow, screen } = require('electron')
const path = require('path')

const { isDev, isWindows, appName } = require('../constants')
const store = require('../store/store')
const { mainWindow } = require('./windowManager')

const windowStateKeeper = require('electron-window-state')

Expand Down Expand Up @@ -70,7 +72,7 @@ const POPUP_OPTIONS = {
* Effective only if display is provided. Optional.
* @returns a BrowserWindow object of the newly created window
*/
module.exports = function createWindow (type, destination = '', display = null, isPopup = false) {
function createWindow (type, destination = '', display = null, isPopup = false) {
// Initialize window
const window = new BrowserWindow({
...SHARED_OPTIONS,
Expand All @@ -88,35 +90,33 @@ module.exports = function createWindow (type, destination = '', display = null,

switch (type) {
case 'main':
// Window state keeper for main window
mainWindowState = windowStateKeeper({})

// Update and remember the position of the main window
mainWindowState = windowStateKeeper({})

if (mainWindowState.x && mainWindowState.y) {
window.setPosition(mainWindowState.x, mainWindowState.y)
}
mainWindowState.manage(window)

// Make the main window always on top if its corresponding preference is enabled
window.setAlwaysOnTop(global.store.get('preferences.appearance.alwaysOnTop'))
window.setAlwaysOnTop(store.get('preferences.appearance.alwaysOnTop'))

// Update the alwaysOnTop preference when the main window's alwaysOnTop property changes
window.on('always-on-top-changed', (event, isAlwaysOnTop) => {
global.store.set('preferences.appearance.alwaysOnTop', isAlwaysOnTop)
store.set('preferences.appearance.alwaysOnTop', isAlwaysOnTop)
})

// Handle the close button action
// Handle the close button action by having window hide
window.on('close', (e) => {
if (isDev) {
app.exit() // Just exit the app if isDev
} else {
e.preventDefault() // Otherwise, just hide to tray
global.mainWindow.hide()
}
e.preventDefault()
mainWindow.get().hide()
})

// If not configured to hide the app on app startup, show window when ready
if (!global.store.get('preferences.startup.hideOnAppStartup')) { window.on('ready-to-show', () => window.show()) }
if (!store.get('preferences.startup.hideOnAppStartup')) {
window.on('ready-to-show', () => window.show())
}

break

Expand Down Expand Up @@ -170,13 +170,6 @@ module.exports = function createWindow (type, destination = '', display = null,
window.setBounds({ ...position, ...size })
}

window.on('system-context-menu', (event, point) => {
event.preventDefault()
Menu.buildFromTemplate([
{ role: 'close' }
]).popup()
})

// On macOS, make it visible across all workspaces
window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })

Expand All @@ -185,3 +178,5 @@ module.exports = function createWindow (type, destination = '', display = null,

return window
}

module.exports = createWindow
65 changes: 0 additions & 65 deletions public/app/initializeApp.js

This file was deleted.

48 changes: 0 additions & 48 deletions public/app/initializeTray.js

This file was deleted.

48 changes: 26 additions & 22 deletions public/app/initializeMenu.js → public/app/menu.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/** Menu */
/*
- File
* Preferences (Ctrl+,)
* Close (Alt+F4)
- Timer
* Start/Stop (Ctrl+S)
- Dev
* Reload (Ctrl+R)
* Force Reload (Ctrl+Shift+R)
* Toggle Developer Tools (Ctrl+Shift+I)
* Start break (Ctrl+E)
- Help (F1)
* About
*/
/**
* @file Holds the template for the app menu.
* @author jalenng
*
* - File
* * Preferences (Ctrl+,)
* * Close (Alt+F4)
* - Timer
* * Start/Stop (Ctrl+S)
* - Dev
* * Reload (Ctrl+R)
* * Force Reload (Ctrl+Shift+R)
* * Toggle Developer Tools (Ctrl+Shift+I)
* * Start break (Ctrl+E)
* - Help (F1)
* * About
*/

const { Menu } = require('electron')

const { timerSystem } = require('../systems/systems')
const createWindow = require('./createWindow')
const { prefsWindow } = require('./windowManager')

const { isDev } = require('../constants')

Expand All @@ -28,11 +32,11 @@ const menu = Menu.buildFromTemplate([
label: 'Preferences',
accelerator: 'CmdOrCtrl+,',
click: () => {
if (!global.prefsWindow || global.prefsWindow.isDestroyed()) {
global.prefsWindow = createWindow('preferences', 'preferences')
if (!prefsWindow.get() || prefsWindow.get().isDestroyed()) {
prefsWindow.set(createWindow('preferences', 'preferences'))
} else {
global.prefsWindow.restore()
global.prefsWindow.focus()
prefsWindow.get().restore()
prefsWindow.get().focus()
}
}
},
Expand All @@ -46,7 +50,7 @@ const menu = Menu.buildFromTemplate([
{
label: 'Start/Stop',
accelerator: 'CmdOrCtrl+s',
click: () => { global.systems.timer.togglePause() }
click: () => { timerSystem.togglePause() }
}
]
},
Expand All @@ -61,7 +65,7 @@ const menu = Menu.buildFromTemplate([
{
label: 'Test break',
accelerator: 'CmdOrCtrl+e',
click: () => { global.systems.timer.end() }
click: () => { timerSystem.end() }
}
]
}]
Expand All @@ -80,4 +84,4 @@ const menu = Menu.buildFromTemplate([
}
])

Menu.setApplicationMenu(menu)
module.exports = { menu }
56 changes: 56 additions & 0 deletions public/app/setupApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file Initializes the Electron app.
* @author jalenng
*/

const { BrowserWindow, Menu, app } = require('electron')

const { appPath, isMacOS, isDev } = require('../constants')
const { mainWindow } = require('./windowManager')
const createWindow = require('./createWindow')
const store = require('../store/store')

const { createTray } = require('./tray')
const { menu } = require('./menu')
require('./theming')

/** isDev: Do not configure login item settings */
if (!isDev) {
const startAppOnLogin = store.get('preferences.startup.startAppOnLogin')
app.setLoginItemSettings({
openAtLogin: startAppOnLogin,
enabled: startAppOnLogin,
path: appPath
})
}

/** Configure app event handlers */
app.whenReady().then(() => {
mainWindow.set(createWindow('main')) // Create main window

// macOS: Recreate a window if none are open but the dock icon is activated
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
mainWindow.set(createWindow('main'))
}
})

createTray() // Create tray button

Menu.setApplicationMenu(menu) // Create menu
})

// macOS: Dock should still show that the app is open even if all windows are closed.
// That means if not on macOS, exit the app if all windows are closed.
app.on('window-all-closed', function () {
if (!isMacOS) {
app.exit()
}
})

// Prevent loading of new websites
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
event.preventDefault()
})
})
Loading

0 comments on commit b171891

Please sign in to comment.