diff --git a/api.py b/api.py index c6b0728..b662008 100644 --- a/api.py +++ b/api.py @@ -3,7 +3,6 @@ :doc: https://simperium.com/docs/reference/http/#auth """ -import base64 import functools import json import logging @@ -22,16 +21,11 @@ __all__ = ["Simplenote"] -SIMPLENOTE_APP_ID: str = "chalk-bump-f49" -SIMPLENOTE_APP_KEY: str = base64.b64decode("YzhjMmI4NjMzNzE1NGNkYWJjOTg5YjIzZTMwYzZiZjQ=").decode("utf-8") -SIMPLENOTE_BUCKET: str = "note" - - class URL: BASE: str = "simperium.com/1" AUTH = f"https://auth.{BASE}" - DATA = f"https://api.{BASE}/{SIMPLENOTE_APP_ID}/{SIMPLENOTE_BUCKET}" - __auth = f"{AUTH}/{SIMPLENOTE_APP_ID}/authorize/" + DATA = f"https://api.{BASE}/{CONFIG.SIMPLENOTE_APP_ID}/{CONFIG.SIMPLENOTE_BUCKET}" + __auth = f"{AUTH}/{CONFIG.SIMPLENOTE_APP_ID}/authorize/" __index = DATA + "/index" __retrieve = DATA + "/i/%s" __modify = __retrieve @@ -113,7 +107,7 @@ def authenticate(username: str, password: str): response = request( URL.auth(), method="POST", - headers={"X-Simperium-API-Key": SIMPLENOTE_APP_KEY}, + headers={"X-Simperium-API-Key": CONFIG.SIMPLENOTE_APP_KEY}, data={"username": username, "password": password}, data_as_json=False, ) diff --git a/gui.py b/gui.py index 5732733..cc107e6 100644 --- a/gui.py +++ b/gui.py @@ -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", @@ -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: diff --git a/simplenotecommands.py b/simplenotecommands.py index d7582e9..f2f3e5d 100644 --- a/simplenotecommands.py +++ b/simplenotecommands.py @@ -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 @@ -248,7 +248,6 @@ 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") @@ -256,11 +255,8 @@ def start(): 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