diff --git a/web/.gitignore b/web/.gitignore index 1b005d6..6a27807 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -10,6 +10,7 @@ node npm-debug.log* yarn-debug.log* yarn-error.log* +*.keystore # Editor directories and files .idea diff --git a/web/src-cordova/.npmignore b/web/src-cordova/.npmignore new file mode 100644 index 0000000..fd29596 --- /dev/null +++ b/web/src-cordova/.npmignore @@ -0,0 +1,2 @@ +# OS X +.DS_Store diff --git a/web/src-cordova/config.xml b/web/src-cordova/config.xml new file mode 100644 index 0000000..c76621b --- /dev/null +++ b/web/src-cordova/config.xml @@ -0,0 +1,25 @@ + + + HABot + A chatbot for openHAB + + Yannick Schaus + + + + + + + + + + + + + + + + + + + diff --git a/web/src-cordova/hooks/README.md b/web/src-cordova/hooks/README.md new file mode 100644 index 0000000..574ad4c --- /dev/null +++ b/web/src-cordova/hooks/README.md @@ -0,0 +1,23 @@ + +# Cordova Hooks + +Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. See Hooks Guide for more details: http://cordova.apache.org/docs/en/edge/guide_appdev_hooks_index.md.html#Hooks%20Guide. diff --git a/web/src-cordova/package-lock.json b/web/src-cordova/package-lock.json new file mode 100644 index 0000000..8a40ddc --- /dev/null +++ b/web/src-cordova/package-lock.json @@ -0,0 +1,227 @@ +{ + "name": "org.openhab.ui.habot", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "cordova-android": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/cordova-android/-/cordova-android-7.0.0.tgz", + "integrity": "sha1-yVvt/PvDhjsYDE0p7/7E95Nh0Z0=", + "requires": { + "android-versions": "1.2.1", + "cordova-common": "2.2.0", + "elementtree": "0.1.6", + "nopt": "3.0.6", + "properties-parser": "0.2.3", + "q": "1.5.1", + "shelljs": "0.5.3" + }, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true + }, + "android-versions": { + "version": "1.2.1", + "bundled": true + }, + "ansi": { + "version": "0.3.1", + "bundled": true + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true + }, + "base64-js": { + "version": "0.0.8", + "bundled": true + }, + "big-integer": { + "version": "1.6.26", + "bundled": true + }, + "bplist-parser": { + "version": "0.1.1", + "bundled": true, + "requires": { + "big-integer": "1.6.26" + } + }, + "brace-expansion": { + "version": "1.1.8", + "bundled": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true + }, + "cordova-common": { + "version": "2.2.0", + "bundled": true, + "requires": { + "ansi": "0.3.1", + "bplist-parser": "0.1.1", + "cordova-registry-mapper": "1.1.15", + "elementtree": "0.1.6", + "glob": "5.0.15", + "minimatch": "3.0.4", + "osenv": "0.1.4", + "plist": "1.2.0", + "q": "1.5.1", + "semver": "5.4.1", + "shelljs": "0.5.3", + "underscore": "1.8.3", + "unorm": "1.4.1" + } + }, + "cordova-registry-mapper": { + "version": "1.1.15", + "bundled": true + }, + "elementtree": { + "version": "0.1.6", + "bundled": true, + "requires": { + "sax": "0.3.5" + } + }, + "glob": { + "version": "5.0.15", + "bundled": true, + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true + }, + "lodash": { + "version": "3.10.1", + "bundled": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "nopt": { + "version": "3.0.6", + "bundled": true, + "requires": { + "abbrev": "1.1.1" + } + }, + "once": { + "version": "1.4.0", + "bundled": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true + }, + "plist": { + "version": "1.2.0", + "bundled": true, + "requires": { + "base64-js": "0.0.8", + "util-deprecate": "1.0.2", + "xmlbuilder": "4.0.0", + "xmldom": "0.1.27" + } + }, + "properties-parser": { + "version": "0.2.3", + "bundled": true + }, + "q": { + "version": "1.5.1", + "bundled": true + }, + "sax": { + "version": "0.3.5", + "bundled": true + }, + "semver": { + "version": "5.4.1", + "bundled": true + }, + "shelljs": { + "version": "0.5.3", + "bundled": true + }, + "underscore": { + "version": "1.8.3", + "bundled": true + }, + "unorm": { + "version": "1.4.1", + "bundled": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true + }, + "wrappy": { + "version": "1.0.2", + "bundled": true + }, + "xmlbuilder": { + "version": "4.0.0", + "bundled": true, + "requires": { + "lodash": "3.10.1" + } + }, + "xmldom": { + "version": "0.1.27", + "bundled": true + } + } + }, + "cordova-plugin-whitelist": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz", + "integrity": "sha1-tehezbv+Wu3tQKG/TuI3LmfZb7Q=" + } + } +} diff --git a/web/src-cordova/package.json b/web/src-cordova/package.json new file mode 100644 index 0000000..8dc0484 --- /dev/null +++ b/web/src-cordova/package.json @@ -0,0 +1,24 @@ +{ + "name": "org.openhab.ui.habot", + "displayName": "HABot", + "version": "1.0.0", + "description": "A sample Apache Cordova application that responds to the deviceready event.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Apache Cordova Team", + "license": "Apache-2.0", + "dependencies": { + "cordova-android": "^7.0.0", + "cordova-plugin-whitelist": "^1.3.3" + }, + "cordova": { + "plugins": { + "cordova-plugin-whitelist": {} + }, + "platforms": [ + "android" + ] + } +} \ No newline at end of file diff --git a/web/src-cordova/res/README.md b/web/src-cordova/res/README.md new file mode 100644 index 0000000..bffb33b --- /dev/null +++ b/web/src-cordova/res/README.md @@ -0,0 +1,29 @@ + + +Note that these image resources are not copied into a project when a project +is created with the CLI. Although there are default image resources in a +newly-created project, those come from the platform-specific project template, +which can generally be found in the platform's `template` directory. Until +icon and splashscreen support is added to the CLI, these image resources +aren't used directly. + +See https://issues.apache.org/jira/browse/CB-5145 diff --git a/web/src-cordova/res/icon/android/icon-36-ldpi.png b/web/src-cordova/res/icon/android/icon-36-ldpi.png new file mode 100644 index 0000000..cd5032a Binary files /dev/null and b/web/src-cordova/res/icon/android/icon-36-ldpi.png differ diff --git a/web/src-cordova/res/icon/android/icon-48-mdpi.png b/web/src-cordova/res/icon/android/icon-48-mdpi.png new file mode 100644 index 0000000..e79c606 Binary files /dev/null and b/web/src-cordova/res/icon/android/icon-48-mdpi.png differ diff --git a/web/src-cordova/res/icon/android/icon-72-hdpi.png b/web/src-cordova/res/icon/android/icon-72-hdpi.png new file mode 100644 index 0000000..4d27634 Binary files /dev/null and b/web/src-cordova/res/icon/android/icon-72-hdpi.png differ diff --git a/web/src-cordova/res/icon/android/icon-96-xhdpi.png b/web/src-cordova/res/icon/android/icon-96-xhdpi.png new file mode 100644 index 0000000..ec7ffbf Binary files /dev/null and b/web/src-cordova/res/icon/android/icon-96-xhdpi.png differ diff --git a/web/src-cordova/res/icon/ios/icon-57-2x.png b/web/src-cordova/res/icon/ios/icon-57-2x.png new file mode 100644 index 0000000..efd9c37 Binary files /dev/null and b/web/src-cordova/res/icon/ios/icon-57-2x.png differ diff --git a/web/src-cordova/res/icon/ios/icon-57.png b/web/src-cordova/res/icon/ios/icon-57.png new file mode 100644 index 0000000..c795fc4 Binary files /dev/null and b/web/src-cordova/res/icon/ios/icon-57.png differ diff --git a/web/src-cordova/res/icon/ios/icon-72-2x.png b/web/src-cordova/res/icon/ios/icon-72-2x.png new file mode 100644 index 0000000..dd819da Binary files /dev/null and b/web/src-cordova/res/icon/ios/icon-72-2x.png differ diff --git a/web/src-cordova/res/icon/ios/icon-72.png b/web/src-cordova/res/icon/ios/icon-72.png new file mode 100644 index 0000000..b1cfde7 Binary files /dev/null and b/web/src-cordova/res/icon/ios/icon-72.png differ diff --git a/web/src-cordova/res/screen/android/screen-hdpi-landscape.png b/web/src-cordova/res/screen/android/screen-hdpi-landscape.png new file mode 100644 index 0000000..a61e2b1 Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-hdpi-landscape.png differ diff --git a/web/src-cordova/res/screen/android/screen-hdpi-portrait.png b/web/src-cordova/res/screen/android/screen-hdpi-portrait.png new file mode 100644 index 0000000..5d6a28a Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-hdpi-portrait.png differ diff --git a/web/src-cordova/res/screen/android/screen-ldpi-landscape.png b/web/src-cordova/res/screen/android/screen-ldpi-landscape.png new file mode 100644 index 0000000..f3934cd Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-ldpi-landscape.png differ diff --git a/web/src-cordova/res/screen/android/screen-ldpi-portrait.png b/web/src-cordova/res/screen/android/screen-ldpi-portrait.png new file mode 100644 index 0000000..65ad163 Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-ldpi-portrait.png differ diff --git a/web/src-cordova/res/screen/android/screen-mdpi-landscape.png b/web/src-cordova/res/screen/android/screen-mdpi-landscape.png new file mode 100644 index 0000000..a1b697c Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-mdpi-landscape.png differ diff --git a/web/src-cordova/res/screen/android/screen-mdpi-portrait.png b/web/src-cordova/res/screen/android/screen-mdpi-portrait.png new file mode 100644 index 0000000..ea15693 Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-mdpi-portrait.png differ diff --git a/web/src-cordova/res/screen/android/screen-xhdpi-landscape.png b/web/src-cordova/res/screen/android/screen-xhdpi-landscape.png new file mode 100644 index 0000000..79f2f09 Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-xhdpi-landscape.png differ diff --git a/web/src-cordova/res/screen/android/screen-xhdpi-portrait.png b/web/src-cordova/res/screen/android/screen-xhdpi-portrait.png new file mode 100644 index 0000000..c2e8042 Binary files /dev/null and b/web/src-cordova/res/screen/android/screen-xhdpi-portrait.png differ diff --git a/web/src-cordova/res/screen/ios/screen-ipad-landscape-2x.png b/web/src-cordova/res/screen/ios/screen-ipad-landscape-2x.png new file mode 100644 index 0000000..0b50ed7 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-ipad-landscape-2x.png differ diff --git a/web/src-cordova/res/screen/ios/screen-ipad-landscape.png b/web/src-cordova/res/screen/ios/screen-ipad-landscape.png new file mode 100644 index 0000000..b2f6019 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-ipad-landscape.png differ diff --git a/web/src-cordova/res/screen/ios/screen-ipad-portrait-2x.png b/web/src-cordova/res/screen/ios/screen-ipad-portrait-2x.png new file mode 100644 index 0000000..cdac6a7 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-ipad-portrait-2x.png differ diff --git a/web/src-cordova/res/screen/ios/screen-ipad-portrait.png b/web/src-cordova/res/screen/ios/screen-ipad-portrait.png new file mode 100644 index 0000000..7f1792c Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-ipad-portrait.png differ diff --git a/web/src-cordova/res/screen/ios/screen-iphone-landscape-2x.png b/web/src-cordova/res/screen/ios/screen-iphone-landscape-2x.png new file mode 100644 index 0000000..0165669 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-iphone-landscape-2x.png differ diff --git a/web/src-cordova/res/screen/ios/screen-iphone-landscape.png b/web/src-cordova/res/screen/ios/screen-iphone-landscape.png new file mode 100644 index 0000000..d154883 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-iphone-landscape.png differ diff --git a/web/src-cordova/res/screen/ios/screen-iphone-portrait-2x.png b/web/src-cordova/res/screen/ios/screen-iphone-portrait-2x.png new file mode 100644 index 0000000..bd24886 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-iphone-portrait-2x.png differ diff --git a/web/src-cordova/res/screen/ios/screen-iphone-portrait-568h-2x.png b/web/src-cordova/res/screen/ios/screen-iphone-portrait-568h-2x.png new file mode 100644 index 0000000..10ed683 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-iphone-portrait-568h-2x.png differ diff --git a/web/src-cordova/res/screen/ios/screen-iphone-portrait.png b/web/src-cordova/res/screen/ios/screen-iphone-portrait.png new file mode 100644 index 0000000..6fcba56 Binary files /dev/null and b/web/src-cordova/res/screen/ios/screen-iphone-portrait.png differ diff --git a/web/src/pages/Chat.vue b/web/src/pages/Chat.vue index 1645290..2875d8f 100644 --- a/web/src/pages/Chat.vue +++ b/web/src/pages/Chat.vue @@ -199,7 +199,7 @@ export default { }) }) - if (this.$q.platform.is.chrome && this.$q.platform.is.android && + if (this.$q.platform.is.chrome && this.$q.platform.is.android && !this.$q.platform.is.cordova && window.matchMedia && !window.matchMedia('(display-mode: standalone)').matches) { this.showPWAPrompt = true } diff --git a/web/src/pages/Error.vue b/web/src/pages/Error.vue index ae07891..f62426f 100644 --- a/web/src/pages/Error.vue +++ b/web/src/pages/Error.vue @@ -2,16 +2,67 @@

+

-

openHAB is offline

-

Sorry, nothing here...(404)

+

{{this.message}}

+
+ + + +
+
{{ $route.meta.reason === 'offline' ? 'Try again' : 'Go back' }} + @click="login" + >{{ initialLogin ? 'Login' : $route.meta.reason === 'offline' ? 'Try again' : 'Go back' }}
+ + diff --git a/web/src/store/actions.js b/web/src/store/actions.js index f42815a..582d159 100644 --- a/web/src/store/actions.js +++ b/web/src/store/actions.js @@ -1,4 +1,5 @@ import axios from 'axios' +import { Platform, LocalStorage } from 'quasar' export const initialLoad = (context, credential) => { let initialRequests = () => { @@ -12,6 +13,24 @@ export const initialLoad = (context, credential) => { }) } + if (Platform.is.cordova) { + const baseURL = LocalStorage.get.item('habot.baseURL') + if (!baseURL) { + return Promise.reject(new Error('Base URL not configured')) + } + axios.defaults.baseURL = baseURL + context.commit('setBaseURL', baseURL) + + let userId = LocalStorage.get.item('habot.credentialUserId') + let password = LocalStorage.get.item('habot.credentialPassword') + if (userId && password) { + credential = { + id: userId, + password: password + } + } + } + if (credential) { axios.defaults.headers.common['Authorization'] = 'Basic ' + btoa(credential.id + ':' + credential.password) context.commit('setUsingStoredCredentials') diff --git a/web/src/store/items/actions.js b/web/src/store/items/actions.js index edf42f7..d1c1e94 100644 --- a/web/src/store/items/actions.js +++ b/web/src/store/items/actions.js @@ -4,7 +4,7 @@ export const someAction = (state) => {} import axios from 'axios' import 'event-source-polyfill' -import { Notify } from 'quasar' +import { Notify, Platform, LocalStorage } from 'quasar' let eventSource let authorizationHeader @@ -28,14 +28,20 @@ export const initialLoad = (context) => { } export const watchEvents = async (context, credential) => { + let baseURL = '' + if (Platform.is.cordova) { + baseURL = LocalStorage.get.item('habot.baseURL') // context.rootState.baseURL + } if (credential || authorizationHeader) { if (!authorizationHeader) { authorizationHeader = 'Basic ' + btoa(credential.id + ':' + credential.password) } - eventSource = new EventSourcePolyfill('/rest/events', // eslint-disable-line no-undef + eventSource = new EventSourcePolyfill(baseURL + '/rest/events', // eslint-disable-line no-undef { headers: { 'Authorization': authorizationHeader } }) + } else if (Platform.is.cordova) { + eventSource = new EventSourcePolyfill(baseURL + '/rest/events') // eslint-disable-line no-undef } else { - eventSource = new EventSource('/rest/events') + eventSource = new EventSource(baseURL + '/rest/events') // eslint-disable-line no-undef } eventSource.onopen = (event) => { diff --git a/web/src/store/mutations.js b/web/src/store/mutations.js index 829206c..63cd4ed 100644 --- a/web/src/store/mutations.js +++ b/web/src/store/mutations.js @@ -6,6 +6,10 @@ export const setUsingStoredCredentials = (state) => { state.usingStoredCredentials = true } +export const setBaseURL = (state, payload) => { + state.baseURL = payload +} + export const setLang = (state, payload) => { state.lang = payload } diff --git a/web/src/store/state.js b/web/src/store/state.js index 378ec9a..2a7edee 100644 --- a/web/src/store/state.js +++ b/web/src/store/state.js @@ -1,5 +1,6 @@ export default { ready: false, lang: 'en', - usingStoredCredentials: false + usingStoredCredentials: false, + baseURL: '' // for cordova }