<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
  id="cordova-plugin-insomnia-xjp"
  version="0.0.53">

  <name>No Sleep plugin</name>

  <js-module src="www/insomnia.js" name="Insomnia">
    <clobbers target="plugins.insomnia" />
  </js-module>

  <platform name="android">

    <framework src="com.android.support:support-v4:26.1.0" />

    <config-file target="config.xml" parent="/*">
      <feature name="Insomnia">
        <param name="android-package" value="com.commontime.cordova.plugins.insomnia.Insomnia" />
        <param name="onload" value="true"/>
      </feature>
    </config-file>

    <preference name="WAKELOCK" default="false" />
    <preference name="BATTOP" default="false" />
    <preference name="FGSERVICEENABLED" default="false" />
    <preference name="FGSERVICEMAIN" default="Foreground Service" />
    <preference name="FGSERVICESUB" default="Preventing App Stopping" />
    <preference name="APPRESTARTSERVICE" default="false" />
    <preference name="STARTONBOOT" default="false" />
    <preference name="BACKGROUNDALARM" default="false" />
      
    <config-file target="AndroidManifest.xml" parent="/manifest/application">
        <meta-data android:name="acquireWakeLockOnStart" android:value="$WAKELOCK" />
        <meta-data android:name="requestStopBatteryOptimizationOnStartup" android:value="$BATTOP" />
        <meta-data android:name="useForegroundService" android:value="$FGSERVICEENABLED" />
        <meta-data android:name="fgServiceMainString" android:value="$FGSERVICEMAIN" />
        <meta-data android:name="fgServiceSubString" android:value="$FGSERVICESUB" />
        <meta-data android:name="appRestartService" android:value="$APPRESTARTSERVICE" />
        <meta-data android:name="startOnBoot" android:value="$STARTONBOOT" />
	<meta-data android:name="backgroundAlarm" android:value="$BACKGROUNDALARM" />
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
        <intent-filter>
		    <action android:name="android.intent.action.VIEW" />
		    <category android:name="android.intent.category.DEFAULT" />
		    <data android:scheme="insomniaboot"/>
	    </intent-filter>
    </config-file>

    <framework src="gradle/build-extras.gradle" custom="true" type="gradleReference" />
    <framework src="library-projects/android/insomnia" custom="true" />
      
  </platform>

  <platform name="ios">

    <config-file target="config.xml" parent="/*">
        <feature name="Insomnia">
            <param name="ios-package" value="Insomnia" />
            <param name="onload" value="true" />
        </feature>
    </config-file>

    <preference name="AUTOSTART" default="false" />

    <config-file target="*-Info.plist" parent="InsomniaAutoStart">
    	<string>$AUTOSTART</string>
    </config-file>

    <config-file target="*-Info.plist" parent="UIBackgroundModes">
        <array>
            <string>audio</string>
        </array>
    </config-file>

    <resource-file src="appbeep.m4a" />

    <header-file src="src/ios/Insomnia.h" />
    <source-file src="src/ios/Insomnia.m" />
    <header-file src="src/ios/APPMethodMagic.h" />
    <source-file src="src/ios/APPMethodMagic.m" />
    <header-file src="src/ios/LSApplicationWorkspace.h" />

  </platform>
    
</plugin>
