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

Commit

Permalink
Improved reliability of app-ready-window-show
Browse files Browse the repository at this point in the history
Throttle post time button to prevent duplicate time
Fix for search input focus
  • Loading branch information
alexcroox committed Dec 19, 2018
1 parent 768947b commit 085b764
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 130 deletions.
222 changes: 109 additions & 113 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ log.info(app.getName())
log.info(app.getVersion())
console.log(app.getName(), app.getVersion())

// resolve user $PATH env variable
// Resolve user $PATH env variable
require('fix-path')()

if (process.env.NODE_ENV === 'development')
Expand All @@ -42,123 +42,122 @@ const installExtensions = () => {
}
})
}
// For copy and paste to work within the menubar we
// need to enable the OS standard Edit menus :(
const menu = Menu.buildFromTemplate([
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
{role: 'pasteandmatchstyle'},
{role: 'delete'},
{role: 'selectall'}
]
}
])

Menu.setApplicationMenu(menu)

let mb = null
let credentials = null
let jiraUserKey = null
let windowVisible = true

Worklogs.getCredentialsFromKeyChain()
.then(keyChainCredentials => {
credentials = keyChainCredentials
console.log('Credentials ready')
launchMenuBar()
})
.catch(launchMenuBar)
app.on('ready', () => {
installExtensions()

// Get our keychain credentials and launch menu bar on success or failure
Worklogs.getCredentialsFromKeyChain()
.then(keyChainCredentials => {
credentials = keyChainCredentials
console.log('Credentials ready')
launchMenuBar()
})
.catch(launchMenuBar)
})

function launchMenuBar () {
app.on('ready', () => {
console.log('App is ready')

// For copy and paste to work within the menubar we
// need to enable the OS standard Edit menus :(
const menu = Menu.buildFromTemplate([
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
{role: 'pasteandmatchstyle'},
{role: 'delete'},
{role: 'selectall'}
]

// transparency workaround https://github.com/electron/electron/issues/2170
setTimeout(() => {

mb = menubar({
alwaysOnTop: process.env.NODE_ENV === 'development',
icon: path.join(app.getAppPath(), '/static/tray-dark.png'),
width: 500,
minWidth: 500,
maxWidth: 500,
minHeight: 20,
hasShadow: false,
preloadWindow: true,
resizable: false,
useContentSize: false,
transparent: true,
frame: false,
toolbar: false
})

console.log('MB Created')

mb.window.credentials = credentials

// Start event handling for the auto updater
const autoUpdater = new Updater(mb.window.webContents, log)
autoUpdater.handleEvents()

mb.on('ready', () => {
console.log('Menubar ready')
mb.tray.setTitle(' Login')
})

mb.on('show', () => {
windowVisible = true

mb.tray.setImage(path.join(app.getAppPath(), '/static/tray-dark-active.png'))

if (jiraUserKey) {

let renderProcess = mb.window.webContents

// Tell the main process the window is visible
renderProcess.send('windowVisible')

Worklogs.checkLock(true)
.then(() => {
console.log('Telling render process we are fetching worklogs')
renderProcess.send('fetchingWorklogs')

let fullWeek = false

Worklogs.request(jiraUserKey, fullWeek, true)
.then(worklogs => {
console.log('All good', worklogs.length)
renderProcess.send('worklogs', JSON.stringify({
fullWeek,
worklogs
}))
})
.catch(error => {
console.error('Error fetching worklogs', error)
renderProcess.send('worklogs', JSON.stringify([]))
})
})
.catch(error => {
renderProcess.send('worklogs', JSON.stringify([]))
})
}
])

Menu.setApplicationMenu(menu)

installExtensions()

// transparency workaround https://github.com/electron/electron/issues/2170
setTimeout(() => {

mb = menubar({
alwaysOnTop: process.env.NODE_ENV === 'development',
icon: path.join(app.getAppPath(), '/static/tray-dark.png'),
width: 500,
minWidth: 500,
maxWidth: 500,
minHeight: 20,
hasShadow: false,
preloadWindow: true,
resizable: false,
useContentSize: false,
transparent: true,
frame: false,
toolbar: false
})

console.log('MB Created')

mb.window.credentials = credentials

// Start event handling for the auto updater
const autoUpdater = new Updater(mb.window.webContents, log)
autoUpdater.handleEvents()

mb.on('ready', () => {
console.log('Menubar ready')
mb.tray.setTitle(' Login')
})

mb.on('show', () => {
windowVisible = true

mb.tray.setImage(path.join(app.getAppPath(), '/static/tray-dark-active.png'))

if (jiraUserKey) {

let renderProcess = mb.window.webContents

// Tell the main process the window is visible
renderProcess.send('windowVisible')

Worklogs.checkLock(true)
.then(() => {
console.log('Telling render process we are fetching worklogs')
renderProcess.send('fetchingWorklogs')

let fullWeek = false

Worklogs.request(jiraUserKey, fullWeek, true)
.then(worklogs => {
console.log('All good', worklogs.length)
renderProcess.send('worklogs', JSON.stringify({
fullWeek,
worklogs
}))
})
.catch(error => {
console.error('Error fetching worklogs', error)
renderProcess.send('worklogs', JSON.stringify([]))
})
})
.catch(error => {
renderProcess.send('worklogs', JSON.stringify([]))
})
}
})

mb.on('hide', () => {
windowVisible = false
mb.tray.setImage(path.join(app.getAppPath(), '/static/tray-dark.png'))
})
}, 100)
})
})

mb.on('hide', () => {
windowVisible = false
mb.tray.setImage(path.join(app.getAppPath(), '/static/tray-dark.png'))
})
}, 100)
}

// Quit when all windows are closed.
Expand All @@ -178,10 +177,8 @@ ipcMain.on('quit', () => {
ipcMain.on('windowSizeChange', (event, newHeight) => {
const [currentWidth, currentHeight] = mb.window.getSize()

console.log('newHeight', newHeight)

mb.window.setSize(currentWidth, newHeight)
});
})

ipcMain.on('openDevTools', (event) => {
mb.window.webContents.openDevTools({ mode: 'detach' })
Expand All @@ -206,7 +203,6 @@ ipcMain.on('deletePassword', (event) => {
})

ipcMain.on('fetchWorklogs', (event, args) => {

let { userKey, fullWeek } = args

jiraUserKey = userKey
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jira-timer",
"version": "1.0.18",
"version": "1.0.17",
"description": "Jira Timer",
"productName": "Jira Timer",
"main": "index.js",
Expand Down Expand Up @@ -94,6 +94,7 @@
"lodash.orderby": "^4.6.0",
"lodash.remove": "^4.7.0",
"lodash.sortby": "^4.7.0",
"lodash.throttle": "^4.1.1",
"menubar": "github:mantou132/menubar#master",
"node-loader": "^0.6.0",
"object-get": "^2.1.0",
Expand Down
24 changes: 9 additions & 15 deletions src/containers/search/search-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,24 @@ class SearchContainer extends Component {
this.triggerChange = this.triggerChange.bind(this)
this.onAddTimer = this.onAddTimer.bind(this)
this.onClearSearch = this.onClearSearch.bind(this)
}

componentWillMount () {
this.searchTimer = null
}

componentDidMount () {
// When the user opens the window lets focus the search input
ipcRenderer.on('windowVisible', () => {
console.log('windowVisible')
this.focusSearch()
if (this.searchInput.current)
this.searchInput.current.focus()
})
}

componentWillMount () {
this.searchTimer = null
}

onAddTimer (id, key, summary) {
this.props.addTimer(id, key, summary)
this.onClearSearch()
}

focusSearch () {
console.log('Focusing search')
this.searchInput.current.focus()
}

onClearSearch () {
this.setState({
query: '',
Expand Down Expand Up @@ -97,7 +91,7 @@ class SearchContainer extends Component {
cursor: prevState.cursor - 1
}))

this.scrollActiveTaskIntoView()
this.scrollActiveTaskIntoView()
break

// Down arrow
Expand All @@ -109,14 +103,14 @@ class SearchContainer extends Component {
cursor: prevState.cursor + 1
}))

this.scrollActiveTaskIntoView()
this.scrollActiveTaskIntoView()
break
}
}

scrollActiveTaskIntoView () {
let itemComponent = this.refs.activeItem
console.log({itemComponent})
//console.log('itemComponent', itemComponent)
if (itemComponent) {
let domNode = ReactDOM.findDOMNode(itemComponent)
domNode.scrollIntoView(true)
Expand Down
3 changes: 2 additions & 1 deletion src/containers/timer/timer-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { Component, Fragment } from 'react'
import { connect } from 'react-redux'
import styled from 'styled-components'
import find from 'lodash.find'
import throttle from 'lodash.throttle'
import parseDuration from 'parse-duration'
import { formatSecondsToStopWatch, roundToNearestMinutes, secondsHuman } from '../../lib/time'
import { openInJira } from '../../lib/jira'
Expand Down Expand Up @@ -38,7 +39,7 @@ class TimerContainer extends Component {
this.onTimeChanged = this.onTimeChanged.bind(this)
this.onEditTime = this.onEditTime.bind(this)
this.onResetEditTime = this.onResetEditTime.bind(this)
this.onEditComment = this.onEditComment.bind(this)
this.onEditComment = throttle(this.onEditComment.bind(this), 1000)
this.onResetEditComment = this.onResetEditComment.bind(this)
this.onCommentSaved = this.onCommentSaved.bind(this)
this.onPlay = this.onPlay.bind(this)
Expand Down

0 comments on commit 085b764

Please sign in to comment.