mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
ebf4cd5c1f
- Remove unnecessary modules - Remove `ts-plugin-namespace-auto-import` as it was a workaround to use the non-conventional `import *` convention - Remove `esbuild-plugin-copy-directories` as it is unuse - Inline modules that are only ever used once - Inline `project-manager-shim` into `gui2` - it is only used during `gui2`'s dev mode - Inline `content-config` into `client` - Flatten `app/ide-desktop/lib/` to `app/ide-desktop/` - Flatten `app/ide-desktop/lib/dashboard/` to `app/dashboard/` # Important Notes - As mentioned above, all remaining modules have been moved up from `app/ide-desktop/lib/` to `app/ide-desktop/`. It's not ideal but I'd rather hold off on moving them anywhere else before we have a consensus on what should go where. - (That is to say, this may not be the final directory structure - but I figure it's fine to get *something* done so that hopefully the rest of the restructuring is simpler.)
79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
/** @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\\Shell Folders',
|
|
'/v',
|
|
'personal',
|
|
],
|
|
{ timeout: CHILD_PROCESS_TIMEOUT },
|
|
)
|
|
|
|
if (out.error !== undefined) {
|
|
return
|
|
} else {
|
|
const stdoutString = out.stdout.toString()
|
|
return stdoutString.split(/\s\s+/)[4]
|
|
}
|
|
}
|