Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,19 @@ export class ImageLoader {
* @returns {Promise<string>} Returns a promise that resolves with the local path if exists, or rejects if doesn't exist
*/
private getCachedImagePath(url: string): Promise<string> {
// Check if we're running with livereload
let _isDev: boolean = (window['IonicDevServer'] != undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If the IonicDevServer variable is defined before the app loads, it makes more sense to make this a global variable (either a variable outside the class, or a private property of the class). This way we don't have to evaluate the expression every time getCachedImagePath is called.

return new Promise<string>((resolve, reject) => {

// make sure cache is ready
if (!this.isCacheReady) {
return reject();
}

// if we're running with livereload, ignore cache and call the resource from it's URL
if(!!_isDev){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! is not required.. since window['IonicDevServer'] != undefined or typeof window['IonicDevServer'] !== 'undefined' will always return a boolean

return reject();
}

// get file name
const fileName = this.createFileName(url);
Expand Down Expand Up @@ -452,10 +459,8 @@ export class ImageLoader {
// in this case only the tempDirectory is accessible,
// therefore the file needs to be copied into that directory first!
if (this.isIonicWKWebView) {

// Use Ionic normalizeUrl to generate the right URL for Ionic WKWebView
resolve(normalizeURL(fileEntry.nativeURL));

} else if (this.isWKWebView) {

// check if file already exists in temp directory
Expand Down