Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IcingTaskManager@json: Add migration functionality for moving pinned apps from ITM to GWL #2146

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions IcingTaskManager@json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changelog

### 6.3.14

* Added a deprecation notice notification for Cinnamon 4.0 users.
* Added migration functionality for moving local pinned apps from ITM to Grouped Window List in Cinnamon 4.0. This can be accessed by clicking "Migrate Pinned Apps to Grouped Window List" from ITM's settings.

### 6.3.11

* Fixed an issue with the applet not initializing when an open app can't be resolved by wm_class.
Expand Down
2 changes: 2 additions & 0 deletions IcingTaskManager@json/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Icing Task Manager
=============

**Icing Task Manager is deprecated for Cinnamon 4.0+. Please add the Grouped Window List applet to your panel, go to ITM's settings, and click "Migrate Pinned Apps to Grouped Window List".**

**Issues should be opened on ITM's [dedicated repository](https://github.com/jaszhix/icingtaskmanager). All PRs should be submitted to the Cinnamon Spices repository.**

This is a fork of the unfinished development branch of [Window List With App Grouping](https://github.com/jake-phy/WindowIconList/) applet, originally by jake-phy who forked the code from [GNOME Shell Window List](https://github.com/siefkenj/gnome-shell-windowlist/).
Expand Down
157 changes: 156 additions & 1 deletion IcingTaskManager@json/files/IcingTaskManager@json/3.8/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const DND = imports.ui.dnd;
const Settings = imports.ui.settings;
const Util = imports.misc.util;
const SignalManager = imports.misc.signalManager;
const {listDirAsync} = imports.misc.fileUtils;
const ByteArray = imports.byteArray;

const {each, findIndex, filter, isEqual, setTimeout, throttle, unref} = require('./utils');
const {each, find, findIndex, filter, isEqual, setTimeout, throttle, unref, tryFn} = require('./utils');
const constants = require('./constants');
const AppList = require('./appList');
const store = require('./store');
Expand Down Expand Up @@ -289,6 +291,13 @@ class ITMApplet extends Applet.Applet {

this.settings = new Settings.AppletSettings(this.state.settings, metadata.uuid, instance_id);
this.bindSettings();

if (typeof this.on_applet_reloaded === 'function') {
this.isCinnamon4 = true;
this.notifyDeprecation();
global.log('Icing Task Manager is deprecated and has been forked as Grouped Window List in Cinnamon 4.0+. Please upgrade for improved stability.');
}

// Passing an empty object instead of `this` because its only used by SignalManager to bind the callback, which
// we already do here. Otherwise, it creates more circular references.
this.signals = new SignalManager.SignalManager(null);
Expand Down Expand Up @@ -372,6 +381,7 @@ class ITMApplet extends Applet.Applet {
{key: 'system-favorites', value: 'systemFavorites', cb: this._updateFavorites},
{key: 'show-all-workspaces', value: 'showAllWorkspaces', cb: this.refreshAllAppLists},
{key: 'list-monitor-windows', value: 'listMonitorWindows', cb: this.handleMonitorWindowsPrefsChange},
{key: 'deprecationNoticeRun', value: 'deprecationNoticeRun', cb: null},
];

for (let i = 0, len = settingsProps.length; i < len; i++) {
Expand Down Expand Up @@ -448,6 +458,151 @@ class ITMApplet extends Applet.Applet {
unref(this);
}

getNotificationIcon() {
return new St.Icon({
icon_type: St.IconType.FULLCOLOR,
icon_size: 24 * global.ui_scale,
gicon: new Gio.FileIcon({
file: Gio.file_new_for_path(
GLib.get_home_dir() + '/.local/share/cinnamon/applets/IcingTaskManager@json/icon.png'
)
})
});
}

notifyDeprecation() {
if (this.state.settings.deprecationNoticeRun) return;
let icon = this.getNotificationIcon();
let header = _('Icing Task Manager is deprecated');
let body = _('Please upgrade to Grouped Window List for a more stable, bug-free experience. ')
+ _('Add GWL to your panel, then open ITM\'s settings and click "Migrate Pinned Apps to Grouped Window List".');
Main.criticalNotify(
header,
body,
icon
);
this.settings.setValue('deprecationNoticeRun', true);
}

migratePinnedToGWL() {
if (!this.isCinnamon4) {
Main.criticalNotify(
_('Migration can only be performed on Cinnamon 4.0+.'),
'',
this.getNotificationIcon()
);
return;
}

let gwlSettingsDir = Gio.file_new_for_path(GLib.get_home_dir() + '/.cinnamon/configs/grouped-window-list@cinnamon.org');
let itmSettingsDir = Gio.file_new_for_path(GLib.get_home_dir() + '/.cinnamon/configs/IcingTaskManager@json');
if (!gwlSettingsDir.query_exists(null)) {
Main.criticalNotify(
_('Please add Grouped Window List to a panel before proceeding with the migration.'),
'',
this.getNotificationIcon()
);
return;
}
if (!itmSettingsDir.query_exists(null)) {
Main.criticalNotify(
_('ITM settings directory could not be found!'),
'',
this.getNotificationIcon()
);
return;
}

// Find the ITM JSON file with the most pinned apps,
// then uniquely concatenate it to every GWL JSON file.
listDirAsync(itmSettingsDir, (itmJSONFiles) => {
listDirAsync(gwlSettingsDir, (gwlJSONFiles) => {
let itm = [], itmJson = [], errors = [];
each(itmJSONFiles, (file) => {
file = file.get_name();
file = Gio.file_new_for_path(GLib.get_home_dir() + '/.cinnamon/configs/IcingTaskManager@json/' + file);
let [success, json] = file.load_contents(null);
if (!success) {
errors.push(file.get_path());
return;
}
// Mozjs60 future proofing
if (json instanceof Uint8Array) {
json = ByteArray.toString(json);
} else {
json = json.toString();
}
tryFn(() => {
json = JSON.parse(json);
if (json['system-favorites'].value) {
Main.criticalNotify(
_('System favorites enabled - no migration is needed.'),
'',
this.getNotificationIcon()
);
return;
}
itm.push(json['pinned-apps'].value.length);
itmJson.push(json);
}, () => errors.push(file.get_path()));
});
let max = Math.max(...itm);
let ref = find(itmJson, (json) => json['pinned-apps'].value.length === max);
if (ref) {
let pinnedApps = ref['pinned-apps'].value;
each(gwlJSONFiles, (file) => {
file = file.get_name();
file = Gio.file_new_for_path(GLib.get_home_dir() + '/.cinnamon/configs/grouped-window-list@cinnamon.org/' + file);
let [success, json] = file.load_contents(null);
if (!success) {
errors.push(file.get_path());
return;
}
if (json instanceof Uint8Array) {
json = ByteArray.toString(json);
} else {
json = json.toString();
}
tryFn(() => {
json = JSON.parse(json);
each(pinnedApps, (item) => {
if (json['pinned-apps'].value.indexOf(item) === -1) {
json['pinned-apps'].value.push(item);
}
});
json = JSON.stringify(json);
let raw = file.replace(null, false, Gio.FileCreateFlags.NONE, null);
let out = Gio.BufferedOutputStream.new_sized(raw, 4096);
Cinnamon.write_string_to_stream(out, json);
out.close(null);
}, () => errors.push(file.get_path()));
});
} else {
Main.criticalNotify(
_('Unable to find a suitable ITM settings file to migrate.'),
errors.join('\n'),
this.getNotificationIcon()
);
return;
}

if (errors.length > 0) {
Main.criticalNotify(
_('Migration complete. ') + errors.length + _(' settings file(s) could not be migrated.'),
errors.join('\n'),
this.getNotificationIcon()
);
} else {
Main.criticalNotify(
_('Migration was successful.'),
'',
this.getNotificationIcon()
);
}
});
});
}

// Override Applet._onButtonPressEvent due to the applet menu being replicated in AppMenuButtonRightClickMenu.
_onButtonPressEvent(actor, event) {
if (this.state.panelEditMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"type" : "section",
"title" : "Behavior",
"keys": [
"migrationButton",
"group-apps",
"scroll-behavior",
"left-click-action",
Expand Down Expand Up @@ -568,5 +569,14 @@
"description" : "Mint X, Linux Mint, and Variants",
"callback" : "handleMintXThemePreset",
"tooltip" : "Mint X, Linux Mint, and Variants"
},
"migrationButton": {
"type": "button",
"description": "Migrate Pinned Apps to Grouped Window List",
"callback": "migratePinnedToGWL"
},
"deprecationNoticeRun": {
"type": "generic",
"default": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Window list with app grouping and thumbnails",
"max-instances": -1,
"name": "Icing Task Manager",
"version": "6.3.13",
"version": "6.3.14",
"role": "panellauncher",
"uuid": "IcingTaskManager@json",
"multiversion": true,
Expand Down