Skip to content

Commit

Permalink
fix: Optimize backend calls
Browse files Browse the repository at this point in the history
  • Loading branch information
korapp committed Nov 15, 2022
1 parent 0041d5d commit dcc660b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
12 changes: 9 additions & 3 deletions plasmoid/contents/ui/Exec.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ PlasmaCore.DataSource {
}

function exec(cmd) {
return new Promise((resolve, reject) => {
callbacks[cmd] = { resolve, reject }
connectSource(cmd)
if (callbacks[cmd]) {
return callbacks[cmd].promise
}
let resolve, reject, promise = new Promise((_resolve, _reject) => {
resolve = _resolve
reject = _reject
})
callbacks[cmd] = { resolve, reject, promise }
connectSource(cmd)
return promise
}
}
22 changes: 10 additions & 12 deletions plasmoid/contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ PlasmaComponents3.Page {
property alias servers: nordVpnModel.servers
property alias allGroups: nordVpnModel.allGroups
property alias functionalGroups: nordVpnModel.functionalGroups
readonly property bool loadModel: plasmoid.expanded && nordvpn.isServiceRunning

NordVPNModel {
id: nordVpnModel
source: nordvpn
}

Connections {
target: plasmoid
onExpandedChanged: {
if (expanded) {
loadFavorites()
root.onFavoriteConnectionsChanged.connect(loadFavorites)
nordVpnModel.loadData()
} else {
nordVpnModel.clear()
root.onFavoriteConnectionsChanged.disconnect(loadFavorites)
favorites.clear()
}
onLoadModelChanged: {
if (loadModel) {
loadFavorites()
root.onFavoriteConnectionsChanged.connect(loadFavorites)
nordVpnModel.loadData()
} else {
nordVpnModel.clear()
root.onFavoriteConnectionsChanged.disconnect(loadFavorites)
favorites.clear()
}
}

Expand Down
10 changes: 0 additions & 10 deletions plasmoid/contents/ui/NordVPNModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,4 @@ QtObject {
function updateCurrentConnectionItem() {
servers.set(0, getCurrentConnectionItem())
}

Component.onCompleted: {
source.onIsServiceRunningChanged.connect(() => {
if (source.isServiceRunning) {
loadData()
} else {
clear()
}
})
}
}

0 comments on commit dcc660b

Please sign in to comment.