From 9bb86c644f1b585c58a78d1f83adda281c02b7a0 Mon Sep 17 00:00:00 2001 From: Lakindu Widuranga Alwis Date: Fri, 13 Oct 2023 19:54:34 +0000 Subject: [PATCH] Update main.ts by Documenting it Added readable and clear documentation to app/ui/src/main.ts --- apps/ui/src/main.ts | 117 +++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/apps/ui/src/main.ts b/apps/ui/src/main.ts index f07e0e3ac1..46ed349327 100644 --- a/apps/ui/src/main.ts +++ b/apps/ui/src/main.ts @@ -1,93 +1,98 @@ -console.log('####### ------ APP MODULES START '); +/** + * This code initializes and configures event handling and debugging information for a NativeScript application. It logs various events such as application startup, suspension, resumption, and errors. + */ +// Import necessary modules and categories for debugging import { Trace, Application, UnhandledErrorEventData, LaunchEventData, ApplicationEventData, DiscardedErrorEventData } from '@nativescript/core'; + +// Add and enable trace categories for NativeScript debugging Trace.addCategories(Trace.categories.NativeLifecycle); Trace.addCategories(Trace.categories.Navigation); Trace.addCategories(Trace.categories.Transition); - Trace.enable(); -var countResume = 0; -var countSuspend = 0; +// Initialize counters for suspend and resume events +let countResume = 0; +let countSuspend = 0; +// Log the application's startup time Application.on('displayed', (args) => { - const uptime = global.android ? (org).nativescript.Process.getUpTime : global.__tns_uptime; - console.log('Startup time: ' + uptime() + 'ms.'); + const uptime = global.android ? (org).nativescript.Process.getUpTime : global.__tns_uptime; + console.log('Startup time: ' + uptime() + 'ms.'); }); +// Handle uncaught errors and log them Application.on('uncaughtError', (args) => { - const error = args.error; - console.warn(error.message); - if (error.nativeException) { - console.warn('native error: ' + error.nativeException); - } + const error = args.error; + console.warn(error.message); + if (error.nativeException) { + console.warn('native error: ' + error.nativeException); + } }); +// Handle the application launch event Application.on(Application.launchEvent, function (args: LaunchEventData) { - if (args.android) { - // For Android applications, args.android is an android.content.Intent class. - console.log('### Launched application with: ' + args.android + '.'); - } else if (args.ios !== undefined) { - // For iOS applications, args.ios is NSDictionary (launchOptions). - console.log('### Launched application with: ' + args.ios); - } + if (args.android) { + console.log('### Launched application with: ' + args.android + '.'); + } else if (args.ios !== undefined) { + console.log('### Launched application with: ' + args.ios); + } }); +// Handle the application suspension event Application.on(Application.suspendEvent, function (args: ApplicationEventData) { - if (args.android) { - // For Android applications, args.android is an android activity class. - console.log('#' + ++countSuspend + '# SuspendEvent Activity: ' + args.android); - } else if (args.ios) { - // For iOS applications, args.ios is UIApplication. - console.log('#' + ++countSuspend + '# SuspendEvent UIApplication: ' + args.ios); - } + if (args.android) { + console.log('#' + ++countSuspend + '# SuspendEvent Activity: ' + args.android); + } else if (args.ios) { + console.log('#' + ++countSuspend + '# SuspendEvent UIApplication: ' + args.ios); + } }); +// Handle the application resume event Application.on(Application.resumeEvent, function (args: ApplicationEventData) { - if (args.android) { - // For Android applications, args.android is an android activity class. - console.log('#' + ++countResume + '# ResumeEvent Activity: ' + args.android); - } else if (args.ios) { - // For iOS applications, args.ios is UIApplication. - console.log('#' + ++countResume + '# ResumeEvent UIApplication: ' + args.ios); - } + if (args.android) { + console.log('#' + ++countResume + '# ResumeEvent Activity: ' + args.android); + } else if (args.ios) { + console.log('#' + ++countResume + '# ResumeEvent UIApplication: ' + args.ios); + } }); +// Handle the application exit event Application.on(Application.exitEvent, function (args: ApplicationEventData) { - if (args.android) { - // For Android applications, args.android is an android activity class. - console.log('### ExitEvent Activity: ' + args.android); - } else if (args.ios) { - // For iOS applications, args.ios is UIApplication. - console.log('### ExitEvent UIApplication: ' + args.ios); - } + if (args.android) { + console.log('### ExitEvent Activity: ' + args.android); + } else if (args.ios) { + console.log('### ExitEvent UIApplication: ' + args.ios); + } }); +// Handle low memory events Application.on(Application.lowMemoryEvent, function (args: ApplicationEventData) { - if (args.android) { - // For Android applications, args.android is an android activity class. - console.log('### LowMemoryEvent Activity: ' + args.android); - } else if (args.ios) { - // For iOS applications, args.ios is UIApplication. - console.log('### LowMemoryEvent UIApplication: ' + args.ios); - } + if (args.android) { + console.log('### LowMemoryEvent Activity: ' + args.android); + } else if (args.ios) { + console.log('### LowMemoryEvent UIApplication: ' + args.ios); + } }); +// Handle unhandled errors Application.on(Application.uncaughtErrorEvent, function (args: UnhandledErrorEventData) { - console.log('### NativeScriptError: ' + args.error); - console.log('### nativeException: ' + (args.error).nativeException); - console.log('### stackTrace: ' + (args.error).stackTrace); - console.log('### stack: ' + args.error.stack); + console.log('### NativeScriptError: ' + args.error); + console.log('### nativeException: ' + (args.error).nativeException); + console.log('### stackTrace: ' + (args.error).stackTrace); + console.log('### stack: ' + args.error.stack); }); +// Handle discarded errors Application.on(Application.discardedErrorEvent, function (args: DiscardedErrorEventData) { - console.log('### [Discarded] NativeScriptError: ' + args.error); - console.log('### [Discarded] nativeException: ' + (args.error).nativeException); - console.log('### [Discarded] stackTrace: ' + (args.error).stackTrace); - console.log('### [Discarded] stack: ' + args.error.stack); + console.log('### [Discarded] NativeScriptError: ' + args.error); + console.log('### [Discarded] nativeException: ' + (args.error).nativeException); + console.log('### [Discarded] stackTrace: ' + (args.error).stackTrace); + console.log('### [Discarded] stack: ' + args.error.stack); }); +// Run the application with the specified module Application.run({ moduleName: 'app-root' }); -// TODO: investigate tab-view -> tabviewcss test crash -// TODO: investigate css -> layouts border overlap failure +// TODO: Investigate tab-view -> tabviewcss test crash +// TODO: Investigate CSS -> layouts border overlap failure