ai-battery 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,134 +1,134 @@
1
- use framework "AppKit"
2
- use framework "Foundation"
3
- use scripting additions
4
-
5
- property statusItem : missing value
6
- property detailItem : missing value
7
- property detailView : missing value
8
- property refreshTimer : missing value
9
- property titleCommand : ""
10
- property detailCommand : ""
11
- property tooltipCommand : ""
12
- property refreshInterval : 10
13
-
14
- on run argv
15
- if (count of argv) < 2 then error "ai-battery macOS status item requires title and detail commands"
16
-
17
- set titleCommand to item 1 of argv
18
- set detailCommand to item 2 of argv
19
- set tooltipCommand to detailCommand
20
- if (count of argv) is greater than or equal to 4 then
21
- set tooltipCommand to item 3 of argv
22
- try
23
- set refreshInterval to (item 4 of argv) as real
24
- end try
25
- else
26
- if (count of argv) is greater than or equal to 3 then
27
- try
28
- set refreshInterval to (item 3 of argv) as real
29
- end try
30
- end if
31
- end if
32
-
33
- current application's NSApplication's sharedApplication()
34
- current application's NSApp's setActivationPolicy:(current application's NSApplicationActivationPolicyAccessory)
35
-
36
- set statusItem to current application's NSStatusBar's systemStatusBar()'s statusItemWithLength:(current application's NSVariableStatusItemLength)
37
- statusItem's button()'s setTitle:"AI --"
38
- statusItem's button()'s setImagePosition:(current application's NSNoImage)
39
- statusItem's button()'s setToolTip:"AI Battery"
40
-
41
- set statusMenu to current application's NSMenu's alloc()'s initWithTitle:"AI Battery"
42
- set detailItem to current application's NSMenuItem's alloc()'s initWithTitle:"Loading..." action:(missing value) keyEquivalent:""
43
- detailItem's setEnabled:false
44
- statusMenu's addItem:detailItem
45
- statusMenu's addItem:(current application's NSMenuItem's separatorItem())
46
-
47
- set refreshItem to current application's NSMenuItem's alloc()'s initWithTitle:"Refresh" action:"refresh:" keyEquivalent:"r"
48
- refreshItem's setTarget:me
49
- statusMenu's addItem:refreshItem
50
-
51
- set quitItem to current application's NSMenuItem's alloc()'s initWithTitle:"Quit AI Battery" action:"quit:" keyEquivalent:"q"
52
- quitItem's setTarget:me
53
- statusMenu's addItem:quitItem
54
-
55
- statusItem's setMenu:statusMenu
56
- my refresh_(missing value)
57
-
58
- set refreshTimer to current application's NSTimer's scheduledTimerWithTimeInterval:refreshInterval target:me selector:"refresh:" userInfo:(missing value) repeats:true
59
- current application's NSRunLoop's currentRunLoop()'s addTimer:refreshTimer forMode:(current application's NSRunLoopCommonModes)
60
- current application's NSApp's |run|()
61
- end run
62
-
63
- on refresh_(sender)
64
- set titleText to "AI --"
65
- set detailText to "AI Battery unavailable"
66
- set tooltipText to "AI Battery unavailable"
67
- set imagePath to ""
68
- set menuImage to missing value
69
- set detailImage to missing value
70
-
71
- try
72
- set imagePath to (do shell script (titleCommand as text))
73
- end try
74
-
75
- try
76
- set detailText to (do shell script (detailCommand as text))
77
- end try
78
-
79
- try
80
- set tooltipText to (do shell script (tooltipCommand as text))
81
- end try
82
-
83
- if imagePath is "" then set imagePath to "AI --"
84
- if detailText is "" then set detailText to "AI Battery unavailable"
85
- if tooltipText is "" then set tooltipText to detailText
86
-
87
- try
88
- set menuImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
89
- end try
90
-
91
- try
92
- set detailImage to current application's NSImage's alloc()'s initWithContentsOfFile:detailText
93
- end try
94
-
95
- if menuImage is not missing value then
96
- set imageSize to menuImage's |size|()
97
- statusItem's setLength:(width of imageSize)
98
- menuImage's setTemplate:false
99
- statusItem's button()'s setImage:menuImage
100
- statusItem's button()'s setImageScaling:(current application's NSImageScaleProportionallyDown)
101
- statusItem's button()'s setImagePosition:(current application's NSImageOnly)
102
- statusItem's button()'s setTitle:""
103
- else
104
- set titleText to imagePath
105
- if titleText is "" then set titleText to "AI --"
106
- statusItem's setLength:(current application's NSVariableStatusItemLength)
107
- statusItem's button()'s setImage:(missing value)
108
- statusItem's button()'s setImagePosition:(current application's NSNoImage)
109
- statusItem's button()'s setTitle:titleText
110
- end if
111
-
112
- if detailImage is not missing value then
113
- set detailSize to detailImage's |size|()
114
- set detailFrame to current application's NSMakeRect(0, 0, (width of detailSize), (height of detailSize))
115
- set detailView to current application's NSImageView's alloc()'s initWithFrame:detailFrame
116
- detailView's setImage:detailImage
117
- detailView's setImageScaling:(current application's NSImageScaleNone)
118
- detailItem's setView:detailView
119
- detailItem's setTitle:""
120
- else
121
- detailItem's setView:(missing value)
122
- detailItem's setTitle:detailText
123
- end if
124
-
125
- statusItem's button()'s setToolTip:tooltipText
126
- end refresh_
127
-
128
- on quit_(sender)
129
- try
130
- refreshTimer's invalidate()
131
- end try
132
- current application's NSStatusBar's systemStatusBar()'s removeStatusItem:statusItem
133
- current application's NSApp's terminate:me
134
- end quit_
1
+ use framework "AppKit"
2
+ use framework "Foundation"
3
+ use scripting additions
4
+
5
+ property statusItem : missing value
6
+ property detailItem : missing value
7
+ property detailView : missing value
8
+ property refreshTimer : missing value
9
+ property titleCommand : ""
10
+ property detailCommand : ""
11
+ property tooltipCommand : ""
12
+ property refreshInterval : 10
13
+
14
+ on run argv
15
+ if (count of argv) < 2 then error "ai-battery macOS status item requires title and detail commands"
16
+
17
+ set titleCommand to item 1 of argv
18
+ set detailCommand to item 2 of argv
19
+ set tooltipCommand to detailCommand
20
+ if (count of argv) is greater than or equal to 4 then
21
+ set tooltipCommand to item 3 of argv
22
+ try
23
+ set refreshInterval to (item 4 of argv) as real
24
+ end try
25
+ else
26
+ if (count of argv) is greater than or equal to 3 then
27
+ try
28
+ set refreshInterval to (item 3 of argv) as real
29
+ end try
30
+ end if
31
+ end if
32
+
33
+ current application's NSApplication's sharedApplication()
34
+ current application's NSApp's setActivationPolicy:(current application's NSApplicationActivationPolicyAccessory)
35
+
36
+ set statusItem to current application's NSStatusBar's systemStatusBar()'s statusItemWithLength:(current application's NSVariableStatusItemLength)
37
+ statusItem's button()'s setTitle:"AI --"
38
+ statusItem's button()'s setImagePosition:(current application's NSNoImage)
39
+ statusItem's button()'s setToolTip:"AI Battery"
40
+
41
+ set statusMenu to current application's NSMenu's alloc()'s initWithTitle:"AI Battery"
42
+ set detailItem to current application's NSMenuItem's alloc()'s initWithTitle:"Loading..." action:(missing value) keyEquivalent:""
43
+ detailItem's setEnabled:false
44
+ statusMenu's addItem:detailItem
45
+ statusMenu's addItem:(current application's NSMenuItem's separatorItem())
46
+
47
+ set refreshItem to current application's NSMenuItem's alloc()'s initWithTitle:"Refresh" action:"refresh:" keyEquivalent:"r"
48
+ refreshItem's setTarget:me
49
+ statusMenu's addItem:refreshItem
50
+
51
+ set quitItem to current application's NSMenuItem's alloc()'s initWithTitle:"Quit AI Battery" action:"quit:" keyEquivalent:"q"
52
+ quitItem's setTarget:me
53
+ statusMenu's addItem:quitItem
54
+
55
+ statusItem's setMenu:statusMenu
56
+ my refresh_(missing value)
57
+
58
+ set refreshTimer to current application's NSTimer's scheduledTimerWithTimeInterval:refreshInterval target:me selector:"refresh:" userInfo:(missing value) repeats:true
59
+ current application's NSRunLoop's currentRunLoop()'s addTimer:refreshTimer forMode:(current application's NSRunLoopCommonModes)
60
+ current application's NSApp's |run|()
61
+ end run
62
+
63
+ on refresh_(sender)
64
+ set titleText to "AI --"
65
+ set detailText to "AI Battery unavailable"
66
+ set tooltipText to "AI Battery unavailable"
67
+ set imagePath to ""
68
+ set menuImage to missing value
69
+ set detailImage to missing value
70
+
71
+ try
72
+ set imagePath to (do shell script (titleCommand as text))
73
+ end try
74
+
75
+ try
76
+ set detailText to (do shell script (detailCommand as text))
77
+ end try
78
+
79
+ try
80
+ set tooltipText to (do shell script (tooltipCommand as text))
81
+ end try
82
+
83
+ if imagePath is "" then set imagePath to "AI --"
84
+ if detailText is "" then set detailText to "AI Battery unavailable"
85
+ if tooltipText is "" then set tooltipText to detailText
86
+
87
+ try
88
+ set menuImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
89
+ end try
90
+
91
+ try
92
+ set detailImage to current application's NSImage's alloc()'s initWithContentsOfFile:detailText
93
+ end try
94
+
95
+ if menuImage is not missing value then
96
+ set imageSize to menuImage's |size|()
97
+ statusItem's setLength:(width of imageSize)
98
+ menuImage's setTemplate:false
99
+ statusItem's button()'s setImage:menuImage
100
+ statusItem's button()'s setImageScaling:(current application's NSImageScaleProportionallyDown)
101
+ statusItem's button()'s setImagePosition:(current application's NSImageOnly)
102
+ statusItem's button()'s setTitle:""
103
+ else
104
+ set titleText to imagePath
105
+ if titleText is "" then set titleText to "AI --"
106
+ statusItem's setLength:(current application's NSVariableStatusItemLength)
107
+ statusItem's button()'s setImage:(missing value)
108
+ statusItem's button()'s setImagePosition:(current application's NSNoImage)
109
+ statusItem's button()'s setTitle:titleText
110
+ end if
111
+
112
+ if detailImage is not missing value then
113
+ set detailSize to detailImage's |size|()
114
+ set detailFrame to current application's NSMakeRect(0, 0, (width of detailSize), (height of detailSize))
115
+ set detailView to current application's NSImageView's alloc()'s initWithFrame:detailFrame
116
+ detailView's setImage:detailImage
117
+ detailView's setImageScaling:(current application's NSImageScaleNone)
118
+ detailItem's setView:detailView
119
+ detailItem's setTitle:""
120
+ else
121
+ detailItem's setView:(missing value)
122
+ detailItem's setTitle:detailText
123
+ end if
124
+
125
+ statusItem's button()'s setToolTip:tooltipText
126
+ end refresh_
127
+
128
+ on quit_(sender)
129
+ try
130
+ refreshTimer's invalidate()
131
+ end try
132
+ current application's NSStatusBar's systemStatusBar()'s removeStatusItem:statusItem
133
+ current application's NSApp's terminate:me
134
+ end quit_