-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from korapp/dev
Dev
- Loading branch information
Showing
12 changed files
with
243 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
pragma Singleton | ||
|
||
import QtQuick 2.0 | ||
|
||
import "components" | ||
|
||
BaseObject { | ||
readonly property var _instances: new Map() | ||
readonly property Component clientComponent: Qt.createComponent("Client.qml") | ||
readonly property bool error: clientComponent.status === Component.Error | ||
readonly property var errorString: clientComponent.errorString | ||
|
||
Secrets { | ||
id: secrets | ||
readonly property var init: new Promise(resolve => onReady.connect(resolve)) | ||
function getToken(url) { | ||
return init.then(() => get(url)) | ||
} | ||
} | ||
|
||
function getClient(consumer, baseUrl) { | ||
if (!(consumer instanceof QtObject) || !baseUrl) return | ||
let instance = _findInstance(baseUrl) | ||
if (!instance) { | ||
instance = _createClient(baseUrl) | ||
} | ||
if (!_instances.has(consumer)) { | ||
consumer.Component.destruction.connect(() => _instances.delete(consumer)) | ||
} | ||
_instances.set(consumer, instance) | ||
return instance | ||
} | ||
|
||
function _createClient(baseUrl) { | ||
const client = clientComponent.createObject(null, { baseUrl }) | ||
secrets.getToken(baseUrl).then(t => client.token = t) | ||
return client | ||
} | ||
|
||
function _findInstance(url) { | ||
return Array.from(_instances.values()).find(i => i.baseUrl === url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.