Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat(releases): add basics to create binary releases (#41)
Browse files Browse the repository at this point in the history
* adds all boilerplate needed to do cross platform releases : closes #32 and closes #40
* adds basic notification system to detect & inform of new releases : after some testing this is simpler and more efficient for now than auto updates : closes #24
  • Loading branch information
kaosat-dev authored Apr 5, 2018
1 parent 1297024 commit 2d4e729
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules/
.nyc_output
coverage
*.log
dist
build
Binary file added assets/icons/icon.icns
Binary file not shown.
Binary file added assets/icons/icon.ico
Binary file not shown.
Binary file added assets/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,16 @@
.dark{
color:white;
}

#appUpdates {
visibility: visible;
position: absolute;
z-index: 99;
top: 40px;
right: 100px;
}
#appUpdates a{
text-decoration:none;
}
</style>
</head>
<body>
Expand Down
10 changes: 8 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function createWindow () {
offscreen: true,
webPreferences: {
nodeIntegrationInWorker: true
}
},
icon: path.join(__dirname, 'assets/icons/icon.png')
}
mainWindow = new BrowserWindow(options)

Expand All @@ -36,7 +37,7 @@ function createWindow () {
}))

// Open the DevTools.
//mainWindow.webContents.openDevTools()
// mainWindow.webContents.openDevTools()

// Emitted when the window is closed.
mainWindow.on('closed', function () {
Expand All @@ -45,6 +46,11 @@ function createWindow () {
// when you should delete the corresponding element.
mainWindow = null
})

mainWindow.webContents.on('new-window', function (event, url) {
event.preventDefault()
require('electron').shell.openExternal(url)
})
}

// This method will be called when Electron has finished
Expand Down
30 changes: 20 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
"dev": "node node_modules/.bin/electron .",
"dev-win": "node_modules/.bin/electron.cmd .",
"pack": "electron-builder --dir",
"pack:all": "build --dir -mlw",
"pack:mac": "build --dir -m",
"pack:linux": "build --dir -l",
"pack:windows": "build --dir -w",
"dist": "electron-builder",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"version": "npm run changelog && git add -A ",
"release": "build",
"release:all": "build -mlw",
"release:mac": "build -m",
"release:linux": "build -l",
"release:windows": "build -w",
"postversion": "git push origin master && git push origin master --tags",
"release-patch": "git checkout master && git pull origin master && npm version patch",
"release-minor": "git checkout master && git pull origin master && npm version minor",
Expand All @@ -36,6 +45,7 @@
"astring": "^1.2.0",
"bel": "^5.1.5",
"blob-to-buffer": "^1.2.6",
"compare-version": "^0.1.2",
"decache": "^4.3.0",
"detective-cjs": "^2.0.0",
"electron-store": "^1.3.0",
Expand All @@ -57,23 +67,23 @@
"electron-builder": "^20.4.1"
},
"build": {
"appId": "jscad.id",
"appId": "org.jscad.desktop",
"mac": {
"category": "public.app-category.graphics-design"
"category": "public.app-category.graphics-design",
"fileAssociations": [
{
"ext": "jscad",
"name": "jscad",
"role": "editor"
}
]
},
"linux": {
"target": "AppImage",
"category": "Graphics"
},
"win": {
"target": "nsis"
},
"fileAssociations": [
{
"ext": "jscad",
"name": "jscad",
"role": "editor"
}
]
}
}
}
68 changes: 64 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ const dragAndDropSource$ = makeDragDropSource(document)
const {watcherSink, watcherSource} = require('./sideEffects/fileWatcher')
const {fsSink, fsSource} = require('./sideEffects/fsWrapper')
const {domSink, domSource} = require('./sideEffects/dom')
const paramsCallbacktoStream = require('./utils/observable-utils/callbackToObservable')()
const makeWorkerEffect = require('./sideEffects/worker')
const {appUpdateSource} = require('./sideEffects/appUpdates')

const solidWorker = makeWorkerEffect('src/core/code-evaluation/rebuildSolidsWorker.js')
const paramsCallbacktoStream = require('./utils/observable-utils/callbackToObservable')()

// proxy state stream to be able to access & manipulate it before it is actually available
const { attach, stream } = proxy()
const state$ = stream
//

// appUpdateSource().forEach(x => console.log('update available', x))

const sources = {
store: storeSource$,
drops: dragAndDropSource$,
Expand All @@ -29,7 +34,8 @@ const sources = {
paramChanges: paramsCallbacktoStream.stream,
state$,
dom: domSource(),
solidWorker: solidWorker.source()
solidWorker: solidWorker.source(),
appUpdates: appUpdateSource()
}
const designActions = require('./ui/design/actions')(sources)
const ioActions = require('./ui/io/actions')(sources)
Expand Down Expand Up @@ -143,7 +149,7 @@ state$
})

// ui updates, exports

// FIXME: this is horrible, restructure
const outToDom$ = state$
.skipRepeatsWith(function (state, previousState) {
const sameParamDefinitions = JSON.stringify(state.design.paramDefinitions) === JSON.stringify(previousState.design.paramDefinitions)
Expand All @@ -164,8 +170,10 @@ const outToDom$ = state$
const sameShowOptions = state.showOptions === previousState.showOptions
const samevtreeMode = state.vtreeMode === previousState.vtreeMode

const sameAppUpdates = JSON.stringify(state.appUpdates) === JSON.stringify(previousState.appUpdates)

return sameParamDefinitions && sameParamValues && sameExportFormats && sameStatus && sameStyling &&
sameAutoreload && sameInstantUpdate && sameError && sameShowOptions && samevtreeMode
sameAutoreload && sameInstantUpdate && sameError && sameShowOptions && samevtreeMode && sameAppUpdates
})
.map(state => require('./ui/main')(state, paramsCallbacktoStream))

Expand Down Expand Up @@ -228,3 +236,55 @@ function setCanvasSize (viewerElement) {
window.onresize = function () {
setCanvasSize(document.getElementById('renderTarget'))
}

// const { dialog } = require('electron')

/*
let updater
autoUpdater.autoDownload = false
autoUpdater.on('error', (error) => {
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString())
})
autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
}
else {
updater.enabled = true
updater = null
}
})
})
autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
})
updater.enabled = true
updater = null
})
autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
}, () => {
setImmediate(() => autoUpdater.quitAndInstall())
})
})
// export this to MenuItem click callback
function checkForUpdates (menuItem, focusedWindow, event) {
updater = menuItem
updater.enabled = false
autoUpdater.checkForUpdates()
} */
34 changes: 34 additions & 0 deletions src/sideEffects/appUpdates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const https = require('https')
const packageInfo = require('../../package.json')
const compareVersion = require('compare-version')
const callBackToStream = require('../utils/observable-utils/callbackToObservable')
const updatesFromCB = callBackToStream()

function appUpdateSource () {
https.get({
host: 'api.github.com',
path: '/repos/jscad/jscad-desktop/releases/latest',
headers: {
'user-agent': `jscad v${packageInfo.localVersion}`
}
}, function (res) {
if (res.statusCode === 200) {
let result = ''
res.on('data', (x) => {
result += x
}).on('end', () => {
const info = JSON.parse(result)
const remoteVersion = info.tag_name.slice(1)
const localVersion = packageInfo.version
const updateAvailable = (compareVersion(remoteVersion, localVersion) > 0)
if (updateAvailable) {
updatesFromCB.callback({available: updateAvailable, version: remoteVersion})
}
})
}
}
)
return updatesFromCB.stream
}

module.exports = {appUpdateSource}
4 changes: 2 additions & 2 deletions src/sideEffects/electronStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const most = require('most')
function electronStoreSideEffect (outToStore$) {
if (outToStore$) {
outToStore$.forEach(function (outToStore) {
//console.log('outToStore', outToStore)
// console.log('outToStore', outToStore)
store.set(outToStore)
})
}
Expand All @@ -17,7 +17,7 @@ function electronStoreSideEffect (outToStore$) {
function electronStoreSink (outToStore$) {
if (outToStore$) {
outToStore$.forEach(function (outToStore) {
//console.log('outToStore', outToStore)
// console.log('outToStore', outToStore)
store.set(outToStore)
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const themes = {
}
const initialState = {
appTitle: `jscad v ${packageMetadata.version}`,
appUpdates: {available: false, version: undefined},
// for possible errors
error: undefined,
// design data
Expand Down Expand Up @@ -57,6 +58,10 @@ function makeState (actions) {
console.log('set Errors', error)
const formattedError = error// {message: error.message, lineno:}
return Object.assign({}, state, {error: formattedError, busy: false})
},
setAppUpdatesAvailable: (state, {version, available}) => {
console.log('updates available', version, available)
return Object.assign({}, state, {appUpdates: {version, available}})
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/ui/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,24 @@ const makeActions = (sources) => {
.delay(30000) */
// .forEach(x => console.log('clear errors', x))

const setAppUpdatesAvailable$ = most.mergeArray([
sources
.appUpdates
.map(data => ({type: 'setAppUpdatesAvailable', data})),
sources
.appUpdates
.delay(15000)// hide after 30 s
.map(data => ({type: 'setAppUpdatesAvailable', data: {available: false}}))
])

return {
// generic key shortuct handler
actionsFromKey$,
// generic clear error action
clearErrors$,
setErrors$,
// app updates
setAppUpdatesAvailable$,
// ui
changeTheme$,
toggleOptions$
Expand Down
7 changes: 7 additions & 0 deletions src/ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ function dom (state, paramsCallbacktoStream) {
</section>
</header>
<!--Status information/errors-->
<span id='busy'>${state.busy ? 'processing, please wait' : ''}</span>
<span id='status'>${statusMessage}</span>
<span id='appUpdates' style='visibility:${state.appUpdates.available === false ? 'hidden' : 'visible'}'>
<a href='https://github.com/jscad/jscad-desktop/releases' target="_blank">
@jscad/desktop version ${state.appUpdates.version} is available! Please click here to view and download
</a>
</span>
<!--Ui Controls-->
<div id='controls'>
<label for="grid">Grid</label>
Expand Down

0 comments on commit 2d4e729

Please sign in to comment.