Skip to content

Commit

Permalink
Add Application matching
Browse files Browse the repository at this point in the history
* Add class and onCreate matching
* Add OneSignal init lines
  • Loading branch information
Jeasmine committed Aug 5, 2021
1 parent 35b6f77 commit c4bd4c8
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions lib/osproject_android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ def add_sdk!

# add OS API key to Application class
if self.lang == "java"
_insert_lines(dir + '/' + app_class_location,
"import [a-zA-Z.]+;",
"import com.onesignal.OneSignal;")
_insert_lines(dir + '/' + app_class_location,
"public class [a-zA-Z\s]+{",
"\s\s\s\sprivate static final String ONESIGNAL_APP_ID = \"" + self.os_app_id + "\";\n")
_sub_file(dir + '/' + app_class_location,
/^(import \w*;)/,
'\1' + "import com.onesignal.OneSignal;")
_sub_file(dir + '/' + app_class_location,
/(\w+ extends Application {)/,
'\1' + 'private static final String ONESIGNAL_APP_ID = "' + self.os_app_id + '";')
_insert_lines(dir + '/' + app_class_location,
'super\.onCreate\(\);?', [
"// Enable verbose OneSignal logging to debug issues if needed.",
"// It is recommended you remove this after validating your implementation.",
"OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);",
"// OneSignal Initialization",
"OneSignal.initWithContext(this);",
"OneSignal.setAppId(ONESIGNAL_APP_ID);"
])
/super.onCreate\(\);\s/,
"super.onCreate();
// Enable verbose OneSignal logging to debug issues if needed.
// It is recommended you remove this after validating your implementation.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Initialization
OneSignal.initWithContext(this);
OneSignal.setAppId(ONESIGNAL_APP_ID);\n")
elsif self.lang == "kotlin"
_sub_file(dir + '/' + app_class_location,
/^(import \w*;)/,
'\1' + 'import com.onesignal.OneSignal')
_sub_file(dir + '/' + app_class_location,
/^(import \w*;)/,
'\1' + 'const val ONESIGNAL_APP_ID = "' + self.os_app_id + '"')
_insert_lines(dir + '/' + app_class_location,
Regexp.quote('super.onCreate()'), [
"// Enable verbose OneSignal logging to debug issues if needed.",
"// It is recommended you remove this after validating your implementation.",
"OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)",
"// OneSignal Initialization",
"OneSignal.initWithContext(this)",
"OneSignal.setAppId(ONESIGNAL_APP_ID)"
])
"import [a-zA-Z.]+",
'import com.onesignal.OneSignal')
_insert_lines(dir + '/' + app_class_location,
"class [a-zA-Z\s:()]+{",
"\s\s\s\sval ONESIGNAL_APP_ID = \"" + self.os_app_id + "\"\n")
_sub_file(dir + '/' + app_class_location,
/super.onCreate\(\)\s/,
"super.onCreate()
// Enable verbose OneSignal logging to debug issues if needed.
// It is recommended you remove this after validating your implementation.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)
// OneSignal Initialization
OneSignal.initWithContext(this)
OneSignal.setAppId(ONESIGNAL_APP_ID)\n")
else
raise "Don't know to handle #{lang}"
end
Expand Down

0 comments on commit c4bd4c8

Please sign in to comment.