Skip to content

Commit

Permalink
New feature: notify users whenever there is a new release available
Browse files Browse the repository at this point in the history
  • Loading branch information
hackjutsu committed Feb 5, 2017
1 parent 0a7f931 commit 4ba4c16
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 14 deletions.
16 changes: 16 additions & 0 deletions app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export const SELECT_GIST = 'SELECT_GIST'
export const UPDATE_AUTHWINDOW_STATUS = 'UPDATE_AUTHWINDOW_STATUS'
export const UPDATE_GIST_SYNC_STATUS = 'UPDATE_GIST_SYNC_STATUS'
export const UPDATE_SEARCHWINDOW_STATUS = 'UPDATE_SEARCHWINDOW_STATUS'
export const UPDATE_UPDATEAVAILABLEBAR_STATUS = 'UPDATE_UPDATEAVAILABLEBAR_STATUS'
export const UPDATE_NEW_VERSION_INFO = 'UPDATE_NEW_VERSION_INFO'

export function updateNewVersionInfo (status) {
return {
type: UPDATE_NEW_VERSION_INFO,
payload: status
}
}

export function updateUpdateAvailableBarStatus (status) {
return {
type: UPDATE_UPDATEAVAILABLEBAR_STATUS,
payload: status
}
}

export function updateGistSyncStatus (status) {
return {
Expand Down
52 changes: 49 additions & 3 deletions app/containers/appContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict'

import React, { Component } from 'react'
import { shell } from 'electron'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Alert } from 'react-bootstrap'
import NavigationPanelDetails from '../navigationPanelDetails'
import NavigationPanel from '../navigationPanel'
import LoginPage from '../loginPage'
import SnippetTable from '../snippetTable'
import SearchPage from '../searchPage'
import './index.scss'

import { updateUpdateAvailableBarStatus } from '../../actions/index'

class AppContainer extends Component {

renderSearchPage () {
Expand All @@ -18,6 +23,25 @@ class AppContainer extends Component {
)
}

dismissAlert () {
this.props.updateUpdateAvailableBarStatus('OFF')
}

handleDownloadClicked () {
shell.openExternal(this.props.newVersionInfo.url)
this.dismissAlert()
}

handleReleaseNotesClicked () {
shell.openExternal('https://github.com/hackjutsu/Lepton/releases')
this.dismissAlert()
}

handleSkipClicked () {
localStorage.setItem('skipped-version', this.props.newVersionInfo.version)
this.dismissAlert()
}

render () {
let {
userSession,
Expand All @@ -27,12 +51,26 @@ class AppContainer extends Component {
updateActiveGistAfterClicked,
reSyncUserGists,
searchWindowStatus,
searchIndex } = this.props
updateAvailableBarStatus,
searchIndex,
newVersionInfo } = this.props

if (userSession.activeStatus === 'ACTIVE') {
return (
<div className='app-container'>
{ this.renderSearchPage() }
{ updateAvailableBarStatus === 'ON'
? <Alert bsStyle="warning" onDismiss={ this.dismissAlert.bind(this) }>
{ `New version ${newVersionInfo.version} is available! ` }
<a className='customized-button' onClick={ this.handleSkipClicked.bind(this) }>#skip</a>
{ newVersionInfo.url
? <a className='customized-button' onClick={ this.handleReleaseNotesClicked.bind(this) }>#release</a>
: <a className='customized-button' onClick={ this.handleReleaseNotesClicked.bind(this) }>#download</a> }
{ newVersionInfo.url
? <a className='customized-button' onClick={ this.handleDownloadClicked.bind(this) }>#download</a>
: null }
</Alert>
: null }
<NavigationPanel
searchIndex = { searchIndex }
updateLocalStorage = { updateLocalStorage }
Expand All @@ -59,8 +97,16 @@ class AppContainer extends Component {
function mapStateToProps (state) {
return {
userSession: state.userSession,
searchWindowStatus: state.searchWindowStatus
searchWindowStatus: state.searchWindowStatus,
newVersionInfo: state.newVersionInfo,
updateAvailableBarStatus: state.updateAvailableBarStatus
}
}

export default connect(mapStateToProps)(AppContainer)
function mapDispatchToProps (dispatch) {
return bindActionCreators({
updateUpdateAvailableBarStatus: updateUpdateAvailableBarStatus
}, dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(AppContainer)
21 changes: 21 additions & 0 deletions app/containers/appContainer/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,24 @@
margin: 5px 20px 5px 20px;
max-height: 95vh;
}

.app-container {
.font-style-base {
font-family: Consolas, Menlo, Monaco, "Courier New", monospace;
font-size: 13px;
}

.bar-button {
width: 100px;
}

.customized-button {
@extend .font-style-base;
float: right;
margin: 5px 5px 0px 10px;
}

.customized-button:hover {
cursor: pointer;
}
}
17 changes: 14 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import {
selectGist,
updateAuthWindowStatus,
updateGistSyncStatus,
updateSearchWindowStatus
updateSearchWindowStatus,
updateUpdateAvailableBarStatus,
updateNewVersionInfo
} from './actions/index'

import Notifier from './utilities/notifier'
Expand Down Expand Up @@ -417,12 +419,21 @@ ipcRenderer.on('search-gist', data => {
let newStatus = preStatus === 'ON' ? 'OFF' : 'ON'
reduxStore.dispatch(updateSearchWindowStatus(newStatus))
})

ipcRenderer.on('update-available', payload => {
logger.debug('The renderer process receives update-available signal from the main process')
const newVersionInfo = remote.getGlobal('newVersionInfo')
if (localStorage.getItem('skipped-version') === newVersionInfo.version ) return

reduxStore.dispatch(updateNewVersionInfo(newVersionInfo))
reduxStore.dispatch(updateUpdateAvailableBarStatus('ON'))
})
/** End: Response to main process events **/

// Start
const reduxStore = createStore(
RootReducer,
applyMiddleware(thunk)
RootReducer,
applyMiddleware(thunk)
)

ReactDom.render(
Expand Down
6 changes: 5 additions & 1 deletion app/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import UserSessionReducer from './reducer_user_session'
import AuthWindowStatusReducer from './reducer_auth_window_status'
import GistSyncStatusReducer from './reducer_gist_sync_status'
import SearchWindowStatusReducer from './reducer_search_window_status'
import UpdateAvailableBarStatusReducer from './reducer_update_available_bar_status'
import NewVersionInfoReducer from './reducer_new_version_info'

const rootReducer = combineReducers({
form: formReducer,
Expand All @@ -24,7 +26,9 @@ const rootReducer = combineReducers({
activeGistTag: ActiveGistTagReducer,
authWindowStatus: AuthWindowStatusReducer,
gistSyncStatus: GistSyncStatusReducer,
searchWindowStatus: SearchWindowStatusReducer
searchWindowStatus: SearchWindowStatusReducer,
updateAvailableBarStatus: UpdateAvailableBarStatusReducer,
newVersionInfo: NewVersionInfoReducer
})

export default rootReducer
12 changes: 12 additions & 0 deletions app/reducers/reducer_new_version_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

import { UPDATE_NEW_VERSION_INFO } from '../actions'

export default function (state = { version: '', url: '' }, action) {
switch (action.type) {
case UPDATE_NEW_VERSION_INFO:
return action.payload
default:
}
return state
}
13 changes: 13 additions & 0 deletions app/reducers/reducer_update_available_bar_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

import { UPDATE_UPDATEAVAILABLEBAR_STATUS } from '../actions'

export default function (state = 'OFF', action) {
switch (action.type) {
case UPDATE_UPDATEAVAILABLEBAR_STATUS:
return action.payload
default:
}

return state
}
Binary file added docs/img/portfolio/markdown.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const logger = require('winston')
const path = require('path')
const fs = require('fs')

const autoUpdater = require("electron-updater").autoUpdater
autoUpdater.logger = logger
autoUpdater.autoDownload = false

initGlobalLogger()

let mainWindow = null
Expand Down Expand Up @@ -61,6 +65,18 @@ function createWindow () {
// console.log('You pressed ' + keyEnter)
mainWindow && mainWindow.webContents.send('key-enter')
})
autoUpdater.on('error', data => {
logger.debug('[autoUpdater] error ' + JSON.stringify(data))
})
autoUpdater.on('update-not-available', () => {
logger.debug('[autoUpdater] update-not-available')
})
autoUpdater.on('update-available', (info) => {
logger.debug('[autoUpdater] update-available. ' + mainWindow)
global.newVersionInfo = info
mainWindow && mainWindow.webContents.send('update-available')
})
autoUpdater.checkForUpdates()
})

const ContextMenu = require('electron-context-menu')
Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"name": "Lepton",
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.7",
"description": "AWESOME Gist client for everyone",
"productName": "Lepton",
"main": "main.js",
"scripts": {
"lint": "eslint app",
"dev": "node dev-server.js",
"pack": "webpack --display-modules",
"watch": "webpack --watch",
"start": "electron ./main.js",
"test": "webpack --display-modules",
"dist": "build"
"dist": "build",
"release": "build"
},
"repository": {
"type": "git",
"url": ""
"url": "https://github.com/hackjutsu/Lepton.git"
},
"keywords": [
"gist",
Expand Down Expand Up @@ -55,6 +56,7 @@
"elasticlunr": "^0.9.5",
"electron-context-menu": "^0.8.0",
"electron-localshortcut": "^1.0.0",
"electron-updater": "^1.4.2",
"highlight.js": "^9.9.0",
"human-readable-time": "^0.2.4",
"image-downloader": "^2.0.1",
Expand All @@ -73,19 +75,22 @@
"build": {
"appId": "com.cosmox.lepton",
"mac": {
"category": "public.app-category.education"
"category": "public.app-category.education",
"publish": ["github"]
},
"win": {
"title": "Lepton",
"author": "CosmoX",
"target": "nsis"
"target": "nsis",
"publish": ["github"]
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"linux": {
"target": "AppImage"
"target": "AppImage",
"publish": ["github"]
}
}
}

0 comments on commit 4ba4c16

Please sign in to comment.