44const { Gio, GLib } = imports . gi ;
55const Params = imports . misc . params ;
66
7- const GnomeSession = imports . misc . gnomeSession ;
7+ const LoginManager = imports . misc . loginManager ;
88const Main = imports . ui . main ;
99const CinnamonMountOperation = imports . ui . cinnamonMountOperation ;
1010
11- var GNOME_SESSION_AUTOMOUNT_INHIBIT = 16 ;
12-
1311// GSettings keys
1412const SETTINGS_SCHEMA = 'org.cinnamon.desktop.media-handling' ;
1513const SETTING_ENABLE_AUTOMOUNT = 'automount' ;
@@ -20,28 +18,16 @@ var AutomountManager = class {
2018 constructor ( ) {
2119 this . _settings = new Gio . Settings ( { schema_id : SETTINGS_SCHEMA } ) ;
2220 this . _activeOperations = new Map ( ) ;
23-
24- GnomeSession . SessionManager ( ( proxy , error ) => {
25- if ( error )
26- return ;
27-
28- this . _session = proxy ;
29- this . actor . show ( ) ;
30- this . updateStatus ( ) ;
31-
32- this . _session . connectSignal (
33- "InhibitorAdded" ,
34- this . _InhibitorsChanged . bind ( this )
35- ) ;
36-
37- this . _session . connectSignal (
38- "InhibitorRemoved" ,
39- this . _InhibitorsChanged . bind ( this )
40- ) ;
21+ this . _volumeQueue = [ ] ;
22+
23+ this . _loginManager = LoginManager . getLoginManager ( ) ;
24+ this . _loginManager . connect ( 'lock' , ( ) => this . _onScreenLocked ( ) ) ;
25+ this . _loginManager . connect ( 'unlock' , ( ) => this . _onScreenUnlocked ( ) ) ;
26+ this . _loginManager . connect ( 'active-changed' , ( lm , active ) => {
27+ if ( active )
28+ this . _drainVolumeQueue ( ) ;
4129 } ) ;
4230
43- this . _inhibited = false ;
44-
4531 this . _volumeMonitor = Gio . VolumeMonitor . get ( ) ;
4632 this . enable ( ) ;
4733 }
@@ -67,12 +53,21 @@ var AutomountManager = class {
6753 }
6854 }
6955
70- async _InhibitorsChanged ( _object , _senderName , [ _inhibitor ] ) {
71- try {
72- const [ inhibited ] =
73- await this . _session . IsInhibitedAsync ( GNOME_SESSION_AUTOMOUNT_INHIBIT ) ;
74- this . _inhibited = inhibited ;
75- } catch ( e ) { }
56+ _onScreenLocked ( ) {
57+ // Volumes inserted while locked will be queued
58+ }
59+
60+ _onScreenUnlocked ( ) {
61+ this . _drainVolumeQueue ( ) ;
62+ }
63+
64+ _drainVolumeQueue ( ) {
65+ while ( this . _volumeQueue . length > 0 ) {
66+ let volume = this . _volumeQueue . shift ( ) ;
67+ this . _checkAndMountVolume ( volume , {
68+ checkSession : false ,
69+ } ) ;
70+ }
7671 }
7772
7873 _startupMountAll ( ) {
@@ -90,10 +85,8 @@ var AutomountManager = class {
9085 }
9186
9287 _onDriveConnected ( ) {
93- // if we're not in the current ConsoleKit session,
94- // or screensaver is active, don't play sounds
95- // if (!this._session.SessionIsActive)
96- // return;
88+ if ( ! this . _loginManager . sessionIsActive )
89+ return ;
9790
9891 let player = global . display . get_sound_player ( ) ;
9992 player . play_from_theme ( 'device-added-media' ,
@@ -102,10 +95,8 @@ var AutomountManager = class {
10295 }
10396
10497 _onDriveDisconnected ( ) {
105- // if we're not in the current ConsoleKit session,
106- // or screensaver is active, don't play sounds
107- // if (!this._session.SessionIsActive)
108- // return;
98+ if ( ! this . _loginManager . sessionIsActive )
99+ return ;
109100
110101 let player = global . display . get_sound_player ( ) ;
111102 player . play_from_theme ( 'device-removed-media' ,
@@ -114,13 +105,9 @@ var AutomountManager = class {
114105 }
115106
116107 _onDriveEjectButton ( monitor , drive ) {
117- // TODO: this code path is not tested, as the GVfs volume monitor
118- // doesn't emit this signal just yet.
119- // if (!this._session.SessionIsActive)
120- // return;
108+ if ( ! this . _loginManager . sessionIsActive )
109+ return ;
121110
122- // we force stop/eject in this case, so we don't have to pass a
123- // mount operation object
124111 if ( drive . can_stop ( ) ) {
125112 drive . stop ( Gio . MountUnmountFlags . FORCE , null , null ,
126113 ( o , res ) => {
@@ -147,34 +134,28 @@ var AutomountManager = class {
147134 }
148135
149136 _checkAndMountVolume ( volume , params ) {
150- global . log ( "check and mount" ) ;
151137 params = Params . parse ( params , {
152138 checkSession : true ,
153139 useMountOp : true ,
154140 allowAutorun : true ,
155141 } ) ;
156142
157143 if ( params . checkSession ) {
158- // if we're not in the current ConsoleKit session,
159- // don't attempt automount
160- // if (!this._session.SessionIsActive)
161- // return;
162- }
144+ if ( ! this . _loginManager . sessionIsActive )
145+ return ;
163146
164- if ( this . _inhibited )
165- return ;
147+ if ( this . _loginManager . isLocked ) {
148+ this . _volumeQueue . push ( volume ) ;
149+ return ;
150+ }
151+ }
166152
167- // Volume is already mounted, don't bother.
168153 if ( volume . get_mount ( ) )
169154 return ;
170155
171156 if ( ! this . _settings . get_boolean ( SETTING_ENABLE_AUTOMOUNT ) ||
172157 ! volume . should_automount ( ) ||
173158 ! volume . can_mount ( ) ) {
174- // allow the autorun to run anyway; this can happen if the
175- // mount gets added programmatically later, even if
176- // should_automount() or can_mount() are false, like for
177- // blank optical media.
178159 this . _allowAutorun ( volume ) ;
179160 this . _allowAutorunExpire ( volume ) ;
180161
@@ -201,23 +182,15 @@ var AutomountManager = class {
201182 }
202183
203184 _onVolumeMounted ( volume , res ) {
204- global . log ( "on volume mounted" ) ;
205185 this . _allowAutorunExpire ( volume ) ;
206186
207187 try {
208188 volume . mount_finish ( res ) ;
209189 this . _closeOperation ( volume ) ;
210190 } catch ( e ) {
211- // FIXME: we will always get G_IO_ERROR_FAILED from the gvfs udisks
212- // backend, see https://bugs.freedesktop.org/show_bug.cgi?id=51271
213- // To reask the password if the user input was empty or wrong, we
214- // will check for corresponding error messages. However, these
215- // error strings are not unique for the cases in the comments below.
216- if ( e . message . includes ( 'No key available with this passphrase' ) || // cryptsetup
217- e . message . includes ( 'No key available to unlock device' ) || // udisks (no password)
218- // libblockdev wrong password opening LUKS device
191+ if ( e . message . includes ( 'No key available with this passphrase' ) ||
192+ e . message . includes ( 'No key available to unlock device' ) ||
219193 e . message . includes ( 'Failed to activate device: Incorrect passphrase' ) ||
220- // cryptsetup returns EINVAL in many cases, including wrong TCRYPT password/parameters
221194 e . message . includes ( 'Failed to load device\'s parameters: Invalid argument' ) ) {
222195 this . _reaskPassword ( volume ) ;
223196 } else {
@@ -238,6 +211,8 @@ var AutomountManager = class {
238211 GLib . source_remove ( volume . _allowAutorunExpireId ) ;
239212 delete volume . _allowAutorunExpireId ;
240213 }
214+
215+ this . _volumeQueue = this . _volumeQueue . filter ( v => v !== volume ) ;
241216 }
242217
243218 _reaskPassword ( volume ) {
0 commit comments