mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-27 06:14:58 +03:00
Shim Array methods added after current Qt version in Ubuntu
This commit is contained in:
parent
610032869f
commit
d0d3fde9b2
@ -16,7 +16,7 @@ Item {
|
||||
Keys.onUpPressed: goUp()
|
||||
|
||||
function findSelectedIndex() {
|
||||
return credentials.findIndex(function(entry) {
|
||||
return util.findIndex(credentials, function(entry) {
|
||||
return entry.credential.key === selectedKey
|
||||
}) || null
|
||||
}
|
||||
|
44
qml/Util.qml
Normal file
44
qml/Util.qml
Normal file
@ -0,0 +1,44 @@
|
||||
import QtQuick 2.5
|
||||
|
||||
Item {
|
||||
visible: false
|
||||
|
||||
/*
|
||||
* Quick and dirty shim for Array.find added in Qt 5.9
|
||||
*
|
||||
* @param items: array
|
||||
* @param predicate: function(any) => Boolean
|
||||
* @return The first `item` in `arr` that matches the `predicate`, or
|
||||
* `undefined` if none matches
|
||||
*/
|
||||
function find(items, predicate) {
|
||||
if (items) {
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
if (predicate(items[i])) {
|
||||
return items[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/*
|
||||
* Quick and dirty shim for Array.findIndex added in Qt 5.9
|
||||
*
|
||||
* @param items: array
|
||||
* @param predicate: function(any) => Boolean
|
||||
* @return The index of the first `item` in `arr` that matches the
|
||||
* `predicate`, or `undefined` if none matches
|
||||
*/
|
||||
function findIndex(items, predicate) {
|
||||
if (items) {
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
if (predicate(items[i])) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
}
|
@ -371,6 +371,10 @@ ApplicationWindow {
|
||||
id: noQr
|
||||
}
|
||||
|
||||
Util {
|
||||
id: util
|
||||
}
|
||||
|
||||
function selectCredential(entry) {
|
||||
selectedKey = entry.credential.key
|
||||
}
|
||||
@ -380,7 +384,7 @@ ApplicationWindow {
|
||||
}
|
||||
|
||||
function getSelected() {
|
||||
return credentials.find(function(entry) {
|
||||
return util.find(credentials, function(entry) {
|
||||
return isSelected(entry.credential)
|
||||
}) || null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user