β οΈ This blog post was created with AI assistance
π What Are Application Shell Triggers?
Application Shell Triggers are special event handlers in Uniface 10.4 that let you control how your application behaves when it starts or interacts with users. Think of them as hooks where you can add your own code to customize the application's behavior.
π§ Common Triggers for All Application Shells
Almost every application shell in Uniface shares these two fundamental triggers:
β¨ trigger apStart
This trigger fires when your application starts. It's the perfect place to initialize settings, load configurations, or set up connections to databases.
Example use case: You might use apStart
to check if a user has valid credentials before letting them access the application, or to load language preferences.
π¨ trigger receiveMessage
This trigger handles incoming messages to your application. It's useful for applications that need to communicate with other systems or processes.
Example use case: Your application could receive notification messages from other services and process them accordingly.
π₯οΈ Desktop Application Triggers
Windows and character-based applications get three additional triggers for handling user interactions:
π trigger menu
This trigger responds when users interact with menu items. You can use it to execute actions when someone clicks a menu option.
Example: When a user clicks "File > Save", the menu
trigger can execute your custom save logic.
β¨οΈ trigger keyboardSwitch
This trigger handles keyboard switching events, useful for applications that support multiple keyboard layouts or input methods.
π trigger userKey
This trigger captures custom keyboard shortcuts defined by users. It allows you to add special functionality for specific key combinations.
Example: You could map Ctrl+Shift+R to refresh data from the database.
π Server Shell Triggers
Server application shells have specialized triggers for web environments. These are essential for handling web requests:
π trigger preRequest
This trigger fires before a component operation is activated. It's the ideal place for authentication and authorization checks.
Example: Check if the user has a valid session token before allowing them to access protected resources. If the token is invalid, redirect them to a login page.
β trigger postRequest
This trigger fires after a component operation completes. Use it for cleanup tasks or logging.
Example: Log the user's activity, clean up temporary resources, or add custom HTTP headers to the response.
π‘ Practical Tips
- Keep it light: Avoid heavy processing in
apStart
as it can slow down application startup - Security first: Always use
preRequest
for authentication in web applications - Error handling: Make sure to handle errors gracefully in all triggers to prevent application crashes
- Testing: Test each trigger thoroughly, especially authentication logic in
preRequest
π― Summary
Application Shell Triggers in Uniface 10.4 give you powerful control points for customizing application behavior. Whether you're building desktop applications with user interactions or server applications handling web requests, these triggers help you implement clean, maintainable code at the right moments in your application's lifecycle.
Happy coding! π
Top comments (0)