Skip to content

Commit

Permalink
Fix: Improve user experience when settings are not configured
Browse files Browse the repository at this point in the history
Simplify the way the settings file is opened and configure the plugin to show a helpful message to the user when the plugin cannot start because the settings are not configured.
  • Loading branch information
RedAtman committed Jul 31, 2024
1 parent 3ea7309 commit f0d3ee0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 15 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import logging
import os
from typing import Optional

import sublime

from ._config import CONFIG


logger = logging.getLogger()


__all__ = [
"edit_settings",
"show_message",
"remove_status",
"get_view_window",
Expand All @@ -29,6 +33,17 @@
# SETTINGS.add_on_change("password", reload_if_needed)


def edit_settings():
# sublime.run_command("open_file", {"file": CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH})
sublime.run_command(
"edit_settings",
{
"base_file": os.path.join(CONFIG.SIMPLENOTE_PACKAGE_DIR, CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH),
"default": "// Simplenote Settings - User\n{\n\t$0\n}\n",
},
)


def _show_message(message: str = ""):
if not isinstance(message, str):
try:
Expand Down
10 changes: 3 additions & 7 deletions simplenotecommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sublime_plugin

from ._config import CONFIG
from .gui import close_view, open_view, remove_status, show_message
from .gui import close_view, edit_settings, open_view, remove_status, show_message
from .models import Note
from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager
from .simplenote import clear_orphaned_filepaths, on_note_changed
Expand Down Expand Up @@ -248,19 +248,15 @@ def start():
global SIMPLENOTE_STARTED

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

if username and password:
sync()
SIMPLENOTE_STARTED = True
else:
sublime.active_window().open_file(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
show_message(
"Simplenote: Please configure username/password, Please check settings file: %s"
% CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH
)
edit_settings()
show_message("Simplenote: Please configure username/password, Please check settings file.")
sublime.set_timeout(remove_status, 2000)
SIMPLENOTE_STARTED = False
return SIMPLENOTE_STARTED
Expand Down

0 comments on commit f0d3ee0

Please sign in to comment.