-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the default location for Enso projects (#10318)
close #10240 Changelog: - add: `desktop-environment` Java module to detect user environment configuration - add: `ProjectsMigration` module containing the migration logic of the enso projects directory - update: updated and cleaned up unused settings from the storage config - add: `desktopEnvironment` TS module to detect user environment configuration in the `project-manager-shim` - update: `project-manager-shim` with the new user projects directory
- Loading branch information
Showing
29 changed files
with
669 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/ide-desktop/lib/project-manager-shim/src/desktopEnvironment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* @file This module contains the logic for the detection of user-specific desktop environment attributes. | ||
*/ | ||
|
||
import * as childProcess from 'node:child_process' | ||
import * as os from 'node:os' | ||
import * as path from 'node:path' | ||
|
||
export const DOCUMENTS = getDocumentsPath() | ||
|
||
const CHILD_PROCESS_TIMEOUT = 3000 | ||
|
||
/** | ||
* Detects path of the user documents directory depending on the operating system. | ||
*/ | ||
function getDocumentsPath(): string | undefined { | ||
if (process.platform === 'linux') { | ||
return getLinuxDocumentsPath() | ||
} else if (process.platform === 'darwin') { | ||
return getMacOsDocumentsPath() | ||
} else if (process.platform === 'win32') { | ||
return getWindowsDocumentsPath() | ||
} else { | ||
return | ||
} | ||
} | ||
|
||
/** | ||
* Returns the user documents path on Linux. | ||
*/ | ||
function getLinuxDocumentsPath(): string { | ||
const xdgDocumentsPath = getXdgDocumentsPath() | ||
|
||
return xdgDocumentsPath ?? path.join(os.homedir(), 'enso') | ||
} | ||
|
||
/** | ||
* Gets the documents directory from the XDG directory management system. | ||
*/ | ||
function getXdgDocumentsPath(): string | undefined { | ||
const out = childProcess.spawnSync('xdg-user-dir', ['DOCUMENTS'], { | ||
timeout: CHILD_PROCESS_TIMEOUT, | ||
}) | ||
|
||
if (out.error !== undefined) { | ||
return | ||
} else { | ||
return out.stdout.toString().trim() | ||
} | ||
} | ||
|
||
/** | ||
* Get the user documents path. On macOS, `Documents` acts as a symlink pointing to the | ||
* real locale-specific user documents directory. | ||
*/ | ||
function getMacOsDocumentsPath(): string { | ||
return path.join(os.homedir(), 'Documents') | ||
} | ||
|
||
/** | ||
* Get the path to the `My Documents` Windows directory. | ||
*/ | ||
function getWindowsDocumentsPath(): string | undefined { | ||
const out = childProcess.spawnSync( | ||
'reg', | ||
[ | ||
'query', | ||
'"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellFolders"', | ||
'/v', | ||
'personal', | ||
], | ||
{ timeout: CHILD_PROCESS_TIMEOUT } | ||
) | ||
|
||
if (out.error !== undefined) { | ||
return | ||
} else { | ||
const stdoutString = out.stdout.toString() | ||
return stdoutString.split('\\s\\s+')[4] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/java/desktop-environment/src/main/java/org/enso/desktopenvironment/Directories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
/** Provides information about user directories. */ | ||
public sealed interface Directories permits LinuxDirectories, MacOsDirectories, WindowsDirectories { | ||
|
||
/** | ||
* @return the user home directory. | ||
*/ | ||
default Path getUserHome() { | ||
return Path.of(System.getProperty("user.home")); | ||
} | ||
|
||
/** | ||
* @return the user documents directory. | ||
* @throws IOException when cannot detect the documents directory of the user. | ||
*/ | ||
Path getDocuments() throws IOException; | ||
} |
28 changes: 28 additions & 0 deletions
28
...ava/desktop-environment/src/main/java/org/enso/desktopenvironment/DirectoriesFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
final class DirectoriesFactory { | ||
|
||
private static final Directories INSTANCE = initDirectories(); | ||
|
||
private static Directories initDirectories() { | ||
if (Platform.isLinux()) { | ||
return new LinuxDirectories(); | ||
} | ||
|
||
if (Platform.isMacOs()) { | ||
return new MacOsDirectories(); | ||
} | ||
|
||
if (Platform.isWindows()) { | ||
return new WindowsDirectories(); | ||
} | ||
|
||
throw new UnsupportedOperationException("Unsupported OS '" + Platform.getOsName() + "'"); | ||
} | ||
|
||
private DirectoriesFactory() {} | ||
|
||
public static Directories getInstance() { | ||
return INSTANCE; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
lib/java/desktop-environment/src/main/java/org/enso/desktopenvironment/LinuxDirectories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
final class LinuxDirectories implements Directories { | ||
|
||
private static final String[] PROCESS_XDG_DOCUMENTS = new String[] {"xdg-user-dir", "DOCUMENTS"}; | ||
|
||
/** | ||
* Get the user 'Documents' directory. | ||
* | ||
* <p>Tries to obtain the documents directory from the XDG directory management system if | ||
* available and falls back to {@code $HOME/enso}. | ||
* | ||
* @return the path to the user documents directory. | ||
*/ | ||
@Override | ||
public Path getDocuments() { | ||
try { | ||
return getXdgDocuments(); | ||
} catch (IOException | InterruptedException e) { | ||
return getUserHome().resolve("enso"); | ||
} | ||
} | ||
|
||
private Path getXdgDocuments() throws IOException, InterruptedException { | ||
var process = new ProcessBuilder(PROCESS_XDG_DOCUMENTS).start(); | ||
process.waitFor(3, TimeUnit.SECONDS); | ||
|
||
var documentsString = | ||
new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); | ||
|
||
return Path.of(documentsString.trim()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/java/desktop-environment/src/main/java/org/enso/desktopenvironment/MacOsDirectories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
final class MacOsDirectories implements Directories { | ||
|
||
private static final String DOCUMENTS = "Documents"; | ||
|
||
/** | ||
* Get the user documents path. | ||
* | ||
* <p>On macOS, the 'Documents' directory acts like a symlink and points to the real | ||
* locale-dependent user documents folder. | ||
* | ||
* @return the path to the user documents directory. | ||
* @throws IOException when unable to resolve the real documents path. | ||
*/ | ||
@Override | ||
public Path getDocuments() throws IOException { | ||
try { | ||
return getUserHome().resolve(DOCUMENTS).toRealPath(); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to resolve real MacOs documents path", e); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/java/desktop-environment/src/main/java/org/enso/desktopenvironment/Platform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
public final class Platform { | ||
|
||
private static final String OS_NAME = "os.name"; | ||
private static final String LINUX = "linux"; | ||
private static final String MAC = "mac"; | ||
private static final String WINDOWS = "windows"; | ||
|
||
private Platform() {} | ||
|
||
public static String getOsName() { | ||
return System.getProperty(OS_NAME); | ||
} | ||
|
||
public static boolean isLinux() { | ||
return getOsName().toLowerCase().contains(LINUX); | ||
} | ||
|
||
public static boolean isMacOs() { | ||
return getOsName().toLowerCase().contains(MAC); | ||
} | ||
|
||
public static boolean isWindows() { | ||
return getOsName().toLowerCase().contains(WINDOWS); | ||
} | ||
|
||
public static Directories getDirectories() { | ||
return DirectoriesFactory.getInstance(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ava/desktop-environment/src/main/java/org/enso/desktopenvironment/WindowsDirectories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
final class WindowsDirectories implements Directories { | ||
|
||
private static final String[] PROCESS_REG_QUERY = | ||
new String[] { | ||
"reg", | ||
"query", | ||
"\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellFolders\"", | ||
"/v", | ||
"personal" | ||
}; | ||
|
||
/** | ||
* Get the path to 'My Documents' user directory. | ||
* | ||
* <p>Method uses the registry query that may not work on Windows XP versions and below. | ||
* | ||
* @return the 'My Documents' user directory path. | ||
* @throws IOException when fails to detect the user documents directory. | ||
*/ | ||
@Override | ||
public Path getDocuments() throws IOException { | ||
try { | ||
var process = new ProcessBuilder(PROCESS_REG_QUERY).start(); | ||
process.waitFor(3, TimeUnit.SECONDS); | ||
|
||
var stdoutString = | ||
new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); | ||
var stdoutParts = stdoutString.split("\\s\\s+"); | ||
if (stdoutParts.length < 5) { | ||
throw new IOException("Invalid Windows registry query output: '" + stdoutString + "'"); | ||
} | ||
|
||
return Path.of(stdoutParts[4].trim()); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to run Windows registry query", e); | ||
} catch (InterruptedException e) { | ||
throw new IOException("Windows registry query timeout", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.