-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.qml
314 lines (246 loc) · 7.28 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import QtQuick
import QtQuick.Window
import QtQuick.Layouts 1.12
import Qt.labs.platform
import Qt.labs.settings
import "./components/ui" as Components
import "./pages" as Pages
import Yandex 1.0
Window {
id: window
title: "YandexTrayApp"
width: 300
height: 365
visible: false
flags: Qt.FramelessWindowHint | Qt.Popup
color: "transparent"
property bool canShowPopup: true
Timer {
id: doubleClickTimer
interval: desktopFeatures.getDoubleclickTime()
running: false
repeat: false
onTriggered: {
window.canShowPopup = true;
}
}
function show_window() {
if (window.canShowPopup) {
window.show();
window.raise();
window.requestActivate();
}
}
function hide_window() {
window.hide();
window.canShowPopup = false;
doubleClickTimer.start();
}
DevicesModel {
id: devicesModel
}
YandexHome {
id: yandexHome
Component.onCompleted: {
loadDevices();
}
}
FontLoader {
id: textFont
source: "qrc:/assets/Montserrat-SemiBold.ttf"
}
Rectangle {
anchors.fill: parent
color: "#ecf9e6"
radius: 3
}
Component.onCompleted: {
yandexAccount.askInfo();
}
onActiveFocusItemChanged: {
if (!activeFocusItem) {
hide_window();
}
}
onVisibleChanged: {
yandexHome.setWatcherState(visible);
}
Connections {
target: yandexAccount
function onInfoReady() {
home.setAccountData(
yandexAccount.getName(),
"https://avatars.yandex.net/get-yapic/" + yandexAccount.getAvatarId() + "/islands-middle"
);
stack.currentIndex = 2;
}
function onError(errorCode) {
switch (errorCode) {
case 2:
stack.currentIndex = 3;
break;
case 1:
stack.currentIndex = 1;
break;
case 0:
stack.currentIndex = 3;
break;
}
}
}
Connections {
target: yandexOAuth
function onGranted() {
yandexOAuth.saveToken(yandexOAuth.getToken());
yandexHome.loadDevices();
yandexAccount.askInfo();
stack.currentIndex = 2;
}
}
Connections {
target: updater
function onUpdateAvaliable(data) {
trayIcon.showMessage("Yandex Home Widgets", "Доступна новая версия приложения!");
}
}
SystemTrayIcon {
id: trayIcon
visible: true
icon.name: "Yandex Home Widgets"
icon.source: "qrc:/assets/icon.png"
onActivated: function(reason) {
if (reason !== SystemTrayIcon.Trigger)
return;
const position = desktopFeatures.getTaskbarPosition();
console.log(geometry.x, geometry.y)
const x0 = position.x;
const y0 = position.y;
const w = position.width;
const h = position.height;
if (y0 > 0 && x0 === 0) {
window.x = geometry.x - window.width / 2 + geometry.width;
window.y = geometry.y - window.height - 5;
} else if (y0 === 0 && x0 === 0 && w < h) {
window.x = geometry.x + w + 5;
window.y = geometry.y - window.height / 2 - geometry.height;
} else if (y0 === 0 && x0 === 0 && h < w) {
window.x = geometry.x - window.width / 2 + geometry.width;
window.y = geometry.y + 15 + h;
} else {
window.x = geometry.x - window.width - 15;
window.y = geometry.y - window.height / 2 - geometry.height;
}
if (!window.visible) {
show_window();
} else {
hide_window();
}
}
menu: Menu {
MenuItem {
text: qsTr("Закрыть приложение")
onTriggered: Qt.quit()
}
MenuItem {
text: qsTr("Github")
onTriggered: Qt.openUrlExternally("https://github.com/Yagodnik/YandexHomeWidgets")
}
// MenuItem {
// text: qsTr("О приложении")
// onTriggered: myDialog.show()
// }
}
onMessageClicked: function() {
// Show dialog about new version maybe
Qt.openUrlExternally("https://github.com/Yagodnik/YandexHomeWidgets");
}
}
Window {
id: myDialog
visible: false
width: 200
height: 120
flags: Qt.FramelessWindowHint | Qt.Popup
color: "transparent"
x: 100
y: 100
Rectangle {
anchors.fill: parent
color: "#ecf9e6"
radius: 3
}
Text {
id: title
height: 20
color: "#1d1e1d"
anchors.bottom: version.top
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.family: textFont.font.family
font.weight: textFont.font.weight
font.pixelSize: 14
text: qsTr("Yandex Home Widgets")
}
Text {
id: version
height: 20
color: "#1d1e1d"
anchors.bottom: link.top
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.family: textFont.font.family
font.weight: textFont.font.weight
font.pixelSize: 12
text: "Версия " + updater.getCurrentVersion()
}
Text {
id: link
height: 20
color: "#1d1e1d"
anchors.bottom: closeButton.top
anchors.bottomMargin: 3
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.family: textFont.font.family
font.weight: textFont.font.weight
font.pixelSize: 12
text: '<a href="https://github.com/Yagodnik/YandexHomeWidgets">GitHub</a>'
onLinkActivated: Qt.openUrlExternally("https://github.com/Yagodnik/YandexHomeWidgets")
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: Qt.PointingHandCursor
}
}
Components.Button {
id: closeButton
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
width: 70
height: 28
text: "Hide"
onClicked: {
myDialog.hide();
}
}
}
StackLayout {
id: stack
anchors.fill: parent
anchors.margins: 3
currentIndex: 0
Pages.Loading {
id: loading
}
Pages.Login {
id: login
}
Pages.Home {
id: home
}
Pages.Error {
id: error
}
}
}