Skip to content

Commit e120319

Browse files
committed
cinnamon-launcher: Add csd-automount to fallback helpers.
1 parent 8cd67e3 commit e120319

3 files changed

Lines changed: 89 additions & 61 deletions

File tree

data/theme/cinnamon-sass/widgets/_dialogs.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,7 @@
200200
}
201201
}
202202
}
203+
204+
.autorun-dialog {
205+
min-width: 40em;
206+
}

files/usr/bin/cinnamon-launcher

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Launcher:
7373

7474
self.polkit_agent_proc = None
7575
self.nm_applet_proc = None
76+
self.automount_proc = None
7677
self.can_restart = False
7778
self.dialog = None
7879

@@ -161,6 +162,10 @@ class Launcher:
161162
print(f"Launching for fallback session: nm-applet")
162163
self.nm_applet_proc = subprocess.Popen(["nm-applet"])
163164

165+
if shutil.which("csd-automount"):
166+
print(f"Launching for fallback session: csd-automount")
167+
self.automount_proc = subprocess.Popen(["csd-automount"])
168+
164169
def kill_fallback_helpers(self):
165170
if self.polkit_agent_proc is not None:
166171
print("Killing fallback polkit agent")
@@ -180,6 +185,15 @@ class Launcher:
180185
self.nm_applet_proc.kill()
181186
self.nm_applet_proc = None
182187

188+
if self.automount_proc is not None:
189+
print("Killing fallback csd-automount")
190+
self.automount_proc.terminate()
191+
try:
192+
self.automount_proc.wait(timeout=5)
193+
except subprocess.TimeoutExpired:
194+
self.automount_proc.kill()
195+
self.automount_proc = None
196+
183197
@async_function
184198
def monitor_memory(self):
185199
if psutil.pid_exists(self.cinnamon_pid):

js/ui/autorunManager.js

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const CheckBox = imports.ui.checkBox;
77
const Dialog = imports.ui.dialog;
88
const ModalDialog = imports.ui.modalDialog;
99

10-
Gio._promisify(Gio.Mount.prototype, 'guess_content_type');
11-
1210
const hotplugSnifferIface =
1311
' \
1412
<node> \
@@ -40,7 +38,7 @@ const AUTORUN_ITEM_APP = 0;
4038
const AUTORUN_ITEM_OPEN_FOLDER = 1;
4139
const AUTORUN_ITEM_DO_NOTHING = 2;
4240

43-
var LIST_ITEM_ICON_SIZE = 24;
41+
var LIST_ITEM_ICON_SIZE = 36;
4442

4543
function shouldAutorunMount(mount) {
4644
let root = mount.get_root();
@@ -86,36 +84,36 @@ function startAppForMount(app, mount) {
8684
}
8785

8886
function _getMediaGreeting(contentType) {
89-
if (contentType === 'x-content/audio-cdda')
90-
return _("You have just inserted an Audio CD.");
91-
if (contentType === 'x-content/audio-dvd')
92-
return _("You have just inserted an Audio DVD.");
93-
if (contentType === 'x-content/video-dvd')
94-
return _("You have just inserted a Video DVD.");
95-
if (contentType === 'x-content/video-vcd')
96-
return _("You have just inserted a Video CD.");
97-
if (contentType === 'x-content/video-svcd')
98-
return _("You have just inserted a Super Video CD.");
99-
if (contentType === 'x-content/blank-cd')
100-
return _("You have just inserted a blank CD.");
101-
if (contentType === 'x-content/blank-dvd')
102-
return _("You have just inserted a blank DVD.");
103-
if (contentType === 'x-content/blank-bd')
104-
return _("You have just inserted a blank Blu-Ray disc.");
105-
if (contentType === 'x-content/blank-hddvd')
106-
return _("You have just inserted a blank HD DVD.");
107-
if (contentType === 'x-content/image-photocd')
108-
return _("You have just inserted a Photo CD.");
109-
if (contentType === 'x-content/image-picturecd')
110-
return _("You have just inserted a Picture CD.");
111-
if (contentType === 'x-content/image-dcf')
112-
return _("You have just inserted a medium with digital photos.");
113-
if (contentType === 'x-content/audio-player')
114-
return _("You have just inserted a digital audio player.");
115-
if (contentType && Gio.content_type_is_a(contentType, 'x-content/software'))
116-
return _("You have just inserted a medium with software intended to be automatically started.");
117-
118-
return _("You have just inserted a medium.");
87+
// if (contentType === 'x-content/audio-cdda')
88+
// return _("You have just inserted an Audio CD.");
89+
// if (contentType === 'x-content/audio-dvd')
90+
// return _("You have just inserted an Audio DVD.");
91+
// if (contentType === 'x-content/video-dvd')
92+
// return _("You have just inserted a Video DVD.");
93+
// if (contentType === 'x-content/video-vcd')
94+
// return _("You have just inserted a Video CD.");
95+
// if (contentType === 'x-content/video-svcd')
96+
// return _("You have just inserted a Super Video CD.");
97+
// if (contentType === 'x-content/blank-cd')
98+
// return _("You have just inserted a blank CD.");
99+
// if (contentType === 'x-content/blank-dvd')
100+
// return _("You have just inserted a blank DVD.");
101+
// if (contentType === 'x-content/blank-bd')
102+
// return _("You have just inserted a blank Blu-Ray disc.");
103+
// if (contentType === 'x-content/blank-hddvd')
104+
// return _("You have just inserted a blank HD DVD.");
105+
// if (contentType === 'x-content/image-photocd')
106+
// return _("You have just inserted a Photo CD.");
107+
// if (contentType === 'x-content/image-picturecd')
108+
// return _("You have just inserted a Picture CD.");
109+
// if (contentType === 'x-content/image-dcf')
110+
// return _("You have just inserted a medium with digital photos.");
111+
// if (contentType === 'x-content/audio-player')
112+
// return _("You have just inserted a digital audio player.");
113+
// if (contentType && Gio.content_type_is_a(contentType, 'x-content/software'))
114+
// return _("You have just inserted a medium with software intended to be automatically started.");
115+
116+
return _("Media inserted");
119117
}
120118

121119
function _setAutorunPreferences(contentType, startApp, ignore, openFolder) {
@@ -149,25 +147,41 @@ var ContentTypeDiscoverer = class {
149147
this._settings = new Gio.Settings({ schema_id: SETTINGS_SCHEMA });
150148
}
151149

152-
async guessContentTypes(mount) {
150+
guessContentTypes(mount, callback) {
153151
let autorunEnabled = !this._settings.get_boolean(SETTING_DISABLE_AUTORUN);
154152
let shouldScan = autorunEnabled && !isMountNonLocal(mount);
155153

156-
let contentTypes = [];
157-
if (shouldScan) {
154+
if (!shouldScan) {
155+
callback([], []);
156+
return;
157+
}
158+
159+
mount.guess_content_type(false, null, (mount, res) => {
160+
let contentTypes = [];
161+
158162
try {
159-
contentTypes = await mount.guess_content_type(false, null);
163+
contentTypes = mount.guess_content_type_finish(res);
160164
} catch (e) {
161165
log(`Unable to guess content types on added mount ${mount.get_name()}: ${e}`);
162166
}
163167

164168
if (contentTypes.length === 0) {
165-
const root = mount.get_root();
166-
const hotplugSniffer = new HotplugSniffer();
167-
[contentTypes] = await hotplugSniffer.SniffURIAsync(root.get_uri());
169+
let root = mount.get_root();
170+
let hotplugSniffer = new HotplugSniffer();
171+
hotplugSniffer.SniffURIRemote(root.get_uri(), (result, error) => {
172+
if (!error && result)
173+
contentTypes = result[0] || [];
174+
175+
this._resolveApps(contentTypes, callback);
176+
});
177+
return;
168178
}
169-
}
170179

180+
this._resolveApps(contentTypes, callback);
181+
});
182+
}
183+
184+
_resolveApps(contentTypes, callback) {
171185
contentTypes = contentTypes.filter(
172186
type => type !== 'x-content/win32-software');
173187

@@ -179,7 +193,7 @@ var ContentTypeDiscoverer = class {
179193
apps.push(app);
180194
});
181195

182-
return [apps, contentTypes];
196+
callback(apps, contentTypes);
183197
}
184198
};
185199

@@ -202,22 +216,22 @@ var AutorunManager = class {
202216
this._volumeMonitor.disconnectObject(this);
203217
}
204218

205-
async _onMountAdded(monitor, mount) {
219+
_onMountAdded(monitor, mount) {
206220
if (!shouldAutorunMount(mount))
207221
return;
208222

209223
const discoverer = new ContentTypeDiscoverer();
210-
const [apps, contentTypes] = await discoverer.guessContentTypes(mount);
224+
discoverer.guessContentTypes(mount, (apps, contentTypes) => {
225+
log(`autorunManager: mount=${mount.get_name()} contentTypes=[${contentTypes}] apps=[${apps.map(a => a.get_name())}]`);
211226

212-
log(`autorunManager: mount=${mount.get_name()} contentTypes=[${contentTypes}] apps=[${apps.map(a => a.get_name())}]`);
213-
214-
if (apps.length === 0) {
215-
if (this._settings.get_boolean(SETTING_AUTOMOUNT_OPEN))
216-
this._openFolderForMount(mount);
217-
return;
218-
}
227+
if (apps.length === 0) {
228+
if (this._settings.get_boolean(SETTING_AUTOMOUNT_OPEN))
229+
this._openFolderForMount(mount);
230+
return;
231+
}
219232

220-
this._dispatcher.addMount(mount, apps, contentTypes);
233+
this._dispatcher.addMount(mount, apps, contentTypes);
234+
});
221235
}
222236

223237
_openFolderForMount(mount) {
@@ -276,9 +290,6 @@ var AutorunDispatcher = class {
276290
if (this._settings.get_boolean(SETTING_DISABLE_AUTORUN))
277291
return;
278292

279-
if (!shouldAutorunMount(mount))
280-
return;
281-
282293
let contentType = contentTypes.length > 0 ? contentTypes[0] : null;
283294

284295
let setting;
@@ -325,19 +336,18 @@ class AutorunDialog extends ModalDialog.ModalDialog {
325336

326337
let mountName = mount.get_name();
327338

328-
let greeting = _getMediaGreeting(contentType);
329-
let title = `${greeting} ${_("Choose what application to launch.")}`;
339+
// let greeting = _getMediaGreeting(contentType);
340+
let title = _("Media inserted");
330341

331342
let contentDescription = contentType
332343
? Gio.content_type_get_description(contentType)
333344
: null;
334345

335346
let description;
336347
if (contentDescription) {
337-
description = _("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\".")
338-
.format(mountName, contentDescription);
348+
description = `${mountName}\n(${contentDescription})\n\n${_("Choose an action")}`;
339349
} else {
340-
description = _("Select how to open \"%s\".").format(mountName);
350+
description = _("Select how to open '%s'.").format(mountName);
341351
}
342352

343353
this._content = new Dialog.MessageDialogContent({ title, description });
@@ -392,7 +402,7 @@ class AutorunDialog extends ModalDialog.ModalDialog {
392402
});
393403

394404
let openFolderItem = new Dialog.ListSectionItem({
395-
icon_actor: new St.Icon({ icon_name: 'folder-open', icon_size: LIST_ITEM_ICON_SIZE }),
405+
icon_actor: new St.Icon({ icon_name: 'folder-open', icon_size: LIST_ITEM_ICON_SIZE, icon_type: St.IconType.FULLCOLOR }),
396406
title: _("Open Folder"),
397407
});
398408
openFolderItem._autorunType = AUTORUN_ITEM_OPEN_FOLDER;

0 commit comments

Comments
 (0)