@@ -6,12 +6,15 @@ import classNames from "classnames";
66import { IReactionDisposer , reaction , toJS } from "mobx" ;
77import i18next from 'i18next' ;
88import { USERNAME , isMac } from "../utils/platform" ;
9+ import { hasWSL } from "../utils/wsl" ;
910import Icons from "../constants/icons" ;
1011import { FavoritesState , Favorite } from "../state/favoritesState" ;
1112import { AppState } from "../state/appState" ;
1213import { AppAlert } from "./AppAlert" ;
1314import CONFIG from '../config/appConfig' ;
1415
16+ declare var ENV : any ;
17+
1518require ( "../css/favoritesPanel.css" ) ;
1619
1720interface LeftPanelState {
@@ -32,10 +35,13 @@ interface InjectedProps extends IProps {
3235export class LeftPanelClass extends React . Component < IProps , LeftPanelState > {
3336 favoritesState : FavoritesState ;
3437 disposers :Array < IReactionDisposer > = new Array ( ) ;
38+ // we have to make an async call to check for WSL
39+ // so we first set it to false
40+ showDistributions : boolean = false ;
3541
3642 constructor ( props :IProps ) {
3743 super ( props ) ;
38-
44+
3945 const { t } = props ;
4046
4147 this . state = {
@@ -60,8 +66,32 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
6066
6167 this . favoritesState = this . injected . appState . favoritesState ;
6268
63- this . installReaction ( ) ;
69+ this . installReactions ( ) ;
6470 this . bindLanguageChange ( ) ;
71+ if ( ! ENV . CY ) {
72+ this . checkForWSL ( ) ;
73+ }
74+ }
75+
76+ private checkForWSL = async ( ) : Promise < boolean > => {
77+ console . log ( 'checking for WSL' ) ;
78+ this . showDistributions = await hasWSL ( ) ;
79+ if ( this . showDistributions ) {
80+ console . log ( 'WSL detected' ) ;
81+ const { t } = this . props ;
82+ const { nodes } = this . state ;
83+
84+ nodes . push ( {
85+ id : 2 ,
86+ hasCaret : true ,
87+ isExpanded : true ,
88+ label : t ( 'FAVORITES_PANEL.LINUX' ) ,
89+ childNodes : [ ]
90+ } ) ;
91+
92+ this . setState ( { nodes } ) ;
93+ }
94+ return this . showDistributions ;
6595 }
6696
6797 private bindLanguageChange = ( ) => {
@@ -76,7 +106,7 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
76106 public onLanguageChanged = ( lang : string ) => {
77107 console . log ( 'building nodes' , lang ) ;
78108 this . buildNodes ( this . favoritesState ) ;
79- }
109+ }
80110
81111 private get injected ( ) {
82112 return this . props as InjectedProps ;
@@ -87,7 +117,7 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
87117 this . unbindLanguageChange ( ) ;
88118 }
89119
90- private installReaction ( ) {
120+ private installReactions ( ) {
91121 this . disposers . push ( reaction (
92122 ( ) => toJS ( this . favoritesState . places ) ,
93123 ( _ : Favorite [ ] ) => {
@@ -97,6 +127,16 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
97127 }
98128 } )
99129 ) ;
130+
131+ this . disposers . push ( reaction (
132+ ( ) => toJS ( this . favoritesState . distributions ) ,
133+ ( _ : Favorite [ ] ) => {
134+ if ( ! this . props . hide ) {
135+ console . log ( 'distributions updated: need to rebuild nodes' ) ;
136+ this . buildNodes ( this . favoritesState ) ;
137+ }
138+ } )
139+ ) ;
100140 }
101141
102142 /**
@@ -108,14 +148,16 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
108148 getNodeFromPath ( path :string ) :ITreeNode < string > {
109149 const { nodes } = this . state ;
110150 const shortcuts = nodes [ 0 ] . childNodes ;
151+ const places = nodes [ 1 ] . childNodes ;
111152
112- const found = shortcuts . find ( node => node . nodeData === path ) ;
153+ const found = shortcuts . find ( node => node . nodeData === path ) || places . find ( node => node . nodeData === path ) ;
113154
114- if ( found ) {
155+ if ( found || ! this . showDistributions ) {
115156 return found ;
116157 } else {
117- const places = nodes [ 1 ] . childNodes ;
118- return places . find ( node => node . nodeData === path ) ;
158+
159+ const distribs = nodes [ 2 ] . childNodes ;
160+ return distribs . find ( node => node . nodeData === path ) ;
119161 }
120162 }
121163
@@ -148,7 +190,7 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
148190 if ( sameView ) {
149191 const activeCache = appState . getActiveCache ( ) ;
150192 if ( activeCache && activeCache . status === 'ok' ) {
151- activeCache . cd ( path )
193+ activeCache . cd ( path ) ;
152194 }
153195 } else {
154196 const winState = appState . winStates [ 0 ] ;
@@ -186,6 +228,7 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
186228 const { nodes } = this . state ;
187229 const shortcuts = nodes [ 0 ] ;
188230 const places = nodes [ 1 ] ;
231+ const distributions = nodes [ 2 ] ;
189232
190233 shortcuts . childNodes = favorites . shortcuts . map ( ( shortcut , i ) => ( {
191234 id : `s_${ shortcut . path } ` ,
@@ -205,15 +248,27 @@ export class LeftPanelClass extends React.Component<IProps, LeftPanelState> {
205248 nodeData : place . path
206249 } ) ) ;
207250
251+ if ( this . showDistributions && favorites . distributions ) {
252+ distributions . childNodes = favorites . distributions . map ( ( distrib ) => ( {
253+ id : `p_${ distrib . path } ` ,
254+ key : `p_${ distrib . path } ` ,
255+ label : < span title = { distrib . path } > { distrib . label } </ span > ,
256+ icon : distrib . icon ,
257+ nodeData : distrib . path
258+ } ) ) ;
259+ }
260+
208261 // update root nodes label too
209262 places . label = t ( 'FAVORITES_PANEL.PLACES' ) ;
210263 shortcuts . label = t ( 'FAVORITES_PANEL.SHORTCUTS' ) ;
264+ if ( distributions ) {
265+ distributions . label = t ( 'FAVORITES_PANEL.LINUX' ) ;
266+ }
211267
212268 this . setState ( this . state ) ;
213269 }
214270
215271 render ( ) {
216- console . log ( 'LeftPanel.render' ) ;
217272 const path = this . getActiveCachePath ( ) ;
218273 this . setActiveNode ( path ) ;
219274 const { nodes } = this . state ;
0 commit comments