This repository was archived by the owner on Aug 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.pb
More file actions
181 lines (164 loc) · 6.55 KB
/
main.pb
File metadata and controls
181 lines (164 loc) · 6.55 KB
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
EnableExplicit
IncludeFile "megaplan.pb"
IncludeFile "const.pb"
IncludeFile "../pb-osx-notifications/notifications.pbi"
notifications::init()
Define app = CocoaMessage(0,0,"NSApplication sharedApplication")
Define statusBar.i,statusItem.i,alerts.i,megaplanState.b
Define connectThread.i,checkThread.i,updateThread.i
Define megaplanAccess.s,megaplanSecret.s
Define megaplanLastMsgId.i
Define delegate.i,delegateClass.i
Define notification.notifications::osxNotification
Define updateVer.s = #myVer
Define updateDetails.s
Define shouldMarkAllAsRead.b = #False
IncludeFile "helpers.pb"
IncludeFile "proc.pb"
CompilerIf Not #PB_Compiler_Debugger
OnErrorCall(@errorHandler())
CompilerEndIf
OpenWindow(#wnd,#PB_Ignore,#PB_Ignore,300,220,#myName,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StickyWindow(#wnd,#True)
CocoaMessage(0,CocoaMessage(0,WindowID(#wnd),"standardWindowButton:",#NSWindowButtonMinimize),"setHidden:",#YES)
CocoaMessage(0,CocoaMessage(0,WindowID(#wnd),"standardWindowButton:",#NSWindowButtonMaximize),"setHidden:",#YES)
FrameGadget(#gadFrameConnection,10,10,280,110,"Connection")
StringGadget(#gadHost,20,33,260,25,"")
CocoaMessage(0,CocoaMessage(0,GadgetID(#gadHost),"cell"),"setPlaceholderString:$",@"Megaplan hostname")
CocoaMessage(0,GadgetID(#gadHost),"setBezelStyle:",1)
CocoaMessage(0,GadgetID(#gadHost),"setFocusRingType:",1)
StringGadget(#gadLogin,20,58,260,25,"")
CocoaMessage(0,CocoaMessage(0,GadgetID(#gadLogin),"cell"),"setPlaceholderString:$",@"Login")
CocoaMessage(0,GadgetID(#gadLogin),"setBezelStyle:",1)
CocoaMessage(0,GadgetID(#gadLogin),"setFocusRingType:",1)
StringGadget(#gadPassword,20,83,260,25,"",#PB_String_Password)
CocoaMessage(0,CocoaMessage(0,GadgetID(#gadPassword),"cell"),"setPlaceholderString:$",@"Password")
CocoaMessage(0,GadgetID(#gadPassword),"setBezelStyle:",1)
CocoaMessage(0,GadgetID(#gadPassword),"setFocusRingType:",1)
FrameGadget(#gadFrameSettings,10,125,280,90,"Settings")
CheckBoxGadget(#gadEnableLoginItem,20,145,180,20,"Start on login")
CocoaMessage(0,GadgetID(#gadEnableLoginItem),"setFocusRingType:",1)
CheckBoxGadget(#gadEnableUpdatesCheck,20,165,180,20,"Check for updates")
CocoaMessage(0,GadgetID(#gadEnableUpdatesCheck),"setFocusRingType:",1)
CheckBoxGadget(#gadEnableStatusBar,20,185,180,20,"Enable status bar icon")
CocoaMessage(0,GadgetID(#gadEnableStatusBar),"setFocusRingType:",1)
HideGadget(#gadEnableStatusBar,#True)
CheckBoxGadget(#gadEnableNotifications,20,185,180,20,"Enable notifications")
CocoaMessage(0,GadgetID(#gadEnableNotifications),"setFocusRingType:",1)
initResources()
settings()
If GetGadgetState(#gadEnableStatusBar)
advancedStatusBar()
EndIf
updateStatusIcon()
SetActiveGadget(-1)
If Len(GetGadgetText(#gadHost)) And Len(GetGadgetText(#gadLogin)) And Len(GetGadgetText(#gadPassword))
hideApp(#True)
PostEvent(#eventDisconnected)
EndIf
updateThread = CreateThread(@checkUpdateAsync(),#updateCheckInterval)
If Not InitNetwork()
MessageRequester(#myName,#errorMsg + "network initialisation")
End 1
EndIf
Repeat
Define ev = WaitWindowEvent()
Define res.i
Select ev
Case #PB_Event_Gadget
Select EventGadget()
; Case #gadEnableStatusBar
; advancedStatusBar()
; settings(#True)
Case #gadEnableLoginItem
If GetGadgetState(#gadEnableLoginItem) = #PB_Checkbox_Checked
If Not enableLoginItem(#myID,#True)
SetGadgetState(#gadEnableLoginItem,#PB_Checkbox_Unchecked)
MessageRequester(#myName,#errorMsg + "applying autostart")
Else
settings(#True)
EndIf
Else
If Not enableLoginItem(#myID,#False)
SetGadgetState(#gadEnableLoginItem,#PB_Checkbox_Checked)
MessageRequester(#myName,#errorMsg + "disabling autostart")
Else
settings(#True)
EndIf
EndIf
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #menuMegaplan
If Len(GetGadgetText(#gadHost))
RunProgram("open",~"\"http://" + GetGadgetText(#gadHost) + ~"\"","")
Else
SetActiveGadget(#gadHost)
hideApp(#False)
EndIf
Case #menuMarkAllAsRead
shouldMarkAllAsRead = #True
PostEvent(#eventAlert,#PB_Ignore,#PB_Ignore,#PB_Ignore,0)
Case #menuPrefs
softReset()
SetActiveGadget(-1)
hideApp(#False)
Case #menuAbout
hideApp(#False)
MessageRequester(#myName + " " + #myVer,~"\ncreated by deseven, 2016")
hideApp(#True)
Case #menuQuit
Break
EndSelect
Case #eventDisconnected
softReset()
connectThread = CreateThread(@megaplanConnect(),#PB_Ignore)
Case #eventConnected
megaplanState = #megaplanConnected
updateStatusIcon()
checkThread = CreateThread(@megaplanCheck(),#megaplanCheckInterval)
Case #eventAlert
If alerts <> EventData()
alerts = EventData()
updateStatusIcon()
EndIf
Case #eventWrongCredentials
softReset()
SetActiveGadget(#gadHost)
hideApp(#False)
MessageRequester(#myName,#invalidCredentials)
Case #eventNotification
If EventData()
RunProgram("open",~"\"http://" + GetGadgetText(#gadHost) + "/task/" + Str(EventData()) + ~"/card/\"","")
Else
RunProgram("open",~"\"http://" + GetGadgetText(#gadHost) + ~"/BumsCommon/Activity/feed.html\"","")
EndIf
Case #eventUpdateArrived
hideApp(#False)
If MessageRequester(#myName + ", new version is available!","Found new version " + updateVer + ~"\n\nChangelog:\n" + updateDetails + ~"\n\nDo you want to download it?",#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
RunProgram("open",~"\"" + #updateDownloadUrl + ~"\"","")
End
EndIf
hideApp(#True)
Case #PB_Event_CloseWindow
If GetGadgetState(#gadEnableStatusBar) = #PB_Checkbox_Unchecked And GetGadgetState(#gadEnableNotifications) = #PB_Checkbox_Unchecked
If MessageRequester(#myName,#disabledWarn,#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
hideApp(#True)
settings(#True)
PostEvent(#eventDisconnected)
EndIf
Else
hideApp(#True)
settings(#True)
PostEvent(#eventDisconnected)
EndIf
EndSelect
ForEver
If IsThread(updateThread) : KillThread(updateThread) : EndIf
If IsThread(connectThread) : KillThread(connectThread) : EndIf
If IsThread(checkThread) : KillThread(checkThread) : EndIf
; IDE Options = PureBasic 5.71 LTS (MacOS X - x64)
; CursorPosition = 24
; Folding = -
; EnableXP
; EnableUnicode