Skip to content

Commit

Permalink
Fix: Initial sync when loading the plugin
Browse files Browse the repository at this point in the history
Initial sync is now performed when the plugin is loaded, removing the need for manual triggering. The plugin also now correctly logs the number of loaded notes.
  • Loading branch information
RedAtman committed Aug 3, 2024
1 parent 02cfb26 commit 8ee3ae2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 5 additions & 1 deletion lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def sync(sync_interval: int = 30):


def start():
global_storage.optimistic_update(CONFIG.SIMPLENOTE_STARTED_KEY, False)
global_storage.optimistic_update(CONFIG.SIMPLENOTE_SYNC_TIMES_KEY, 0)

settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
username = settings.get("username")
password = settings.get("password")

if username and password:
if global_storage.get(CONFIG.SIMPLENOTE_SYNC_TIMES_KEY) != 0:
return
Expand All @@ -65,8 +67,10 @@ def start():
return
if sync_interval <= 0:
return
logger.debug(("Loaded notes number: ", Note.tree.count))
sync(sync_interval)
return

show_message("Simplenote: Please configure username/password in settings file.")
edit_settings()
sublime.set_timeout(remove_status, 2000)
Expand Down
13 changes: 1 addition & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
import sublime

from ._config import CONFIG
from .lib.core import GlobalStorage, show_message, start
from .lib.models import Note
from .lib.core import show_message, start


logger = logging.getLogger()


global_storage = GlobalStorage()
global_storage.optimistic_update(CONFIG.SIMPLENOTE_STARTED_KEY, False)
global_storage.optimistic_update(CONFIG.SIMPLENOTE_SYNC_TIMES_KEY, 0)


def reload_if_needed():
# global SIMPLENOTE_RELOAD_CALLS

Expand All @@ -36,12 +30,7 @@ def reload_if_needed():

def plugin_loaded():
# load_notes()
logger.debug(("Loaded notes number: ", Note.tree.count))

settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
# logger.debug(("SETTINGS.__dict__: ", SETTINGS.__dict__))
# logger.debug(("SETTINGS.username: ", SETTINGS.get("username")))

settings.clear_on_change("username")
settings.clear_on_change("password")
settings.add_on_change("username", reload_if_needed)
Expand Down

0 comments on commit 8ee3ae2

Please sign in to comment.