-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support the portals CLI functionality for android serve (#65)
- Loading branch information
Showing
5 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
IonicPortals/src/main/kotlin/io/ionic/portals/DevConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.ionic.portals | ||
|
||
import android.content.Context | ||
import com.getcapacitor.CapConfig | ||
|
||
/** | ||
* This class is used to load the server URL and Capacitor configuration from the assets folder when the app | ||
* is being run in developer mode with the Portals CLI. | ||
*/ | ||
object DevConfiguration { | ||
|
||
/** | ||
* Get the server URL for the given portal name from the developer mode assets folder. | ||
*/ | ||
fun getServerUrl(context: Context, portalName: String): String? { | ||
val portalDirName = "$portalName.debug" | ||
val generalDirName = "portal.debug" | ||
val urlFileName = "url" | ||
|
||
val assetManager = context.assets | ||
var serverUrl = try { | ||
assetManager.open("$portalDirName/$urlFileName").bufferedReader().use { | ||
it.readText() | ||
} | ||
} catch (e: Exception) { | ||
null | ||
} | ||
|
||
if (serverUrl == null) { | ||
serverUrl = try { | ||
assetManager.open("$generalDirName/$urlFileName").bufferedReader().use { | ||
it.readText() | ||
} | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
|
||
return serverUrl | ||
} | ||
|
||
/** | ||
* Get the Capacitor configuration for the given portal name from the developer mode assets folder. | ||
*/ | ||
fun getCapacitorConfig(context: Context, portalName: String): CapConfig? { | ||
val portalDirName = "$portalName.debug" | ||
val generalDirName = "portal.debug" | ||
val capConfigFileName = "capacitor.config.json" | ||
|
||
var serverConfig = try { | ||
val configFile = context.assets.open("$portalDirName/$capConfigFileName") | ||
CapConfig.loadFromAssets(context, portalDirName) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
|
||
if (serverConfig == null) { | ||
serverConfig = try { | ||
val configFile = context.assets.open("$generalDirName/$capConfigFileName") | ||
CapConfig.loadFromAssets(context, generalDirName) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
|
||
return serverConfig | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters