Skip to content

Commit

Permalink
added native dialogs and http/http settings for run app
Browse files Browse the repository at this point in the history
  • Loading branch information
psvensson committed Sep 27, 2016
1 parent e2f0a15 commit a376271
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 39 deletions.
5 changes: 3 additions & 2 deletions app/hyper/server/file-server.js
Expand Up @@ -231,7 +231,7 @@ function sendMessageToServer(_socket, name, data)
if(!cloudToken)
{
console.log('trying to open token dialog....')
EVENTS.publish(EVENTS.OPENTOKENDIALOG, '')
EVENTS.publish(EVENTS.OPENTOKENDIALOG, 'Cloud Token Missing')
}
}
else
Expand Down Expand Up @@ -562,7 +562,8 @@ exports.runApp = function()
sessionID: mSessionID,
appID: mAppID,
appName: hyper.UI.getProjectNameFromFile(exports.getAppPath()),
url: getAppURL()
url: getAppURL(),
protocol: SETTINGS.getRunProtocol()
})
}

Expand Down
10 changes: 10 additions & 0 deletions app/hyper/settings/settings.js
Expand Up @@ -148,6 +148,16 @@ systemSetting('SessionID', null)
*/
systemSetting('RepositoryURLs', '')

/*
* Which protocol the viewer should run against
*/
systemSetting('RunProtocol', 'http')

/**
* URL for translation JSON
*/
systemSetting('TranslationsURL', MAIN.TRANSLATIONS+'/translations.json')

/**
* Settings for user GUID are handled specially to preserve existing ids.
*/
Expand Down
16 changes: 16 additions & 0 deletions app/hyper/ui/index.html
Expand Up @@ -61,6 +61,7 @@
<div id="panel-middle">

<!-- ModalDialog-NoClientConnected--->
<!--
<div class="modal fade" id="ModalDialog-NoClientConnected" tabindex="-1" role="dialog" aria-labelledby="ModalDialog-NoClientConnected-Label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand All @@ -77,6 +78,7 @@ <h4 class="modal-title" id="ModalDialog-NoClientConnected-Label">No Evothings Vi
</div>
</div>
</div>
-->

<!-- Modal dialog: dialog-settings -->
<div class="modal fade"
Expand Down Expand Up @@ -133,6 +135,18 @@ <h4 class="modal-title" id="dialog-settings-label">
class="form-control"/>
</div>

<div class="form-group">
<label for="input-setting-repository-urls">
Protocol to use for loading webapps :</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-http">
<input type="radio" id="option-http" class="mdl-radio__button" name="protocol" value="http" checked>
<span class="mdl-radio__label">HTTP</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-https">
<input type="radio" id="option-https" class="mdl-radio__button" name="protocol" value="https">
<span class="mdl-radio__label">HTTPS</span>
</label>
</div>
<span>
<div class="form-group">
<label> Reset Cloud Token:</label>
Expand Down Expand Up @@ -390,6 +404,7 @@ <h4 class="modal-title" id="dialog-remove-app-label">
</div>

<!-- ModalDialog: dialog-system-message --->
<!--
<div class="modal fade"
id="dialog-system-message"
tabindex="-1"
Expand Down Expand Up @@ -421,6 +436,7 @@ <h4 class="modal-title" id="dialog-system-message-label">
</div>
</div>
</div>
-->

<!-- ModalDialog: dialog-build-message --->
<div class="modal fade"
Expand Down
24 changes: 23 additions & 1 deletion app/hyper/ui/main-window-events.js
Expand Up @@ -624,7 +624,29 @@ exports.defineUIEvents = function(hyper)
// Called when you press Run and no client is connected.
hyper.UI.noClientConnectedHander = function()
{
hyper.UI.$('#ModalDialog-NoClientConnected').modal('show')
/*
<div class="modal fade" id="ModalDialog-NoClientConnected" tabindex="-1" role="dialog" aria-labelledby="ModalDialog-NoClientConnected-Label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="ModalDialog-NoClientConnected-Label">No Evothings Viewer app connected</h4>
</div>
<div class="modal-body">
Please connect from the Evothings Viewer</a> app on your mobile device(s). Learn more on the <a href="javascript:void(0)" id="ModalDialog-NoClientConnected-HelpLink">Getting Started screen</a>.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
*/
//hyper.UI.$('#ModalDialog-NoClientConnected').modal('show')
MAIN.openDialog(
'No Evothings Viewer app connected',
'Please connect from the Evothings Viewer app on your mobile device(s). Learn more on the Getting Started screen.'
)
}

// Click handler for link in the ModalDialog-NoClientConnected dialog.
Expand Down
20 changes: 19 additions & 1 deletion app/hyper/ui/main-window-func.js
Expand Up @@ -80,6 +80,7 @@ exports.defineUIFunctions = function(hyper)
setTimeout(function() {mUpdatingLists = false}, 5000)
hyper.UI.updateExampleList(silent)
hyper.UI.updateLibraryList(silent)
UTIL.updateTranslations(SETTINGS.getTranslationsURL())
} else {
console.log("Already updating lists, ignoring")
}
Expand Down Expand Up @@ -125,13 +126,21 @@ exports.defineUIFunctions = function(hyper)
console.log('------------------ setting up open token dialog listener...')
EVENTS.subscribe(EVENTS.OPENTOKENDIALOG, function(message)
{
console.log('open cloud token dialog')
console.log('------------------ token dialog event. message = '+message)
if(message)
{
console.log('open cloud token dialog')
MAIN.openDialog('Cloud Token Message', message, 'info')
}

/*
if(message)
{
hyper.UI.$('#tokentext')[0].innerHTML = message
}
hyper.UI.$('#connect-spinner').removeClass('icon-spin-animate')
dialog.showModal()
*/
hyper.UI.hideToken()
})
}
Expand Down Expand Up @@ -1049,6 +1058,11 @@ exports.defineUIFunctions = function(hyper)
SETTINGS.getReloadServerAddress())
hyper.UI.$('#input-setting-repository-urls').val(
SETTINGS.getRepositoryURLs())
var $radios = $('input:radio[name=protocol]')
var checked = SETTINGS.getRunProtocol()
console.log('-- protocol setting is')
console.log(JSON.stringify(checked))
$radios.filter('[value='+checked+']').prop('checked', true)

// Show settings dialog.
hyper.UI.$('#dialog-settings').modal('show')
Expand Down Expand Up @@ -1094,6 +1108,7 @@ exports.defineUIFunctions = function(hyper)
hyper.UI.displayConnectKey(
'Server address has been changed. Click GET KEY to get a new connect key.')
}
SETTINGS.setRunProtocol($('input[name=protocol]:checked').val())
}

hyper.UI.disconnectAllViewers = function()
Expand Down Expand Up @@ -1665,11 +1680,14 @@ exports.defineUIFunctions = function(hyper)

hyper.UI.displaySystemMessage = function(message)
{
/*
if (!hyper.UI.$('#dialog-system-message').is(':visible'))
{
hyper.UI.$('#dialog-system-message').modal('show')
}
hyper.UI.$('#system-message').text(message)
*/
MAIN.openDialog('System Message', message, 'info')
}

hyper.UI.openBuildMessageDialog = function(message)
Expand Down
114 changes: 83 additions & 31 deletions app/hyper/util/util.js
Expand Up @@ -31,40 +31,65 @@ exports.alertDownloadError = function(msg, url, status) {
window.alert(`${msg}\n\nURL: ${url}\nSTATUS: ${status}\n\nDo you have internet access?`)
}

exports.getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { //if complete
if (xhr.status === 200){ //check if "OK" (200)
resolve([xhr.response, url]);
} else {
reject([xhr.statusText, url]);
}
}
}

xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.send();
});
var getJSON = function(url)
{
return new Promise(function(resolve, reject)
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === 4)
{ //if complete
if (xhr.status === 200)
{ //check if "OK" (200)
resolve([xhr.response, url]);
}
else
{
reject([xhr.statusText, url]);
}
}
}
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.send();
});
};

exports.updateTranslations = function(url)
{
console.log('UTIL.updateTranslations called')
getJSON(url).then(function(ttext)
{
console.log('UTIL.updateTranslations got new translations.')
console.dir(ttext)
translations = ttext
}, function(err)
{
console.log('unable to donwload translations :(')
console.dir(err)
})
}


exports.getJSON = getJSON

exports.checkInternet = function() {
return exports.getJSON('http://evothings.com/pong.json').then(json => {
// If there is an alert message, show it to the user
if (json[0].alert) {
window.alert(json[0].alert)
}
// Otherwise we just log that we are fine
console.log(json[0].message)
return true
}, error => {
// Ok, couldn't reach pong.json, internet is probably down
window.alert('You do not seem to have internet access?\n\nEvothings Studio requires access to the Internet.');
return false
})
return exports.getJSON('http://evothings.com/pong.json').then(json =>
{
// If there is an alert message, show it to the user
if (json[0].alert) {
window.alert(json[0].alert)
}
// Otherwise we just log that we are fine
console.log(json[0].message)
return true
}, error =>
{
// Ok, couldn't reach pong.json, internet is probably down
window.alert('You do not seem to have internet access?\n\nEvothings Studio requires access to the Internet.');
return false
})
}

exports.unzip = function(zipfile, path, cb) {
Expand Down Expand Up @@ -99,3 +124,30 @@ exports.download = function(url, cb) {
})
})
}

var translations =
{
// Strings internal to the workbench
'No Evothings Viewer app connected': '* No Evothings Viewer app connected',
'Please connect from the Evothings Viewer app on your mobile device(s). Learn more on the Getting Started screen.':
'* Please connect from the Evothings Viewer app on your mobile device(s). Learn more on the Getting Started screen.',
'System Message': '* System Message',
// Strings coming from the proxy
'Could not find cloud API token': '* Could not find cloud API token',
'Cloud API token has already been used': '* Cloud API token has already been used',
// Proxy names for limits
'Clients': '* Clients',
'InstrumentationDataStreams': '* InstrumentationDataStreams',
'exceeded (limit:': '* exceeded (limit:'
}

exports.translate = function(content)
{
// TODO: actually translate :)
for( k in translations)
{
var v = translations[k]
content = content.replace(k,v)
}
return content
}
16 changes: 16 additions & 0 deletions app/main.js
Expand Up @@ -24,13 +24,16 @@ main.BASE = 'https://evothings.com/' + main.VERSION
main.DOC = main.BASE + "/doc"
main.EXAMPLES = main.BASE + "/examples"
main.LIBRARIES = main.BASE + "/libraries"
main.TRANSLATIONS = main.BASE + '/translations'

main.limits = 'Not yet available'


const electron = require('electron')
const app = electron.app
const DIALOG = require('electron').dialog;
console.dir(__dirname)
const UTIL = require('/home/peter/projects/evothings-studio/app/hyper/util/util.js')

// We don't really want caching since it can serve stale examples and libraries
app.commandLine.appendSwitch('disable-http-cache', 'true');
Expand Down Expand Up @@ -505,6 +508,19 @@ main.selectOrCreateFolder = function(title, defaultDir) {
defaultPath: defaultDir, properties: [ 'openDirectory', 'createDirectory']})
}

main.openDialog = function(title, content, type) {

console.log('openDialog called title = '+title+', content = '+content)
DIALOG.showMessageBox(
{
type: type || "info",
title: title,
/*message:content,*/
buttons: ["Close"],
detail: UTIL.translate(content)
})
}

// Work as relay between our BrowserWindows since they can not talk to
// each other directly. We simply have one relay handler per window.
ipcMain.on('workbench-window', function(event, arg) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -13,6 +13,7 @@
"electron-builder": "^4.2.6",
"electron-packager": "^7.0.3",
"electron-prebuilt": "^1.2.1",
"node-promise": "^0.5.12",
"spectron": "^3.3.0"
},
"build": {
Expand Down

0 comments on commit a376271

Please sign in to comment.