@@ -175,48 +175,59 @@ export class Platform {
175
175
* Returns a promise when the platform is ready and native functionality
176
176
* can be called. If the app is running from within a web browser, then
177
177
* the promise will resolve when the DOM is ready. When the app is running
178
- * from an application engine such as Cordova, then the promise
179
- * will resolve when Cordova triggers the `deviceready` event.
178
+ * from an application engine such as Cordova, then the promise will
179
+ * resolve when Cordova triggers the `deviceready` event.
180
+ *
181
+ * The resolved value is the `readySource`, which states which platform
182
+ * ready was used. For example, when Cordova is ready, the resolved ready
183
+ * source is `cordova`. The default ready source value will be `dom`. The
184
+ * `readySource` is useful if different logic should run depending on the
185
+ * platform the app is running from. For example, only Cordova can execute
186
+ * the status bar plugin, so the web should not run status bar plugin logic.
180
187
*
181
188
* ```
182
- * import {Platform} from 'ionic-angular';
189
+ * import {App, Platform} from 'ionic-angular';
183
190
*
184
- * @Page ({...})
185
- * export MyPage {
191
+ * @App ({...})
192
+ * export MyApp {
186
193
* constructor(platform: Platform) {
187
- * platform.ready().then(() => {
188
- * console.log('Platform ready' );
189
- * // The platform is now ready, execute any native code you want
194
+ * platform.ready().then((readySource ) => {
195
+ * console.log('Platform ready from', readySource );
196
+ * // Platform now ready, execute any required native code
190
197
* });
191
198
* }
192
199
* }
193
200
* ```
194
201
* @returns {promise }
195
202
*/
196
- ready ( ) : Promise < any > {
197
- // this is the default if it's not replaced by the engine
198
- // if there was no custom ready method from the engine
199
- // then use the default DOM ready
203
+ ready ( ) : Promise < string > {
200
204
return this . _readyPromise ;
201
205
}
202
206
203
207
/**
204
208
* @private
209
+ * This should be triggered by the engine when the platform is
210
+ * ready. If there was no custom prepareReady method from the engine,
211
+ * such as Cordova or Electron, then it uses the default DOM ready.
205
212
*/
206
- triggerReady ( ) {
213
+ triggerReady ( readySource : string ) {
207
214
this . _zone . run ( ( ) => {
208
- this . _readyResolve ( ) ;
215
+ this . _readyResolve ( readySource ) ;
209
216
} ) ;
210
217
}
211
218
212
219
/**
213
220
* @private
221
+ * This is the default prepareReady if it's not replaced by an engine,
222
+ * such as Cordova or Electron. If there was no custom prepareReady
223
+ * method from an engine then it uses the method below, which triggers
224
+ * the platform ready on the DOM ready event, and the default resolved
225
+ * value is `dom`.
214
226
*/
215
227
prepareReady ( ) {
216
- // this is the default prepareReady if it's not replaced by the engine
217
- // if there was no custom ready method from the engine
218
- // then use the default DOM ready
219
- ready ( this . triggerReady . bind ( this ) ) ;
228
+ ready ( ( ) => {
229
+ this . triggerReady ( 'dom' ) ;
230
+ } ) ;
220
231
}
221
232
222
233
/**
0 commit comments