diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/preferences.ts | 42 | ||||
| -rw-r--r-- | src/renderer.ts | 30 | ||||
| -rw-r--r-- | src/systemLevelInformation.ts | 5 |
3 files changed, 68 insertions, 9 deletions
diff --git a/src/preferences.ts b/src/preferences.ts new file mode 100644 index 0000000..ea8ae64 --- /dev/null +++ b/src/preferences.ts @@ -0,0 +1,42 @@ +// import * as Store from 'electron-store'; +import systemLevelInformation from './systemLevelInformation'; + +class Preferences { + + + getFavourites(): { text: string, path: string, icon: string }[] { + if (localStorage.getItem('favourites')) { + return JSON.parse(localStorage.getItem('favourites')) as { text: string, path: string, icon: string }[]; + } else { + switch (systemLevelInformation.getUserInfo().platform) { + case 'darwin': + const userPath: string = `/Users/${systemLevelInformation.getUserInfo().username}`; + const favourites: { text: string, path: string, icon: string }[] = [ + { text: 'Applications', path: '/Applications', icon: 'icofont-brand-appstore' }, + { text: 'Desktop', path: `${userPath}/Desktop`, icon: 'icofont-computer' }, + { text: 'Documents', path: `${userPath}/Documents`, icon: 'icofont-file-document' }, + { text: 'Movies', path: `${userPath}/Movies`, icon: 'icofont-movie' }, + { text: 'Music', path: `${userPath}/Music`, icon: 'icofont-music-disk' }, + { text: 'Pictures', path: `${userPath}/Pictures`, icon: 'icofont-image' }, + { text: systemLevelInformation.getUserInfo().username, path: `${userPath}`, icon: 'icofont-home' }, + ]; + localStorage.setItem('favourites', JSON.stringify(favourites)); + return favourites; + default: + return []; + } + } + } + + getConfiguredPathToDisplayAfterAppInit(): string { + if (localStorage.getItem('appStartPath')) { + return localStorage.getItem('appStartPath'); + } else { + localStorage.setItem('appStartPath', `/Users/${systemLevelInformation.getUserInfo().username}`); + return localStorage.getItem('appStartPath'); + } + } + +} + +export default new Preferences; diff --git a/src/renderer.ts b/src/renderer.ts index d3a21bc..33cfdef 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -1,12 +1,28 @@ import systemLevelInformation from './systemLevelInformation'; +import Preferences from './Preferences'; -// Listing Files in Home Directory +// List all the favourites -const currentHomeDir: string = systemLevelInformation.getUserInfo().homedir; -document.getElementById('username').innerHTML = systemLevelInformation.getUserInfo().username; +Preferences.getFavourites().forEach(favourite => { + const favourites = document.getElementById('favourites'); + const listElement = document.createElement('li'); + const iconElement = document.createElement('i'); + iconElement.classList.add(favourite.icon); + listElement.appendChild(iconElement); + const spanElement = document.createElement('span'); + spanElement.innerHTML = favourite.text; + listElement.appendChild(spanElement); + listElement.setAttribute('path', favourite.path); + if (Preferences.getConfiguredPathToDisplayAfterAppInit() === favourite.path) { + listElement.classList.add('selected'); + displayDirectoryViaElement(listElement); + } + favourites.appendChild(listElement); +}); -// This variable will keep track of current path -var currentDirectoryPath: string = currentHomeDir; - -const currentHomeFolders: any = systemLevelInformation.getAllFilesOfDirectory(currentHomeDir); +function displayDirectoryViaElement(element: HTMLElement) { + // Listing Files in the Directory + const currentFolders: any = systemLevelInformation.getAllFilesOfDirectory(element.getAttribute('path')); + console.log(currentFolders); +} diff --git a/src/systemLevelInformation.ts b/src/systemLevelInformation.ts index e902d32..43edcc9 100644 --- a/src/systemLevelInformation.ts +++ b/src/systemLevelInformation.ts @@ -5,10 +5,11 @@ import { extname, basename } from 'path'; class systemLevelInformation { - getUserInfo(): { username: string, homedir: string } { + getUserInfo(): { username: string, homedir: string, platform: string } { return { username: os.userInfo().username, - homedir: os.userInfo().homedir + homedir: os.userInfo().homedir, + platform: os.platform() }; } |
