dEhiN / CompStart

See README
2 stars 0 forks source link

Work on menu option: Save startup data to disk for a single, modified startup item #6

Closed dEhiN closed 7 months ago

dEhiN commented 12 months ago

Currently, when choosing to edit an existing startup item, it's possible to change the name, description, program path, and even arguments. This includes editing, deleting, and adding arguments. However, while there's a menu option to save the (modified) startup data, currently, a message is printed out that the functionality isn't available yet.

dEhiN commented 11 months ago

See issue #10 for more details

dEhiN commented 11 months ago

Even though I'm the only one currently working on this repo, it's probably a good idea to get into the habit of updating issues. So, currently while no data is actually saved to disk yet, the function to save the data is coming along well.

It calls the function generate_user_edited_data which needed to be coded in anyway, as it will help with other overall functionality. This function handles 4 scenarios:

  1. Need to update a single, existing startup item
  2. Need to update the full JSON data
  3. Need to add a single startup item
  4. The passed in JSON data isn't valid - either the original passed in or the modified data

Currently, scenarios 2-4 are handled by generate_user_edited_data. None of the generated JSON data is saved to disk yet, since scenario 1 still needs to be added in.

dEhiN commented 11 months ago

In testing out the existing code to make sure that scenario 1 works correctly, discovered a bug. So far, for all my testing of the save functionality, and specifically the generate_user_edited_data function, I've been using startup item 2 from the default startup data, which is the following:

{
  "ItemNumber": 2,
  "Name": "Google",
  "FilePath": "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
  "Description": "The Google Homepage",
  "Browser": true,
  "ArgumentCount": 3,
  "ArgumentList": [
    "--profile-directory=Default",
    "--new-window",
    "https://www.google.com/"
  ]
}

This startup item has existing arguments, so the tests have been working to add a new argument, for example. However, I tried with startup item 1, which doesn't have any arguments, and while the argument count key/property gets updated, the prettify_startup_item function runs into an error. Will need to fix this.

dEhiN commented 11 months ago

Created issue #15 to work on this.

dEhiN commented 8 months ago

Currently, the save function prints out that the functionality isn't yet implemented. Will continue to work on this.

dEhiN commented 7 months ago

As of March 2/23, the save function only pertains and shows for a single startup item. While testing, I discovered that when editing the startup file, while changes made to more than 1 startup item is retained in memory while the program is running, it's not possible to save all the changes. When saving the changes to 1 startup item, the text file that the changes are printed/saved to will use the default or original JSON data for the other startup items.

For example, say a user follows the following steps:

  1. Select to edit the existing startup file
  2. Select to edit item 2 (of the 3 default startup items)
  3. Edit item 2
  4. Return to the menu to select which item to edit
  5. Select to edit item 3
  6. Edit item 3

The user could then switch between selecting to edit item 2 and 3, and then choose the option to view the startup item, and the changes in steps 3 and 5 above will be retained. However, the only save option in the menu for editing a single startup item. If this option is chosen for item 2, then the original JSON data will save for item 3. Conversely, if the save option is chosen for item 3, then the original JSON data will save for item 2.

dEhiN commented 7 months ago

Debugged and stepped through to see what's currently happening. In the stack, when going through the menu to edit a single startup item, the following happens:

demord > json_editor() > edit_startup_item() > edit_startup_item_arguments_list() > add_startup_item_arguments_list()* *the last function for when a startup item has no arguments

As already mentioned, currently the only save option is in the menu for editing a single startup item. The problem is that the function json_editor holds a reference to the full startup data dictionary including every changed startup item. So, if items 2 and 3 are changed, when the program flow goes back to json_editor, the dictionary json_data will have both updated items.

But, when the function edit_startup_item is called, only the specific item chosen is passed through. Additionally, currently, when the save function is called, the function edit_startup_item passes onto the save_startup_item function the same specific item chosen. The save function then calls json_reader() to read in the original JSON data. This is what causes previously edited startup items to not be saved.

dEhiN commented 7 months ago

Possible solutions:

  1. Move the save functionality to json_editor() so it's not possible to save an individual startup item after editing it, but only always the full startup data
  2. Create a global variable in demord to hold the persistent startup data, which can then be updated as needed as well as used throughout the program
  3. Change the save function to work as it should and save the updated startup item to disk, which in theory, should then be read in the next time the save function is called
dEhiN commented 7 months ago

Thoughts on the possible solutions:

Solutions 1 and 2 may potentially involve rewriting existing functions. For example, with solution 1, if it's only possible to save the whole startup data dictionary, then the functionality to determine which type of save operation is unnecessary. While it can be erased, there's probably no need. A similar situation occurs with solution 2.

Solution 3 is probably the original idea I had in mind when creating the save functionality with all the logic to determine which type of save operation, to allow for and choose different scenarios, etc. The save function probably doesn't work fully at this moment because, in order to confirm the updated startup item data would be saved, I modified the save function to write the original JSON data, the original startup item, the changed startup item, and the changed JSON data (with the changed startup item) to a text file.

If, instead, I have the save function properly save the changed JSON data, then, when the save function is called after editing another startup item, the JSON data read in by json_reader() will be the changed data instead of the default startup data. I will need to test this. However, if this works, I could still implement solution 1, or at least, add a save functionality to the json_editor() menu.

dEhiN commented 7 months ago

Changed the issue title to reflect that it's for a single startup item. This issue is now complete.