Is there a method in Adobe AIR for JS that allows for the storage of non-persistent data?

Working on a project, I am developing an app using Adobe AIR and have opted for the HTML/Ajax version. At this point, the project is relatively small, consisting of a login section and a details section.

My goal is to display the login.html page upon app launch and then automatically navigate to details.html upon successful login. Is there a convenient method to store some of the login information (such as user ID) in a session or application container?

I took a quick look at the BlackBookSafe example provided by Adobe, but it seems that they keep the main blackbooksafe.html open at all times, loading child pages into the body to store session data within blackbooksafe.html. However, I find this approach a bit messy and would prefer each page to manage its own data (using JavaScript), which I believe will enhance readability.

Answer №1

Although this discussion is quite old, I thought I'd share my solution in case it helps someone out there.

I came up with a workaround that feels like a bit of a hack, but it gets the job done. Shame on Adobe for not making this easier!

Storing Data as JSON Strings in Menu Data

Menus can persist across page loads, and you can add custom data to a menu. However, it seems to only accept simple data types like strings or integers. To work around this limitation, you can download json2.js from http://json.org and use its `stringify()` and `parse()` functions to convert your application state into a JSON string and store it in the `.data` property of a menu item.

In my case, I stored the JSON string in the first menu item's `items` list. Here's how I did it using jQuery:


function InitApp() {
    var menu = air.NativeApplication.nativeApplication.menu;
    var firstMenu = menu.items[0];
    
    // Check if data has been stored previously
    var dataStore = firstMenu.data;
    
    if (dataStore == null) {
        var dataObj = { 
            msg: "Message Object",
            status: 1 
        };
        
        var dataObjStr = JSON.stringify(dataObj);
        firstMenu.data = dataObjStr;
        
        dataStore = firstMenu.data;
    } else {
        var obj = JSON.parse(dataStore);
    }

    BuildMenu();
    
    // Pass data along after creating the menu
    firstMenu = air.NativeApplication.nativeApplication.menu.items[0];
    firstMenu.data = dataStore; 
}

$(document).ready(InitApp);

Keep in mind that this data will disappear once the application is closed, as it's only persistent while the app is running.

It would have been much better if NativeApplication supported the same feature as menus!

Note: This code was written on a Mac, so adjustments may be needed for Windows/Linux environments using NativeWindow.menu.

Answer №2

While exploring different options, I came across a variety of hacks such as saving data on a file (which was used in one of Adobe's examples) or storing it in the database. However, I couldn't find a quick solution for a non-persistent data store. It would be great to have a key/value dictionary connected to the NativeApplication object for storing my non-persistent data, but unfortunately, that feature doesn't exist.

In the end, I opted for an IFRAME approach where the parent page holds the non-persistent data.

Answer №3

It appears you are working with an AIR application, indicating it is not a standard web application.

In traditional web applications, sessions are necessary because web pages do not maintain persistent connections. However, in your situation, you have access to other resources that can provide similar functionality such as database connections that stay open and store login information through the chosen dbms connectivity solution. This alternative should serve the same purpose as sessions in a web environment.

Another approach could be using a singleton Users class that remains active throughout the application's lifespan.


EDIT:

Answer №4

Instead of using a complex data structure, why not keep it simple and create a basic object:

var details = {};

How to use it:

details.email = 'example@email.com';
details.phone = '555-5555';
// Accessing the information:
alert(details.email);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for writing/appending the JSON object from a POST request to a JSON file

I'm looking to update a JSON file by adding a new element using data from a POST request. The process is mostly working, but I'm struggling with including the id in the data. Can anyone help me figure this out? I've tried various approaches ...

Jquery and CSS behaving in an unexpected manner

Here's a piece of code that I need some help with. The issue occurs when clicking on a box to expand it and display more information. Most of the time, it works fine, but occasionally if an image is not cached, clicking again to minimize the box cause ...

What techniques can be applied to utilize JSON data in order to dynamically create menu components using the map method?

My current challenge involves dynamically generating a set of menu items using data retrieved from a JSON file. I've attempted to achieve this by mapping the values with props, but it seems like I'm overlooking something. Below is the code snipp ...

Having trouble sending data to a Laravel 5 controller through Angular. Keep getting Error 422: Unprocessable Entity

My login form is built with angularjs, and I am trying to send the user's credentials to the default AuthController in Laravel 5. However, I keep encountering a server response of 422 Unprocessable Entity with the message: email field is required. HT ...

Querying a Database to Toggle a Boolean Value with Jquery, Ajax, and Laravel 5.4

I am facing an issue with a button I created to approve a row in a table. It seems that everything is working fine when clicking the button, but there is no change happening in the MySQL database Boolean column. Here is the code for my button: <td> ...

Tips for transferring information from Django to React without relying on a database

Currently, I am in the process of developing a dashboard application using Django and React. The data for the user is being pulled from the Dynamics CRM API. To accomplish this, I have implemented a Python function that retrieves all necessary informatio ...

Using jQuery to append an <option> element to a <select> tag

Every time I try to add an option to a select, the option I want to add gets appended to the first option instead of the actual select element. $(".ct [value='']").each(function() { $(this).append($("<option></option>").attr("val ...

Utilizing props in makeStyles for React styling

I have a component that looks like this: const MyComponent = (props) => { const classes = useStyles(props); return ( <div className={classes.divBackground} backgroundImageLink={props.product?.image} sx={{ position: "r ...

PhoneGap iOS application storing outdated information

My Phonegap 2.1 app running on iOS 6, with jQuery 1.7.2 and JQMobile 1.1.1 libraries, is experiencing an issue where old data from ajax responses gets cached if the app is unused for a few days. The only way to resolve this issue is by reinstalling the a ...

Uncovering Modified Form Elements Using jQuery

I am managing a form with the ID "search_options" and tracking changes in the form using the following code: $("#search_options").change(function() { // Bla Bla Bla }); Within this form, I have various inputs including one with the ID "p ...

The chosen index in the Material Stepper feature is experiencing a malfunction

I've been busy working on a Mat-Stepper, actually two of them. I have a component that contains two ng-templates set up like this: Question: Why is my selected index not functioning as expected? Am I missing something? I know you can define [selected ...

What is the best way to make a specific update to a single dependency in package-lock.json without causing any unintended consequences?

I want to update a specific NPM (v5) dependency in my application from version 1.0.0 to 1.0.1 without altering my package.json file. "dependencies": { "package": "~1.0.0" }, Currently, my package-lock.json file lists the dependency as version 1.0.0, so ...

JavaScript countdown feature that includes hours and minutes

Currently, I have successfully implemented a countdown timer in seconds. However, I am looking to enhance this by incorporating hours and minutes into the countdown as well while maintaining the existing structure using only pure JavaScript. The desired ou ...

The Google Maps application is having trouble zooming in

I'm having trouble with my function that takes the zoom level and sets the center of the map. When I call setCenter with my positional coordinates and zoom level, the map doesn't zoom in where I want it to. However, the position of my info window ...

What is the best approach to determine the value of a textbox in an array for each row of

I am trying to display the total sum of values for each row in a data array. There are 5 rows of data, and I need to calculate the results for each one. Can someone assist me in solving this? function calculateTotalValue(){ var total = (document.get ...

Using Javascript to parse a json file that contains additional content at the beginning

I am attempting to access a JSON URL, but the JSON is displaying some extra characters before it starts. The structure of the JSON script is as follows: throw 'allowIllegalResourceCall is false.'; { "name":"mkyong", "age":30, "addres ...

Having trouble reaching an injected dependency beyond the controller method

Can an injected dependency on a controller be accessed outside of it? function clientCreateController(ClientsService, retrieveAddress) { var vm = this; vm.searchCep = searchCep; } function searchCep(cep) { retrieveAddress.find(cep) .success ...

Retrieve the visible text content of an element by utilizing various ids

I am currently working on a project using AngularJS with multiple conditions all sharing the same id. My goal is to extract text only from the condition that evaluates to true. Recently, I discovered a major bug in an app that I am preparing for release. ...

Accessing dropdown selection in Javascript-Json: A Comprehensive Guide

My dropdown list is being populated dynamically using json. The selected option from the first dropdown determines the options in a secondary dropdown. I need to use the selection from the second dropdown to automatically fill out two more fields. For exa ...

Issues with AJAX file uploads in Django

I'm encountering an issue while attempting to upload files using Ajax in Django. My approach involves utilizing FormData in Javascript. However, the problem lies on the server side. The files are expected to be received in request.FILES, but they are ...