mathe00 / obsidian-plugin-python-bridge

Develop Obsidian plugins in Python! 🐍 Interact with your notes, retrieve frontmatter, send notifications, and much more – all through simple Python scripts. Cut the complexity of writing JavaScript plugins and dive into creating your Obsidian workflows with Python!
MIT License
45 stars 1 forks source link

Handle multiple Obsidian instances to avoid socket conflicts when using multiple vaults #2

Open mathe00 opened 1 month ago

mathe00 commented 1 month ago

When multiple instances of Obsidian are opened simultaneously (e.g., when working with multiple vaults), socket conflicts can occur, potentially leading to unexpected behavior.

Problem:

Proposed Solutions:

  1. Port Scanning for Available Sockets:

    • Upon launching a new instance, the plugin could scan for available ports in a defined range. If the default socket is in use, it could dynamically bind to the next available port.
    • This ensures that each instance operates on a different port without conflicts.
  2. Instance ID and Socket Assignment:

    • Each vault instance could be assigned a unique ID, and the plugin would append this ID to the socket name.
    • This method avoids port collisions and simplifies instance identification.
  3. Centralized Socket Management:

    • Implement a centralized socket manager that runs on the first instance of Obsidian. Other instances would communicate through this central manager to avoid direct socket conflicts.
    • This would allow all instances to share the same communication channel without direct socket handling.
  4. User Notification and Recovery:

    • If a socket conflict is detected, show a notification to the user, allowing them to choose whether to retry with a different port or abort the operation.
    • This improves user experience by providing transparency and control over the situation.

Additional Considerations:

This feature would greatly improve the user experience when managing multiple Obsidian instances, particularly for those who work with multiple vaults simultaneously.

mathe00 commented 1 month ago

Hey everyone,

I’ve been struggling with this issue for a while (disclaimer: I'm not a JS developer 😅) and I’ve been trying to get it done with ChatGPT’s help. I’ve almost got it working, but the code ended up messy and unorganized. So I figured it would be better to let an experienced dev handle it properly.

What I need:

If anyone could help implement this cleanly into the code, that would be fantastic! I’ve almost got there, but it’s pretty cracra now and not production-ready.

Thanks in advance!