mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
feat: OnDiscardedError typings and event (#6777)
* feat: OnDiscardedError typings and event * remove ios and android from DiscardedErrorEventData
This commit is contained in:
@ -81,6 +81,13 @@ application.on(application.uncaughtErrorEvent, function(args: application.Unhand
|
|||||||
console.log("### stack: " + args.error.stack);
|
console.log("### stack: " + args.error.stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
application.on(application.discardedErrorEvent, function(args: application.DiscardedErrorEventData) {
|
||||||
|
console.log("### [Discarded] NativeScriptError: " + args.error);
|
||||||
|
console.log("### [Discarded] nativeException: " + (<any>args.error).nativeException);
|
||||||
|
console.log("### [Discarded] stackTrace: " + (<any>args.error).stackTrace);
|
||||||
|
console.log("### [Discarded] stack: " + args.error.stack);
|
||||||
|
});
|
||||||
|
|
||||||
application.setCssFileName("ui-tests-app/app.css");
|
application.setCssFileName("ui-tests-app/app.css");
|
||||||
|
|
||||||
application.start({ moduleName: "ui-tests-app/main-page" });
|
application.start({ moduleName: "ui-tests-app/main-page" });
|
||||||
|
@ -90,6 +90,12 @@ application.on(application.uncaughtErrorEvent, function (args: application.Unhan
|
|||||||
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
|
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
application.on(application.discardedErrorEvent, function (args: application.DiscardedErrorEventData) {
|
||||||
|
console.log("[Discarded] NativeScriptError: " + args.error);
|
||||||
|
console.log((<any>args.error).nativeException || (<any>args.error).nativeError);
|
||||||
|
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
|
||||||
|
});
|
||||||
|
|
||||||
// Android activity events
|
// Android activity events
|
||||||
if (application.android) {
|
if (application.android) {
|
||||||
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {
|
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {
|
||||||
|
@ -38,10 +38,11 @@ import {
|
|||||||
getRootView,
|
getRootView,
|
||||||
iOSApplication,
|
iOSApplication,
|
||||||
LoadAppCSSEventData,
|
LoadAppCSSEventData,
|
||||||
UnhandledErrorEventData
|
UnhandledErrorEventData,
|
||||||
|
DiscardedErrorEventData
|
||||||
} from "./application";
|
} from "./application";
|
||||||
|
|
||||||
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
||||||
|
|
||||||
export const launchEvent = "launch";
|
export const launchEvent = "launch";
|
||||||
export const suspendEvent = "suspend";
|
export const suspendEvent = "suspend";
|
||||||
@ -50,6 +51,7 @@ export const resumeEvent = "resume";
|
|||||||
export const exitEvent = "exit";
|
export const exitEvent = "exit";
|
||||||
export const lowMemoryEvent = "lowMemory";
|
export const lowMemoryEvent = "lowMemory";
|
||||||
export const uncaughtErrorEvent = "uncaughtError";
|
export const uncaughtErrorEvent = "uncaughtError";
|
||||||
|
export const discardedErrorEvent = "discardedError";
|
||||||
export const orientationChangedEvent = "orientationChanged";
|
export const orientationChangedEvent = "orientationChanged";
|
||||||
|
|
||||||
let cssFile: string = "./app.css";
|
let cssFile: string = "./app.css";
|
||||||
@ -122,3 +124,7 @@ export function addCss(cssText: string): void {
|
|||||||
global.__onUncaughtError = function (error: NativeScriptError) {
|
global.__onUncaughtError = function (error: NativeScriptError) {
|
||||||
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
|
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.__onDiscardedError = function (error: NativeScriptError) {
|
||||||
|
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
|
||||||
|
}
|
||||||
|
29
tns-core-modules/application/application.d.ts
vendored
29
tns-core-modules/application/application.d.ts
vendored
@ -21,6 +21,11 @@ export var displayedEvent: string;
|
|||||||
*/
|
*/
|
||||||
export var uncaughtErrorEvent: string;
|
export var uncaughtErrorEvent: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value used when hooking to discardedError event.
|
||||||
|
*/
|
||||||
|
export var discardedErrorEvent: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String value used when hooking to suspend event.
|
* String value used when hooking to suspend event.
|
||||||
*/
|
*/
|
||||||
@ -103,6 +108,13 @@ export interface UnhandledErrorEventData extends ApplicationEventData {
|
|||||||
error: NativeScriptError;
|
error: NativeScriptError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event data containing information about discarded application errors.
|
||||||
|
*/
|
||||||
|
export interface DiscardedErrorEventData extends ApplicationEventData {
|
||||||
|
error: NativeScriptError;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event data containing information about application css change.
|
* Event data containing information about application css change.
|
||||||
*/
|
*/
|
||||||
@ -137,7 +149,7 @@ export function setResources(res: any): void;
|
|||||||
export function setResources(resources: any);
|
export function setResources(resources: any);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets css file name for the application.
|
* Sets css file name for the application.
|
||||||
*/
|
*/
|
||||||
export function setCssFileName(cssFile: string): void;
|
export function setCssFileName(cssFile: string): void;
|
||||||
|
|
||||||
@ -199,7 +211,7 @@ export function shouldCreateRootFrame(): boolean;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||||
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
|
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
|
||||||
* @param callback - Callback function which will be executed when event is raised.
|
* @param callback - Callback function which will be executed when event is raised.
|
||||||
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
||||||
*/
|
*/
|
||||||
@ -262,6 +274,11 @@ export function on(event: "lowMemory", callback: (args: ApplicationEventData) =>
|
|||||||
*/
|
*/
|
||||||
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
|
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is raised when an discarded error occurs while the application is running.
|
||||||
|
*/
|
||||||
|
export function on(event: "discardedError", callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is raised the orientation of the current device has changed.
|
* This event is raised the orientation of the current device has changed.
|
||||||
*/
|
*/
|
||||||
@ -403,13 +420,13 @@ export class AndroidApplication extends Observable {
|
|||||||
/**
|
/**
|
||||||
* Initialized the android-specific application object with the native android.app.Application instance.
|
* Initialized the android-specific application object with the native android.app.Application instance.
|
||||||
* This is useful when creating custom application types.
|
* This is useful when creating custom application types.
|
||||||
* @param nativeApp - the android.app.Application instance that started the app.
|
* @param nativeApp - the android.app.Application instance that started the app.
|
||||||
*/
|
*/
|
||||||
init: (nativeApp) => void;
|
init: (nativeApp) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||||
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
||||||
* @param callback - Callback function which will be executed when event is raised.
|
* @param callback - Callback function which will be executed when event is raised.
|
||||||
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
||||||
*/
|
*/
|
||||||
@ -516,7 +533,7 @@ export class AndroidApplication extends Observable {
|
|||||||
public static activityRequestPermissionsEvent: string;
|
public static activityRequestPermissionsEvent: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
|
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
|
||||||
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
|
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
|
||||||
* @param intentFilter A string containing the intent filter.
|
* @param intentFilter A string containing the intent filter.
|
||||||
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
|
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
|
||||||
@ -524,7 +541,7 @@ export class AndroidApplication extends Observable {
|
|||||||
registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
|
registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a previously registered BroadcastReceiver.
|
* Unregister a previously registered BroadcastReceiver.
|
||||||
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
|
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
|
||||||
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
|
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
|
||||||
*/
|
*/
|
||||||
|
5
tns-core-modules/module.d.ts
vendored
5
tns-core-modules/module.d.ts
vendored
@ -3,7 +3,7 @@ declare var global: NodeJS.Global;
|
|||||||
interface ModuleResolver {
|
interface ModuleResolver {
|
||||||
/**
|
/**
|
||||||
* A function used to resolve the exports for a module.
|
* A function used to resolve the exports for a module.
|
||||||
* @param uri The name of the module to be resolved.
|
* @param uri The name of the module to be resolved.
|
||||||
*/
|
*/
|
||||||
(uri: string): any;
|
(uri: string): any;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ declare namespace NodeJS {
|
|||||||
* Register all modules from a webpack context.
|
* Register all modules from a webpack context.
|
||||||
* The context is one created using the following webpack utility:
|
* The context is one created using the following webpack utility:
|
||||||
* https://webpack.github.io/docs/context.html
|
* https://webpack.github.io/docs/context.html
|
||||||
*
|
*
|
||||||
* The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.),
|
* The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.),
|
||||||
* while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as:
|
* while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as:
|
||||||
* ```
|
* ```
|
||||||
@ -54,6 +54,7 @@ declare namespace NodeJS {
|
|||||||
__onLiveSync: (context?: { type: string, module: string }) => void;
|
__onLiveSync: (context?: { type: string, module: string }) => void;
|
||||||
__onLiveSyncCore: () => void;
|
__onLiveSyncCore: () => void;
|
||||||
__onUncaughtError: (error: NativeScriptError) => void;
|
__onUncaughtError: (error: NativeScriptError) => void;
|
||||||
|
__onDiscardedError: (error: NativeScriptError) => void;
|
||||||
TNS_WEBPACK?: boolean;
|
TNS_WEBPACK?: boolean;
|
||||||
__requireOverride?: (name: string, dir: string) => any;
|
__requireOverride?: (name: string, dir: string) => any;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user