Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have Leo self register with operating system (create menu links, icons, etc) #1012

Closed
6 tasks done
maphew opened this issue Nov 4, 2018 · 12 comments
Closed
6 tasks done
Assignees
Labels
Enhancement Pip Related to distribution

Comments

@maphew
Copy link
Member

maphew commented Nov 4, 2018

Windows

Linux: see #1246

Current Status - Windows

2019-10-09
Functionally complete (modulo a bug I just found).

2019-07-30
Integrated into Settings menu as "Open Desktop Integration Leo", which creates two buttons in the menu bar, which carry out the actions described below. There's no logic to distinguish between OS yet, so the menu shows on Linux and Mac also.

2019-02-27
Register and Unregister now work a) from Leo GUI, b) from Leo command line, and c) from straight python :-) 👍

Leo GUI:

  • Run Leo >> Open specific Leo file >> scripts.leo >> Find "Windows only scripts" node* >> select @file win-register-leo.leox >> Execute script (Ctrl-B)

* Current node location, subject to change: .../leo-editor/leo/scripts/scripts.leo#Scripts-->@file leoScripts.txt-->Command-line scripts-->Windows-only scripts

Leo script:

> leo-m --script=..\scripts\win-register-leo.leox
      # broken! will open new bug
> leo-m --script leo\scripts\add-desktop-links.leox
      # works

Python:

> python .\leo-editor\leo\scripts\win\register-leo.leox
  --- Running register-leo Leo script
  No admin privileges
  --- Relaunching and asking for elevated permissions
  ---
  --- end of script

> python .\leo-editor\leo\scripts\add-desktop-links.leox
  ----- Running add-desktop-links -----
  Created shortcut 'Leo Editor.lnk' in:
     D:\Matt\Desktop
     C:\Users\Matt\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
@maphew maphew self-assigned this Nov 4, 2018
@maphew

This comment has been minimized.

@edreamleo
Copy link
Member

edreamleo commented Nov 5, 2018 via email

@edreamleo edreamleo added the Pip Related to distribution label Jan 20, 2019
maphew added a commit that referenced this issue Feb 14, 2019
Relaunching doesn't work yet. I expect because this pattern is expecting
to be run from the parent exe process, but in this case we're running
from inside Leo.

#1012

Leo build: 20190213233241
@maphew
Copy link
Member Author

maphew commented Feb 14, 2019

Part way there. I've adjusted register-leo.leox for py3 and fixed a unicode escape error. Next up is to relaunch the script with admin privileges. The relaunch attempt fires but fails because we don't have the path to script correct.

--- Running register-leo Leo script
Re-run the program with admin rights...
exception executing script
NameError: name '__file__' is not defined

--------------------
   line 122:     g.es("Re-run the program with admin rights...")
* line 123:     ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
   line 124: 
   line 125: 

maphew added a commit that referenced this issue Feb 15, 2019
created branch `desktop-links` to keep maybe-not-working as well as
possibly-dangerous scripts out of everyone else's way. Part of #1012.

Leo build: 20190214234013
@maphew
Copy link
Member Author

maphew commented Feb 15, 2019

Created branch desktop-links to keep maybe-not-working as well as possibly-dangerous scripts out of everyone else's way.

__file__ not found was addressed by writing contents of g.app.scriptDict['script2'] to a temp file. We then attempt to run that exported script with elevated permissions, but that block of the script isn't firing for some reason.

Side notes:

  • leo --script {path} always creates a full path starting with path\to\leo\core, so you need to pass {path} relative to that (see next point). This is probably a bug.
  • g.app.scriptDict doesn't get populated when run from command line with leo ..\scripts\register-leo.leox. It's only populated when run from inside Leo with execute-script ([ctrl-b])

@maphew
Copy link
Member Author

maphew commented Feb 16, 2019

With today's work culminating in commit 5f3c569 win-register-leo and win-unregister-leo scripts work again. After registration:

  • .leo files use Leo's icon
  • 2x-clicking something.leo launches Leo and opens that file

Example output when running as normal user:

--- Running register-leo Leo script
No admin privileges. Start Leo as administrator first and then run this script
--- end of script

And after starting as Administrator:

--- Running register-leo Leo script
Attempting to register leo filetype with Windows...
  Python: c:\apps\miniconda3\envs\leo-dev\pythonw.exe
  Leo: C:/Users/mattw/code/leo-editor/launchLeo.py
  Found: C:/Users/mattw/code/leo-editor/leo\Icons\LeoDoc.ico
  Registered!
  .leo, .leox files associated as 'Leo.File'
--- end of script

and

--- Running unregister-leo Leo script
  Attempting to un-register leo filetype with Windows...
  Leo file type has been removed from registry
  .leo, .leox file associations removed from registry
--- end of script

Caveats:

  • Leo must be started as Administrator
  • They must be run from a source checkout (so not from a pip install unless was installed with --editable. This is because the scripts assume launchLeo.py which doesn't exist outside of a source checkout.)
  • They don't work as command line scripts, leo --script leo\scripts\win-register-leo.leox. They did a few years ago. I don't know why yet.

@edreamleo
Copy link
Member

edreamleo commented Feb 17, 2019 via email

@maphew
Copy link
Member Author

maphew commented Feb 22, 2019

With bb0e6bb incomplete works in progress and scrap is removed.

I've rediscovered the elevate.py which I put there years ago and is better than all the similar crap I've been doing lately(!). All it needed was a unicode bug fix, though that one did take awhile to identify.

The (un)register scripts do work from the command line, but the command line needs to be crafted properly. I'll document that soon. I'm hoping to get a fully working "request elevation from inside Leo" recipe first.

Register now works for both source code checkout and pip installed Leo.

@maphew
Copy link
Member Author

maphew commented Feb 28, 2019

Register and Unregister now work a) from Leo GUI, b) from Leo command line, and c) from straight python :-) 👍

Python:
python .\leo-editor\leo\scripts\win-register-leo.leox

Leo script:
leo-messages.exe --script=..\scripts\win-register-leo.leox

--Script path must be relative to leo-editor\leo\core NOT the filesystem (a bug in Leo core I think).

Leo GUI:

  • Run Leo >> Open specific Leo file >> scripts.leo >> Find "Windows only scripts" node* >> select @file win-register-leo.leox >> Execute script (Ctrl-B)

* Current node location, subject to change: .../leo-editor/leo/scripts/scripts.leo#Scripts-->@file leoScripts.txt-->Command-line scripts-->Windows-only scripts


Expected results

(leo-dev) matt@ENV-SURFACE-MHW C:\Users\mattw\code\leo-editor
> python leo\scripts\win-register-leo.leox
--- Running register-leo Leo script
No admin privileges. Start Leo as administrator first and then run this script 
--- end of script
matt@ENV-SURFACE-MHW C:\Users\mattw\code
$ c:\apps\miniconda3\envs\leo-dev\python leo-editor\leo\scripts\win-register-leo.leox
--- Running register-leo Leo script
Attempting to register leo filetype with Windows...
  Python: c:\apps\miniconda3\envs\leo-dev\pythonw.exe
  Leo: c:\apps\miniconda3\envs\leo-dev\Scripts\leo.exe
  Found: c:\users\mattw\code\leo-editor\leo\Icons\LeoDoc.ico
  Registered!
  .leo, .leox files associated as 'Leo.File'
--- end of script

matt@ENV-SURFACE-MHW C:\Users\mattw\code
$ c:\apps\miniconda3\envs\leo-dev\python leo-editor\leo\scripts\win-unregister-leo.leox
--- Running unregister-leo Leo script
  Attempting to un-register leo filetype with Windows...
  Leo file type has been removed from registry
  .leo, .leox file associations removed from registry
--- end of script

matt@ENV-SURFACE-MHW C:\Users\mattw\code
$ c:\apps\miniconda3\envs\leo-dev\Scripts\leo-m.exe --script=..\scripts\win-register-leo.leox

Leo 5.8.1-b2 devel, build 20190222005157, Fri Feb 22 00:51:57 PST 2019
--- Running register-leo Leo script
Attempting to register leo filetype with Windows...
  Python: c:\apps\miniconda3\envs\leo-dev\pythonw.exe
  Leo: c:\apps\miniconda3\envs\leo-dev\Scripts\leo.exe
  Found: c:\users\mattw\code\leo-editor\leo\Icons\LeoDoc.ico
  Registered!
  .leo, .leox files associated as 'Leo.File'

Remaining to-do before complete: Request elevation prompt when running from Leo gui.

Pushed in b5017f6

maphew added a commit that referenced this issue Feb 28, 2019
almost done #1012

Leo build: 20190227233831
maphew added a commit that referenced this issue Mar 5, 2019
part of #1012. We could just ship like this, it works, but it has too
many files/nodes for my taste. There's got to be a better way of
combining them. Maybe all into a module?

Leo build: 20190305052933
maphew added a commit that referenced this issue Mar 14, 2019
So now both register and unregister work, and we no longer require the
user to manually launch Leo or a CMD shell as administrator. Leo prompts
for elevation at run time.

What's not good: we're using cross-file clones between the scripts
because of the shared request elevation and related code. Have to figure
out how to combine these into a single script, or maybe even move into
Leo itself(?)

Part of #1012

Leo build: 20190314011223
@maphew
Copy link
Member Author

maphew commented Mar 14, 2019

With b380d72 there's no longer a need to manually launch Leo or a command shell as administrator. Yay!

The prompt for elevation from just python on the command line does not work. I haven't dug into it because now that we can fire from inside Leo it's less necessary. There's room for refactoring: there are duplicate functions across the scripts in cross-file clones.

@maphew
Copy link
Member Author

maphew commented Jul 11, 2019

I created sub-issues removed Milestone marker for this parent one. So the components can have different milestones.

@maphew
Copy link
Member Author

maphew commented Jul 30, 2019

updated current status note.

@maphew
Copy link
Member Author

maphew commented Oct 9, 2019

This is functionally complete for Windows and half there for Linux (lightly tested) so I'm going to close. I wish for a nicer looking way to describe and use the scripts but changing UI would be a much bigger project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Pip Related to distribution
Projects
None yet
Development

No branches or pull requests

2 participants