-
Notifications
You must be signed in to change notification settings - Fork 208
/
app.rb
106 lines (85 loc) · 2.49 KB
/
app.rb
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
# Provides a module to store global states
#
module BubbleWrap
module App
include BubbleWrap::Deprecated
module_function
# Returns the application's document directory path where users might be able to upload content.
# @return [String] the path to the document directory
def documents_path
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
end
# Returns the application resource path where resource located
# @return [String] the application main bundle resource path
def resources_path
NSBundle.mainBundle.resourcePath
end
# Returns the default notification center
# @return [NSNotificationCenter] the default notification center
def notification_center
NSNotificationCenter.defaultCenter
end
def user_cache
NSUserDefaults.standardUserDefaults
end
deprecated :user_cache, "2.0.0"
# Executes a block after a certain delay
# Usage example:
# App.run_after(0.5) { p "It's #{Time.now}" }
def run_after(delay,&block)
NSTimer.scheduledTimerWithTimeInterval( delay,
target: block,
selector: "call:",
userInfo: nil,
repeats: false)
end
@states = {}
def states
@states
end
def info_plist
NSBundle.mainBundle.infoDictionary
end
def name
info_plist['CFBundleDisplayName']
end
def identifier
NSBundle.mainBundle.bundleIdentifier
end
def version
info_plist['CFBundleVersion']
end
def short_version
info_plist['CFBundleShortVersionString']
end
# @return [NSLocale] locale of user settings
def current_locale
languages = NSLocale.preferredLanguages
if languages.count > 0
return NSLocale.alloc.initWithLocaleIdentifier(languages.first)
else
return NSLocale.currentLocale
end
end
# the current application environment : development, test, release
def environment
RUBYMOTION_ENV
end
def development?
environment == 'development'
end
def test?
environment == 'test'
end
def release?
environment == 'release'
end
def osx?
Kernel.const_defined?(:NSApplication)
end
def ios?
Kernel.const_defined?(:UIApplication)
end
end
end
::App = BubbleWrap::App unless defined?(::App)