How do I log messages to console? - and help fixing issue

Hello All,
I have been trying to fix this issue.

My approach to add this feature is as follows:

  1. write a public static method in the AssetManager class to check for extensions in the project. Something as below.
  public static boolean hasExtensions(){
    if (INSTANCE != null) {
      if (!INSTANCE.extensions.isEmpty())
        return true;
    }
    return false;
  }
  1. Then in DesignToolbar.java, inside the private class SendToGalleryAction, call the hasExtensions() before making a request to publish to the gallery. If the user has extensions, then display the correct error message.

I wanted to know if this approach will work or not, and if not what else should I try out.
Secondly I wanted to ask how to write to the debug Console?

        if (AssetManager.hasExtensions()){
          OdeLog.wlog("cant publish project with extensions");  
        }else{
          odeLog.wlog("good to go");
        }

I have written the above code inside the SendToGalleryAction class and I am getting this error.
image

Rather than putting this as a static method on the AssetManager, it might be more appropriate to define it as a method on ProjectRootNode and then in YoungAndroidProjectNode you can check whether getComponentsFolder() has any children.

Then in DesignToolbar you could do something like:

if (Ode.getCurrentYoungAndroidProjectRootNode().hasExtensions()) ...

Regarding your error, it looks like you've got a typo. It should be OdeLog not odeLog. However, this logs to a special debug window in App Inventor that is only accessible to administrators. Instead, consider using Ode.CLog(...) which logs to the browser's developer console.

Thanks @ewpatton,
I will be trying to solve it the way you suggested tomorrow.
For the time being I have fixed the typo and it compiled successfully.

I have change the galleryEnabled variable from false to true inside the designer toolbar constructor.
My implementation seems to work but not all the time can you suggest why it is not working all the time.

Cheers
Arya

I think the issue is that the AssetManager isn't really engaged if the companion isn't connected. My proposed solution doesn't rely on presence of the companion connection to infer the correct state.

Thank you so much will be working on the solution you proposed tomorrow. :slight_smile:

Arya

Hi ewan,
I am happy to report that I have implemented your solution.
The changes I made:

  1. ProjectRootNode
  public boolean hasExtensions(){
    return false;
  }
  1. YoungAndroidProjectNode
  @Override
  public boolean hasExtensions(){
    for (ProjectNode node : getComponentsFolder().getChildren()){
      return true;
    }
    return false;
  }
  1. DesignToolbar
    changed galleryenabled to true and lockPublishButton to false.
    (Will change them back when I push the code)

and added the code below (inside the sendToGalleryAction)

      if (!lockPublishButton) {
        lockPublishButton = false;
        if (Ode.getInstance().getCurrentYoungAndroidProjectRootNode().hasExtensions()){
          Ode.CLog("cant publish project with extensions");  
        }else{
          Ode.CLog("good to go");
        }

When there is no extension:

image

With extensions:
image

I am facing two problems:

  1. how do I make this error message appear in a user friendly way
  2. If I remove the extension and still try to publish, it still shows the error message.

@ewpatton @preetvadaliya can you guys help me out?

Cheers
Arya

Well, you can show them on GUI using modal or pop up using GWT.

The easiest way would be to do Window.alert. This is used in a few other places in the code for error messages.

Does it work correctly with a fresh project without extensions? It's possible that the deletion code might not be cleaning everything up correctly in which case the check you're using to verify if there are extensions might unexpectedly succeed. If this is the case it's likely a separate issue that we'll need to fix.

Does it work correctly with a fresh project without extensions?

Yes it works perfectly in a new project. But even after removal, it still thinks that I have an extension.

The easiest way would be to do Window.alert . This is used in a few other places in the code for error messages.

Thank you, works.

image

Ok will look into this, after 2 days, been caught up with some work. In the meantime can you guide me where to look in the source code for the extension deletion code.

Thank You
Arya

So the removal of extensions is kicked off by appinventor/appengine/src/com/google/appinventor/client/editor/simple/palette/ComponentRemoveWidget.java. This calls through to the component database, which eventually triggers YaProjectEditor's removeComponent method. This method makes the backend call to delete the extension from the server and then (supposedly) removes the extension from the local copy project tree:

So the most likely candidate seems to be that this check doesn't work correctly and so the local node isn't removed (but reloading should refresh the project from the server leading to the correct behavior).

You may want to print out all of the children of the asset folder in your check code to see what remains after you delete the extension.

Hi Evan,
I was trying to figure out why the extension is not being deleted from the client. When the site is refreshed the extension the issue is not there and the publish button works as expected. So the extension is being deleted from the server, I wanted to know can we change the data that we get from the server on the clinet locally when deleting the extension. If we can, then can you point me in the right direction on how to solve it.

Thanks
Arya