Working autosave, but need help to finalize it
All  1-6  7-19

Previous
Next
 From:  Michael Gibson
11150.7 In reply to 11150.6 
Hi Moi3dFan,

re:
> One last question, the autosave options only apply when the entire interface is reloaded or if reopen moi3d

I think this is because you need the script code inside of SidePane.htm to run again and currently the code in there is only set to run when the SidePane.htm document is loading.

You'll need to package up the code in SidePane.htm so the timer can be cleared and reset when the settings change.

So for example change the script code in SidePane.htm to something like this (untested):
code:
			<script>
				var myTimer = false;

				function SetAutosaveTimer()
				{
					if ( myTimer )
						clearInterval( myTimer );

					... get any value from moi.ini and set up timer
				}

				// Call SetAutosaveTimer() on SidePane.htm load to get it running.
				SetAutosaveTimer();
			</script>



Then in some other location like in GeneralOptions.htm when you want to clear and reset the timer, you can call that function inside SidePane.htm like this:

moi.ui.sidePane.SetAutosaveTimer();

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.8 In reply to 11150.7 
I tried this method, it passes without error.
But unfortunately it didn't help.
Only reloading the interface leads to results
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11150.9 In reply to 11150.8 
Hi Moi3dFan, can you please show your updated SidePane.htm file?

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.10 In reply to 11150.9 
Yep!

p.s. I have textID configured


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11150.11 In reply to 11150.10 
Hi Moi3dFan, the problem is your function SetAutosaveTimer() inside SidePane.htm only consists of this:

code:
					function SetAutosaveTimer()
					{
						if ( Autosave == 0 ) clearInterval(AutosaveTimer);
					}


That's only clearing the timer, not setting it up.

The point of making the function is for it to contain the setup code as well. So you need to move the code for setting up the timer into the function.

Something like this (untested, may have typos):

code:
					var AutosaveTimer = false;
					var Autosave = 0;
					var AutosaveIncremental = false;
	
					function SetAutosaveTimer()
					{
						if ( AutosaveTimer ) clearInterval(AutosaveTimer);

						Autosave = moi.command.getOption( 'Autosave', true); // return autosave time (ms) from ini (180000 = 3 min)
						AutosaveIncremental = moi.command.getOption( 'AutosaveIncremental', true); //return AS mode (false)

						AutosaveTimer = setInterval(function() {
							if (AutosaveIncremental) { 
								moi.command.execCommand('IncrementalSave');
							} else { 
								moi.command.execCommand('Save');
							}
						}, Autosave)

					}
					SetAutosaveTimer();


Also since the setup is retrieving the values from moi.ini you need to alter the code in GeneralOptions.htm so it will store the values in moi.ini before it calls moi.ui.sidePane.SetAutosaveTimer(); in addition to doing it in the Shutdown() function.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.12 In reply to 11150.11 
Hi Michael! I'm back to you.
I've set everything up as you indicated and it seems to be working fine.
Later it turned out that the Shutdown() function does not run moi.ui.sidePane.SetAutosaveTimer(); in SidePane

This came to light when I changed the theme and my reloaded all the functions. Moi3d gives this error.

What could it be?



  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11150.13 In reply to 11150.12 
Hi Moi3dFan,

re:
> This came to light when I changed the theme and my reloaded all the functions. Moi3d gives this error.
>
> What could it be?

Can you post your GeneralOptions.htm and SidePane.htm files ?

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.14 In reply to 11150.13 
Here you go!

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11150.15 In reply to 11150.14 
Hi Moi3dFan, I guess during a UI reload (when changing the theme) you can get in the situation that SidePane.htm has not finished loading yet while the Shutdown function is running.

So to guard against an error there try changing the last like of function Shutdown() to this:

code:
if ( moi.ui.sidePane && moi.ui.sidePane.SetAutosaveTimer )
    moi.ui.sidePane.SetAutosaveTimer();


- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.16 In reply to 11150.15 
The error no longer occurs. But there is a new one.

The setting only works once. The video shows that at first it was 0, then I changed it to 0.1 minute, everything worked as it should. But when I returned 0 minutes, autosave didn't turn off.

EDITED: 14 Nov 2023 by MOI3DFAN

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
11150.17 In reply to 11150.16 
Hii Moi3dFan, I think maybe you're getting multiple timers going.

Probably the very first thing that should be done inside function SetAutosaveTimer() is to clear any previous timer, by doing:

code:
if ( AutosaveTimer )
{
    clearInterval( AutosaveTimer );
    AutosaveTimer = false;
}


If Autosave is 0 then it's probably better to exit out right after that, currently it sets up a timer and then will clear it out at the end.

So maybe more like this:

code:
				function SetAutosaveTimer()
				{
					// Clear any existing timer.
					if ( AutosaveTimer )
					{
						clearInterval( AutosaveTimer );
						AutosaveTimer = false;
					}

					Autosave = moi.command.getOption( 'Autosave', true); // return autosave time (ms) from ini (180000 = 3 min)
					AutosaveIncremental = moi.command.getOption( 'AutosaveIncremental', true); //return AS mode (false)

					// If Autosave is turned off, exit without setting any timer up.
					if ( Autosave == 0 )
						return;

					AutosaveTimer = setInterval(function() {
						if (AutosaveIncremental) { 
							moi.command.execCommand('IncrementalSave');
						} else { 
							moi.command.execCommand('Save');
						}
					}, Autosave);
				}
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Moi3dFan
11150.18 In reply to 11150.17 
It's working! Thanks, how likely is it that autosave will appear in the native version of moi3d v5 beta?
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
11150.19 In reply to 11150.18 
Hi Moi3dFan,

re:
> It's working! Thanks, how likely is it that autosave will appear in the native version of moi3d v5 beta?

Not too likely, there are a lot of details to work out for a real version of it.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1-6  7-19