designSpaceRoboFontExtension icon indicating copy to clipboard operation
designSpaceRoboFontExtension copied to clipboard

Can DSE2 look for and warn about older DSE installs?

Open LettError opened this issue 11 months ago • 5 comments

Leaving the older DSE in the plugins folder causes problems. Maybe DSE2 could check if the old one is still there. This finds the folder and counts the DSE plugins. It doesn't take any other steps. I don't thin extensions should be able to disable other extensions. But maybe it can open a dialog with instructions and open a Finder window on the Plugins..

# try to count the designspaceditor extensions in the RoboFont plugins folder.

from pathlib import Path

appSupport = "Application Support"

import sys
import os, glob

plugsinsDir = None
dsePaths = []

for s in sys.path:
    if appSupport in s:
        if 'plugins' in s:
            plugsinsDir = Path(s[:s.index('plugins')+len('plugins')])
            break

if plugsinsDir.exists():
    pattern = plugsinsDir.joinpath("*.roboFontExt").as_posix()
    for extPath in glob.glob(pattern):
        if "DesignspaceEditor" in extPath:
            dsePaths.append(Path(extPath))
else:
    print(f"Can't find plugsinsDir at {plugsinsDir}")
    
if len(dsePaths) > 1:
    print(f"Multiple DesignspaceEditors installed in {plugsinsDir}")
    for item in dsePaths:
        print(f'\t{item.name}')

LettError avatar Feb 12 '25 20:02 LettError

More compact, same goal:

from pathlib import Path
import glob
from mojo.extensions import ExtensionBundle
DSEBundle = ExtensionBundle("DesignspaceEditor2")

dsePath = Path(DSEBundle.path)
pattern = dsePath.parents[0].joinpath("DesignspaceEditor*")

editors = glob.glob(pattern.as_posix())
if len(editors) > 1:
    print("Multiple DesignspaceEditor extensions installed:")
    for edPath in editors:
        print(edPath)

LettError avatar Feb 13 '25 07:02 LettError

This should already happen: https://github.com/LettError/designSpaceRoboFontExtension/blob/8b4765741503b13c1c760babac1acab7a344c5d2/DesignspaceEditor2.roboFontExt/lib/install.py#L15

typemytype avatar Feb 13 '25 08:02 typemytype

But it doesn't reliably work because we have a question in Discord where the old DesignspaceEditor was also installed, but no warnings were presented.

If I install an old DesignspaceEditor (2022) next to the current model, and restart RF, this is printed to output:

********************
Installing 'DesignSpaceEdit' report:
  Traceback (most recent call last):
      File "addDesignSpaceFileHandler.py", line 3, in <module>
      File "/Users/erik/Library/Application Support/RoboFont/plugins/DesignSpaceEditor.roboFontExt/lib/designSpaceEditorwindow.py", line 67, in <module>
    TypeError: ExtensionBundle.__init__() got an unexpected keyword argument 'resourcesName'
  
********************

This is similar to the output in the report on Discord. But no messages are posted.

LettError avatar Feb 13 '25 08:02 LettError

Could it be: DesignSpaceEdit has a traceback while installing. Therefor it doesn't fully come to life, and then there is nothing for ExtensionBundle to find?

Even with the old DesignspaceEdit installed, this gives me None: oldBundle = ExtensionBundle("DesignspaceEdit")

Nope. Hang on.

LettError avatar Feb 13 '25 08:02 LettError

from pathlib import Path
import glob
from mojo.extensions import ExtensionBundle
DSEBundle = ExtensionBundle("DesignspaceEditor2")

dsePath = Path(DSEBundle.path)
pattern = dsePath.parents[0].joinpath("Design*")

editors = glob.glob(pattern.as_posix())
if len(editors) > 1:
    print("Multiple DesignspaceEditor extensions installed:")
    for edPath in editors:
        print(f'\t{edPath}')
        
# this is how DSE2 tries to detect the old one. 
oldBundle = ExtensionBundle("DesignspaceEditor")
print('oldBundle', oldBundle, oldBundle.bundleExists())

if oldBundle.bundleExists():
    from vanilla.dialogs import message
    message(
        "Found older version of Designspace edit.",
        "An old version of Designspace edit is still installed. This can cause issues while opening designspace files."
    )
Multiple DesignspaceEditor extensions installed:
	/Users/erik/Library/Application Support/RoboFont/plugins/DesignspaceEditor2.roboFontExt
	/Users/erik/Library/Application Support/RoboFont/plugins/DesignSpaceEditor.roboFontExt
oldBundle <ExtensionBundle: DesignSpaceEdit> True

LettError avatar Feb 13 '25 09:02 LettError