From 5f07f4fc17adac5bc2d811cbba3413c2fce44f3e Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 10 Nov 2015 15:00:41 +0200 Subject: [PATCH 1/2] Reload app.css and clear file resolver cache on livesync. --- application/application-common.ts | 8 ++++++++ file-system/file-name-resolver.d.ts | 2 ++ file-system/file-name-resolver.ts | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/application/application-common.ts b/application/application-common.ts index 192c40791..54d5922cf 100644 --- a/application/application-common.ts +++ b/application/application-common.ts @@ -4,6 +4,7 @@ import fs = require("file-system"); import styleScope = require("ui/styling/style-scope"); import observable = require("data/observable"); import frame = require("ui/frame"); +import fileResolverModule = require("file-system/file-name-resolver"); var events = new observable.Observable(); global.moduleMerge(events, exports); @@ -53,5 +54,12 @@ export function loadCss() { } global.__onLiveSync = function () { + // Clear file resolver cache to respect newly added files. + fileResolverModule.clearCache(); + + // Reload app.css in case it was changed. + loadCss(); + + // Reload current page. frame.reloadPage(); } \ No newline at end of file diff --git a/file-system/file-name-resolver.d.ts b/file-system/file-name-resolver.d.ts index 2d9e5d370..5b18d44e1 100644 --- a/file-system/file-name-resolver.d.ts +++ b/file-system/file-name-resolver.d.ts @@ -12,9 +12,11 @@ declare module "file-system/file-name-resolver" { export class FileNameResolver { constructor(context: PlatformContext); resolveFileName(path: string, ext: string): string; + clearCache(): void; } export function resolveFileName(path: string, ext: string): string; + export function clearCache(): void; //@private export function findFileMatch(path: string, ext: string, candidates: Array, context: PlatformContext): string diff --git a/file-system/file-name-resolver.ts b/file-system/file-name-resolver.ts index fdf023498..b9e7c785a 100644 --- a/file-system/file-name-resolver.ts +++ b/file-system/file-name-resolver.ts @@ -126,6 +126,10 @@ export class FileNameResolver implements definition.FileNameResolver { return result; } + public clearCache(): void { + this._cache = {}; + } + private resolveFileNameImpl(path: string, ext: string): string { var result: string = null; path = fs.path.normalize(path); @@ -239,3 +243,8 @@ export function resolveFileName(path: string, ext: string): string { return resolverInstance.resolveFileName(path, ext); } +export function clearCache(): void { + if (resolverInstance) { + resolverInstance.clearCache(); + } +} \ No newline at end of file From 79caa4ba0c5b8a9323bfa13a9820d275c19ce05b Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 10 Nov 2015 16:22:09 +0200 Subject: [PATCH 2/2] Fix: Crash in when livesync-ing minimized app --- application/application-common.ts | 12 ------------ application/application.android.ts | 20 ++++++++++++++++++++ application/application.ios.ts | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/application/application-common.ts b/application/application-common.ts index 54d5922cf..377c8cdf9 100644 --- a/application/application-common.ts +++ b/application/application-common.ts @@ -4,7 +4,6 @@ import fs = require("file-system"); import styleScope = require("ui/styling/style-scope"); import observable = require("data/observable"); import frame = require("ui/frame"); -import fileResolverModule = require("file-system/file-name-resolver"); var events = new observable.Observable(); global.moduleMerge(events, exports); @@ -51,15 +50,4 @@ export function loadCss() { } } } -} - -global.__onLiveSync = function () { - // Clear file resolver cache to respect newly added files. - fileResolverModule.clearCache(); - - // Reload app.css in case it was changed. - loadCss(); - - // Reload current page. - frame.reloadPage(); } \ No newline at end of file diff --git a/application/application.android.ts b/application/application.android.ts index 6bafb8e40..7b501d7fc 100644 --- a/application/application.android.ts +++ b/application/application.android.ts @@ -4,6 +4,7 @@ import frame = require("ui/frame"); import types = require("utils/types"); import observable = require("data/observable"); import enums = require("ui/enums"); +import fileResolverModule = require("file-system/file-name-resolver"); global.moduleMerge(appModule, exports); @@ -71,6 +72,8 @@ var initEvents = function () { return; } + (androidApp).paused = true; + if (activity === androidApp.foregroundActivity) { if (exports.onSuspend) { exports.onSuspend(); @@ -91,6 +94,8 @@ var initEvents = function () { return; } + (androidApp).paused = false; + if (activity === androidApp.foregroundActivity) { if (exports.onResume) { exports.onResume(); @@ -347,3 +352,18 @@ function onConfigurationChanged(context: android.content.Context, intent: androi }); } } + +global.__onLiveSync = function () { + if (exports.android && exports.android.paused) { + return; + } + + // Clear file resolver cache to respect newly added files. + fileResolverModule.clearCache(); + + // Reload app.css in case it was changed. + appModule.loadCss(); + + // Reload current page. + frame.reloadPage(); +} \ No newline at end of file diff --git a/application/application.ios.ts b/application/application.ios.ts index a1910d018..4f2dc6241 100644 --- a/application/application.ios.ts +++ b/application/application.ios.ts @@ -5,6 +5,7 @@ import view = require("ui/core/view"); import definition = require("application"); import enums = require("ui/enums"); import uiUtils = require("ui/utils"); +import fileResolverModule = require("file-system/file-name-resolver"); global.moduleMerge(appModule, exports); @@ -227,3 +228,18 @@ exports.start = function () { throw new Error("iOS Application already started!"); } } + +global.__onLiveSync = function () { + if (!started) { + return; + } + + // Clear file resolver cache to respect newly added files. + fileResolverModule.clearCache(); + + // Reload app.css in case it was changed. + appModule.loadCss(); + + // Reload current page. + frame.reloadPage(); +} \ No newline at end of file