Online Download

Dan P's Avatar

Dan P

28 May, 2021 05:05 PM

I'd like to disable the "Automatically Download" on startup and call it from my extension. Is this possible? I can't find anything in the API.

Thanks!

  1. 1 Posted by Stuart Beesley ... on 29 May, 2021 05:21 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    There is no documented API call.. But you can do it (thus, it's non-API and may not survive upgrades):

    In Python you would call:

    moneydance.getBackgroundThread().scheduleNetSync()
    

    In Java, exactly the same but using your reference (or context()) for main..

    NOTE: MD checks that it's the primary Sync dataset when opening a datafile, before triggering the downloads... I.E. you don't want all Sync copies doing this... You can check this using:

    if moneydance.getCurrentAccount().getBook().getLocalStorage().getBoolean("_is_master_node", True) then:
    

    To turn off Autodownload... Menu, Preferences, Network, untick Automatically Download in Background. This sets the config.dict key "net.auto_download" to false.

  2. 2 Posted by Dan P on 29 May, 2021 12:54 PM

    Dan P's Avatar

    Wow! The Amazing Stuart has the answer! Sean should really be paying you.
    I'll see if I can incorporate your suggestions in Java.

    Thanks!

  3. 3 Posted by Dan P on 29 May, 2021 03:50 PM

    Dan P's Avatar

    Well, as I'm not a good programmer in python or java, this is going well.

    I got the check on master node to work. However, I can't get to the
    background thread.

    *In Python you would call:*

    *moneydance.getBackgroundThread().scheduleNetSync()
    *

    *In Java, exactly the same but using your reference (or context()) for
    main.*

    I can't find any context that will do this. I may not have a required
    library imported.

    I'll keep looking. Any 'nudge' would be appreciated.

  4. 4 Posted by Stuart Beesley ... on 29 May, 2021 04:12 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    Ok. Well in your Java code you must already have a reference to main / context otherwise you couldn’t call the MD api functions. Do you have anything like xxxx.getUI(). The xxx is it.

    Else post your Java code?

  5. 5 Posted by Stuart Beesley ... on 29 May, 2021 04:16 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    so... in your Main.java you will see something like this:

    public class Main
      extends FeatureModule
    {
      private AccountListWindow accountListWindow = null;
    
      public void init() {
        // the first thing we will do is register this module to be invoked
        // via the application toolbar
        FeatureModuleContext context = getContext();
        try {
          context.registerFeature(this, "showconsole",
            getIcon("accountlist"),
            getName());
        }
        catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }
    

    context (above) or whatever you called it should be it....

  6. 6 Posted by Stuart Beesley ... on 29 May, 2021 05:24 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    I just reread you message. If you already got x.getCurrentAccount() to work, then x should be what you want....

  7. 7 Posted by Dan P on 29 May, 2021 05:40 PM

    Dan P's Avatar

    Well, that's what I thought too. But it isn't working. I've made several attempts but here is the latest code:

    public void execAll() {
        getPrefs();
        if (!Prefs.doneToday) {
            if (Prefs.doQUOTES) {getQuotes();}
            if (Prefs.doFORUM)  {doForum();}
            if (Prefs.doAIG)    {doAIG(); }
            if (Prefs.doLPL)    {doLPL();}
            if (Prefs.doNW)     {doNW();}
            Prefs.savePrefs(prefFile);
            System.err.println(String.format("%-8s %6s %-14s %-20s", "DAILY", "<INIT>", ft.format(new Date()),
                    "Daily Update Completed."));
        } else {
            System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INIT>", ft.format(new Date()),
                    "Daily Update Already Processed for Today."));
        }
        if (extension.getUnprotectedContext().getCurrentAccountBook().getLocalStorage().getBoolean("_is_master_node", true) )  {
            System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INIT>", ft.format(new Date()),
                    "Yes, I am the Master Node."));
        try {
            FeatureModuleContext contxt = getContext();
            System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<INFO> ", ft.format(new Date()),
                    "Invoking NetSync."));
            ((BackgroundOpsThread) contxt).scheduleNetSync(); 
            } catch (final Exception e) {
            System.err.println(String.format("%-8s %6s %-14s %-60s", "DAILY", "<ERR> ", ft.format(new Date()),
                    e.getMessage()));
            }
        }
    }
    

    The BackGroundOpsThread cast was suggested by Eclipse so I'm guessing the ScheduleNetSync is in there. It compiles but throws an exception.
    class com.moneydance.apps.md.controller.Main cannot be cast to class com.moneydance.apps.md.controller.BackgroundOpsThread (com.moneydance.apps.md.controller.Main and com.moneydance.apps.md.controller.BackgroundOpsThread are in unnamed module of loader 'app')

    I changed the contxt from getContext() to getUnprotectedContext - same result.

    (I am NOT a java guy - as you can probably tell)

  8. 8 Posted by Dan P on 29 May, 2021 05:58 PM

    Dan P's Avatar

    FYI

  9. 9 Posted by Stuart Beesley ... on 29 May, 2021 08:43 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    .

  10. 10 Posted by Stuart Beesley ... on 29 May, 2021 10:13 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    I don't write Java myself (just read it), but I just tried adding this line, ran ant to build it, and it works for me.... Remember you're off-piste (off API here).. try:

    ((com.moneydance.apps.md.controller.Main) getContext()).getBackgroundThread().scheduleNetSync();
    
  11. 11 Posted by Dan P on 29 May, 2021 11:13 PM

    Dan P's Avatar

    Success!

    I've incorporated that into my extension and it works fine.
    Cautions noted.

    Thanks for your help, Stuart. I would likely not have ever figured that cast out.

    Dan

  12. Dan P closed this discussion on 16 Jun, 2021 06:22 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac