Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets (& cache) location should be user configurable #6

Open
Nos78 opened this issue Nov 7, 2022 · 0 comments
Open

Assets (& cache) location should be user configurable #6

Nos78 opened this issue Nov 7, 2022 · 0 comments

Comments

@Nos78
Copy link

Nos78 commented Nov 7, 2022

Related to issue #5 and #3 - if the path for both the project assets and the extension cache location were user-configurable, I doubt either of these issues would have been raised.

The resources directory in the latest android SDK is called 'res' rather than 'resources' - the README specifically instructs the user to construct their project as src/main/resources/drawable, which is fine if they are building the project themselves and from scratch, but many users may want to use this extension part way through the development of an existing app, and changing the project structure at this point becomes a hassle.

I personally have my workspace folder at the /app/src/main/.../etc/... level, so the path is wrong for me in any case - I need the path to be at the parent directory, so it would be app/src/... I've modified this myself, but I'm sure I'm not the only user who would prefer to configure this rather than re-organising their project or opening a new workspace at the /app/ directory just to get this extension working.

Also, the cache location, /media/drawable doesn't exist, vscode is not creating this directory when the extension is installed, and createOrShow() attempts to access it without checking if it exists. If these paths had been user configurable, I'm sure the developer would have immediately considered the case of this directory not existing.

In brief:

  • The paths used for the assets (both cache & asset location) are hard coded.
  • In addition, the cache is not being checked to see if it exists before trying to access it and throwing an exception immediately after a user presses F1 and tries to run it.

I've made a few changes, and will create pull requests (I'll split the change, just in case you don't want to make the cache location user-configurable, and I can see the sense in that if that is indeed the case).

  • Change 1: make the /src/main/res/drawable path configurable, and change the default to be /res/ (another pull request has already changed this default location, but it is still hard-coded)
  • Change 2: check that the /media/drawable cache location exists, and if not, create it before trying to copy or delete the contents.
  • Change 3: make /media/assets user configurable, for those like me that like to have these sorts of storage placed in /tmp/ so I know it is safe to delete when I want to free up space!
Nos78 added a commit to Nos78/android-xml-editor that referenced this issue Nov 7, 2022
…ble via a new configuration setting, xmlEditor.resourcesPath, which is accessible via the File->Settings menu within VSCode.

package.json:
Add new configuration properties for xmlEditor.resourcesPath, as a string with
a default value to match the existing hard-coded location (modified to reflect
the standard location of /res/ rather than /resources/).

Added a markdownDescription for this setting, which explains the default value
and that this path is relative to the workspace root.

Note that when you add settings (or remove them) into an extension package.json,
you need to reboot vscode to re-build the settings menu, then reboot vscode a
second time to actually see it.

src/extension.ts:
+ Modified the createOrShow() function to get the configuration via vscode API,
and get the resources path from the settings configuration object. If this path
is not defined or empty, we fall back to the (modified) hard-coded path.
+ Replaced the hard-coded path with the new variable from the settings.

This commit addresses issue Knowcode-AI#6, change 1.
Nos78 added a commit to Nos78/android-xml-editor that referenced this issue Nov 7, 2022
…nowcode-AI#6

The /media/drawable directory does not exist when the extension is initially
installed, yet the createOrShow() function calls fs.rmdirSync recursively,
which throws an error on the non-existing drawable directory (media exists).

I've wrapped this call up with an fs.existsSync, which will perform the
existing action if the directory exists, otherwise it calls fs.mkdirSync
with the same options as the call to fs.rmdirSync (i.e, recursive: true)

The extension will now execute successfully on an initial install without the
user having to create the subdirectory tree manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant