<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Jakob,<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 29, 2021 at 5:41 AM Jakob Reschke <<a href="mailto:jakres%2Bsqueak@gmail.com">jakres+squeak@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
Am Do., 23. Dez. 2021 um 13:39 Uhr schrieb Jakob Reschke<br>
<<a href="mailto:jakres%2Bsqueak@gmail.com" target="_blank">jakres+squeak@gmail.com</a>>:<br>
><br>
> [...] we should write default<br>
> preferences to ~/.config/squeak-default-preferences.dat or so when the<br>
> wizard is finished for the first time [...]<br>
><br>
<br>
I just "quickly" wanted to try this out the other day, but it seems<br>
there is no clean way to determine the home directory from a plain<br>
Trunk image without third party packages. Sigh!<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">There is a getenv primitive (but see below on a better solution).  So you can implement this anywhere and use self getenv: 'HOME'</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">getenv: aByteStringOrByteArray<br>    <primitive: 'primitiveGetenv' module: '' error: ec><br>    ec == #'bad argument' ifTrue:<br>        [aByteStringOrByteArray isString ifFalse:<br>            [^self getenv: aByteStringOrByteArray asString]].<br>    self primitiveFail<br></div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
The context: I would like to store some contested preferences<br>
externally in a well-known, stable location, so that when you start a<br>
new image, these preferences are already pre-set in the preference<br>
wizard with your choices from the last time you completed the wizard<br>
in a different image. For example, auto-enclose, enclose selection,<br>
colorful windows, attach tools to mouse cursor, ... That would allow<br>
us to change the default preferences for first-time users without<br>
bothering our veterans with behavior to which they are not accustomed,<br>
and which they first have to turn off in each new image.<br>
<br>
SecurityManager>>#primUntrustedUserDirectory comes closest to the<br>
user's home directory, but on Unix you would have to go up three<br>
directories and on Windows just two. On its own, the SecurityManager<br>
default untrustedUserDirectory does not really adhere to the platform<br>
rules for storing preferences (at least not on Windows). Also it may<br>
be incorrect to use the SecurityManager protocol for this purpose, I<br>
have no experience with it.<br>
<br>
Before I delve too much into getting the home directory, what I really want is<br>
- to access a place where some preferences values could be stored<br>
- without user input (i. e. they should not have to choose a file or<br>
directory first)<br>
- independent of the location of the current image file.<br>
- The place must be writable.<br>
- It must work eventually in a fresh image without extra plugins or<br>
packages loaded.<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">We have a plugin in the Virtend VM that answers the well known folder locations.  I'm happy to move this into VMMaker.</div><div class="gmail_default" style="font-size:small">     Primitive. Query for a common file location.<br>      Arguments:<br>            location: String describing the common file location.<br>      Return value: The path to the designated location.<br>      Known locations:<br>            'home' - the user's home directory<br>            'desktop' - the user's desktop directory<br><br>            'temp' - the temp directory to use<br>            'preferences' - the place to store (per user) app preferences<br>            'applications' - the directory for installing applications<br>            'fonts' - the directory to install fonts in the system<br><br>            'documents' - the users documents folder<br>            'music' - the users default location for music<br>            'pictures' - the users default location for pictures<br>            'videos' - the users default location for videos<br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Ideally the place would adhere to the rules and conventions of the<br>
platform. So if it is a directory to store configuration files:<br>
- On Windows this could be %APPDATA% (e. g. C:\Users\Jakob\AppData\Roaming)<br>
- On Linux this could be $XDG_CONFIG_HOME, with a fallback of $HOME/.config [1]<br>
- On the Mac I don't really know, but according to [2]<br>
$HOME/Library/Preferences might be it.<br>
(In all the cases above, a Squeak subdirectory should be created, of course.)<br>
- SqueakJS in the web browser could arbitrarily define a simulated<br>
directory in the local storage.<br>
- As a last resort, FileDrectory default could be used, although in<br>
general it does not fulfill the requirements (e. g. being indepent of<br>
the image location).<br>
<br>
I suppose it would make sense to implement the lookup of the path in<br>
the VM (or a plugin that is included by default). Otherwise, the<br>
minimum requirement would be that getenv() functionality is available<br>
without installing OSProcess first. It looks like Pharo has done<br>
something like that: `Smalltalk os environment` answers a dictionary<br>
of environment variables and this is used in FileSystem to retrieve<br>
preferences and home directories.<br>
<br>
Alternatively, we could outsource this to the VM completely by<br>
specifying a key-value store protocol of primitives for simple<br>
preferences. Then the VM could even implement it using<br>
platform-specific API (e. g. the Windows Registry, Mac NSUserDefaults<br>
[2]). But I have the feeling that this may not be the most popular<br>
choice in the community. ;-)<br>
<br>
What are your thoughts about the matter?<br>
<br>
[1] <a href="https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html" rel="noreferrer" target="_blank">https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html</a><br>
[2] <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/UserDefaults/AboutPreferenceDomains/AboutPreferenceDomains.html" rel="noreferrer" target="_blank">https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/UserDefaults/AboutPreferenceDomains/AboutPreferenceDomains.html</a><br>
<br>
Kind regards,<br>
Jakob<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>