intro: explain using the javascript Date api over the date command
This commit is contained in:
parent
adb293de95
commit
97b2c23f9f
content/docs/configuration
|
@ -750,7 +750,7 @@ import QtQuick
|
||||||
|
|
||||||
// your singletons should always have Singleton as the type
|
// your singletons should always have Singleton as the type
|
||||||
Singleton {
|
Singleton {
|
||||||
property string time;
|
property string time
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: dateProc
|
id: dateProc
|
||||||
|
@ -817,3 +817,31 @@ Scope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## JavaScript APIs
|
||||||
|
|
||||||
|
In addition to calling external processes, a [limited set of javascript interfaces] is available.
|
||||||
|
We can use this to improve our clock by using the [Date API] instead of calling `date`.
|
||||||
|
|
||||||
|
[limited set of javascript interfaces]: https://doc.qt.io/qt-6/qtqml-javascript-functionlist.html
|
||||||
|
[Date API]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
||||||
|
|
||||||
|
```qml {filename="Time.qml"}
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Singleton {
|
||||||
|
property var date: new Date()
|
||||||
|
property string time: date.toLocaleString(Qt.locale())
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 1000
|
||||||
|
running: true
|
||||||
|
repeat: true
|
||||||
|
onTriggered: date = new Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -15,7 +15,7 @@ Notes:
|
||||||
- Semicolons are permitted basically everywhere, and recommended in
|
- Semicolons are permitted basically everywhere, and recommended in
|
||||||
functions and expressions.
|
functions and expressions.
|
||||||
- While types can often be elided, we recommend you use them where
|
- While types can often be elided, we recommend you use them where
|
||||||
possible to catch proplems early instead of running into them unexpectedly layer on.
|
possible to catch problems early instead of running into them unexpectedly later on.
|
||||||
|
|
||||||
```qml
|
```qml
|
||||||
// QML Import statement
|
// QML Import statement
|
||||||
|
|
Loading…
Reference in a new issue