Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 81 additions & 80 deletions Engines/Wine/Shortcuts/Reader/script.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,123 @@
include("engines.wine.engine.object");

var _WineShortcutReader = function (shortcut) {
var that = this;
that._shortcutManager = Bean("shortcutManager");
that._libraryManager = Bean("libraryManager");
that._uiQuestionFactory = Bean("uiQuestionFactory");
that._winePrefixesDirectory = Bean("propertyReader").getProperty("application.user.containers") + "/" + WINE_PREFIX_DIR + "/";
class WineShortcutReader {
constructor(shortcut) {
this.shortcut = shortcut;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mainly access this.shortcut using JSON.parse(this.shortcut.script) maybe it makes sense to provide this value as either a getter method:

get shortcutScript() {
   return JSON.parse(this.shortcut.script)
}

or as a public field.

What do you think @plata @ImperatorS79?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO IDEA ^^.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much about this detail but you're approach is fine for me.


this.shortcutManager = Bean("shortcutManager");
this.libraryManager = Bean("libraryManager");
this.uiQuestionFactory = Bean("uiQuestionFactory");
this.winePrefixesDirectory = Bean("propertyReader").getProperty("application.user.containers") + "/" + WINE_PREFIX_DIR + "/";
}

this.shortcut = shortcut;
get wineprefix() {
const shortcutContent = JSON.parse(this.shortcut.script);

this.wineprefix = function () {
var shortcutContent = JSON.parse(this.shortcut.script);
return shortcutContent.winePrefix;
};

this.container = this.wineprefix;
}

this.run = function (userArguments) {
var shortcutContent = JSON.parse(this.shortcut.script);
run(userArguments) {
const shortcutContent = JSON.parse(this.shortcut.script);

if (!userArguments) {
userArguments = [];
}

var args = (shortcutContent.arguments ? shortcutContent.arguments : []).concat(Java.from(userArguments));
const args = (shortcutContent.arguments ? shortcutContent.arguments : []).concat(Java.from(userArguments));

const userData = {
wineDebug: shortcutContent.wineDebug
};

var userData = {};
userData["wineDebug"] = shortcutContent.wineDebug;
new Wine()
.prefix(shortcutContent.winePrefix)
.run(shortcutContent.executable, args, shortcutContent.workingDirectory, false, false, userData)
};
}


this.stop = function () {
var shortcutContent = JSON.parse(this.shortcut.script);
stop() {
const shortcutContent = JSON.parse(this.shortcut.script);

new Wine()
.prefix(shortcutContent.winePrefix)
.kill()
};
}

uninstall() {
const shortcutContent = JSON.parse(this.shortcut.script);

this.uninstall = function () {
var shortcutContent = JSON.parse(this.shortcut.script);
var _winePrefix = shortcutContent.winePrefix;
const winePrefix = shortcutContent.winePrefix;

var _found = false;
this._libraryManager.fetchShortcuts().forEach(function (shortcutCategory) {
let found = false;
this.libraryManager.fetchShortcuts().forEach(function (shortcutCategory) {
shortcutCategory.getShortcuts().forEach(function (shortcut) {
var _otherShortcutContent = JSON.parse(shortcut.script);
const otherShortcutContent = JSON.parse(shortcut.script);

if (_otherShortcutContent.winePrefix == _winePrefix && shortcut.name != that.shortcut.name) {
_found = true;
if (otherShortcutContent.winePrefix == winePrefix && shortcut.name != that.shortcut.name) {
found = true;
}
});
});

this._shortcutManager.deleteShortcut(this.shortcut);
this.shortcutManager.deleteShortcut(this.shortcut);

if (!_found) {
this._uiQuestionFactory.create(tr("The container {0} is no longer used.\nDo you want to delete it?", _winePrefix),
if (!found) {
this.uiQuestionFactory.create(tr("The container {0} is no longer used.\nDo you want to delete it?", winePrefix),
function () {
remove(that._winePrefixesDirectory + _winePrefix);
remove(that.winePrefixesDirectory + winePrefix);
});
}
}
};

/**
* ShortcutReader prototype
* @constructor
*/
function ShortcutReader() {
}

/**
* sets shortcut
* @param {string} shortcut shortcut
* @returns {void}
*/
ShortcutReader.prototype.of = function (shortcut) {
this.shortcut = shortcut;
var shortcutContentParsed = JSON.parse(this.shortcut.script);

if (shortcutContentParsed.type == "WINE") {
this._runner = new _WineShortcutReader(this.shortcut);
class ShortcutReader {
constructor() {
// do nothing
}
}

/**
* runs shortcut
* @param {array} userArguments arguments
* @returns {void}
*/
ShortcutReader.prototype.run = function (userArguments) {
this._runner.run(userArguments);
}
/**
* sets shortcut
* @param {string} shortcut shortcut
* @returns {void}
*/
of(shortcut) {
const shortcutContentParsed = JSON.parse(shortcut.script);

/**
* stops running shortcut
* @returns {void}
*/
ShortcutReader.prototype.stop = function () {
this._runner.stop();
}
if (shortcutContentParsed.type == "WINE") {
this.runner = new WineShortcutReader(shortcut);
}
}

/**
* uninstalls shortcut
* @returns {void}
*/
ShortcutReader.prototype.uninstall = function () {
this._runner.uninstall();
}
/**
* returns container of shortcut
* @returns {string} container
*/
get container() {
return this.runner.container();
}

/**
* returns container of shortcut
* @returns {string} container
*/
ShortcutReader.prototype.container = function () {
return this._runner.container();
/**
* runs shortcut
* @param {array} userArguments arguments
* @returns {void}
*/
run(userArguments) {
this.runner.run(userArguments);
}

/**
* stops running shortcut
* @returns {void}
*/
stop() {
this.runner.stop();
}

/**
* uninstalls shortcut
* @returns {void}
*/
uninstall() {
this.runner.uninstall();
}
}