Skip to content

Commit

Permalink
Added configuration for openhab.host and openhab.path
Browse files Browse the repository at this point in the history
Optimized URL handling using 'path' and configured host and port
  • Loading branch information
Dennis Gieseler committed Jun 21, 2017
1 parent 5f646cd commit c00af43
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 68 deletions.
117 changes: 69 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,60 +27,81 @@
"contributes": {
"menus": {
"editor/title": [{
"when": "resourceLangId == openhab",
"command": "openhab.basicUI",
"group": "navigation"
}]
"when": "resourceLangId == openhab",
"command": "openhab.basicUI",
"group": "navigation"
}]
},
"keybindings": [{
"when": "resourceLangId == openhab",
"command": "openhab.basicUI",
"key": "ctrl+alt+o",
"mac": "cmd+alt+o"
}, {
"when": "resourceLangId == openhab",
"command": "openhab.searchDocs",
"key": "shift+alt+o"
}],
"when": "resourceLangId == openhab",
"command": "openhab.basicUI",
"key": "ctrl+alt+o",
"mac": "cmd+alt+o"
}, {
"when": "resourceLangId == openhab",
"command": "openhab.searchDocs",
"key": "shift+alt+o"
}],
"commands": [{
"command": "openhab.searchDocs",
"title": "openHAB: Search in Docs"
}, {
"command": "openhab.searchCommunity",
"title": "openHAB: Search in Community Forum"
}, {
"command": "openhab.basicUI",
"title": "openHAB: Open Basic UI",
"icon": {
"light": "./images/oh_color.svg",
"dark": "./images/oh.svg"
"command": "openhab.searchDocs",
"title": "openHAB: Search in Docs"
}, {
"command": "openhab.searchCommunity",
"title": "openHAB: Search in Community Forum"
}, {
"command": "openhab.basicUI",
"title": "openHAB: Open Basic UI",
"icon": {
"light": "./images/oh_color.svg",
"dark": "./images/oh.svg"
}
}],
"configuration": {
"type": "object",
"title": "openHAB Configuration",
"properties": {
"openhab.host": {
"type": [
"string"
],
"default": "openhabianpi",
"description": "Specifies the URL for the openHAB preview. (Use 'localhost' when developing locally)"
},
"openhab.port": {
"type": [
"string",
"null"
],
"default": "8080",
"description": "Specifies the port for the openHAB preview."
}
}
}],
},
"languages": [{
"id": "openhab",
"aliases": ["openHAB"],
"extensions": [
".rules",
".script",
".items",
".sitemap",
".things",
".persist"
],
"configuration": "./language-configuration.json"
}],
"id": "openhab",
"aliases": ["openHAB"],
"extensions": [
".rules",
".script",
".items",
".sitemap",
".things",
".persist"
],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "openhab",
"scopeName": "source.openhab",
"path": "./syntaxes/openhab.tmLanguage.json"
}],
"language": "openhab",
"scopeName": "source.openhab",
"path": "./syntaxes/openhab.tmLanguage.json"
}],
"snippets": [{
"language": "openhab",
"path": "./snippets/openhabrules.json"
}, {
"language": "openhab",
"path": "./snippets/openhab.json"
}]
"language": "openhab",
"path": "./snippets/openhabrules.json"
}, {
"language": "openhab",
"path": "./snippets/openhab.json"
}]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
Expand All @@ -99,4 +120,4 @@
"@types/lodash": "^4.14.58",
"lodash": "^4.17.4"
}
}
}
26 changes: 6 additions & 20 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import _ = require('lodash')
async function init(context: ExtensionContext, disposables: Disposable[]): Promise<void> {
let ui = new OpenHABContentProvider()
let registration = workspace.registerTextDocumentContentProvider(SCHEME, ui)

const path = require('path');

const openHtml = (uri: Uri, title) => {
return commands.executeCommand('vscode.previewHtml', uri, ViewColumn.Two, title)
Expand All @@ -49,33 +51,17 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
openHtml(encodeOpenHABUri(query), title)

let basicUI = commands.registerCommand('openhab.basicUI', () => {
let config = workspace.getConfiguration('openhab')
let editor = window.activeTextEditor
if (!editor) {
window.showInformationMessage('No editor is active')
return
}

const getHostName = () => {
if ( os === 'win32' && absolutePath.slice(0,2) === '\\\\') {
let filePath = absolutePath.split('\\')
return _.compact(filePath)[0]
} else if ( os === 'darwin' && absolutePath.slice(0,9) === '/Volumes/') {
return 'openhabianpi.local'
} else {
return 'localhost'
}
}

const getFileName = () => {
return (os === 'win32') ? absolutePath.split('\\').pop() : absolutePath.split('/').pop()
}

let os = process.platform
let absolutePath = editor.document.fileName
let hostname = getHostName()
let fileName = getFileName()
let address = hostname + ':8080'

let fileName = path.basename(absolutePath)
let address = config.port ? config.host + ':' + config.port : config.host

let params = {
hostname: address
};
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"lib": [
"es6"
],
"types":[
"node"
],
"sourceMap": true,
"rootDir": "."
},
Expand Down

0 comments on commit c00af43

Please sign in to comment.