Skip to content

Commit

Permalink
1.2.rev177
Browse files Browse the repository at this point in the history
COMMIT TO SAVE
  • Loading branch information
Noitidart committed May 26, 2015
1 parent 7b479d3 commit 675f0d5
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 122 deletions.
153 changes: 81 additions & 72 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7088,14 +7088,15 @@ function makeDeskCut(for_ini_key, useSpecObj) {

// creates desktop shortcut to the launcher
// if launcher doesnt exist it makes it first

var deferredMain_makeDeskCut = new Deferred();

var do_getProfSpecsCheckUse = function(aSpecObj, aIfRunningThenTakeThat, aCB) {
if (aSpecObj) {
aCB(aSpecObj);
return; // to prevent deeper exec
}
var promise_cProfSpecs = getProfileSpecs(aProfileIniKey, aIfRunningThenTakeThat, false, false);
var promise_cProfSpecs = getProfileSpecs(for_ini_key, aIfRunningThenTakeThat, false, false);
promise_cProfSpecs.then(
function(aVal) {
console.log('Fullfilled - promise_cProfSpecs - ', aVal);
Expand All @@ -7108,38 +7109,38 @@ function makeDeskCut(for_ini_key, useSpecObj) {
function(aReason) {
var rejObj = {name:'promise_cProfSpecs', aReason:aReason};
console.warn('Rejected - promise_cProfSpecs - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
).catch(
function(aCaught) {
var rejObj = {name:'promise_cProfSpecs', aCaught:aCaught};
console.error('Caught - promise_cProfSpecs - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
);
};

var do_ensureIconExists = function(useIconNameObj, aCB) {
var promise_getIconName = makeIcon(aProfileIniKey, useIconNameObj);
promise_getIconName.then(
var promise_ensureIconRdyAndMade = makeIcon(for_ini_key, useIconNameObj);
promise_ensureIconRdyAndMade.then(
function(aVal) {
console.log('Fullfilled - promise_getIconName - ', aVal);
// start - do stuff here - promise_getIconName
console.log('Fullfilled - promise_ensureIconRdyAndMade - ', aVal);
// start - do stuff here - promise_ensureIconRdyAndMade

aCB();

// end - do stuff here - promise_getIconName
// end - do stuff here - promise_ensureIconRdyAndMade
},
function(aReason) {
var rejObj = {name:'promise_getIconName', aReason:aReason};
console.error('Rejected - promise_getIconName - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
var rejObj = {name:'promise_ensureIconRdyAndMade', aReason:aReason};
console.error('Rejected - promise_ensureIconRdyAndMade - ', rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
).catch(
function(aCaught) {
var rejObj = {name:'promise_getIconName', aCaught:aCaught};
console.error('Caught - promise_getIconName - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
var rejObj = {name:'promise_ensureIconRdyAndMade', aCaught:aCaught};
console.error('Caught - promise_ensureIconRdyAndMade - ', rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
);
};
Expand All @@ -7154,40 +7155,46 @@ function makeDeskCut(for_ini_key, useSpecObj) {

do_getProfSpecsCheckUse(useSpecObj, true, function(cProfSpec) {
console.info('cProfSpec:', cProfSpec);
var do_sendMsgToLaunch = function() {
var pathsObj = {
OSPath_makeFileAt: OS.Path.join(profToolkit.path_profilistData_launcherExes, cProfSpec.launcherName + '.lnk'), // :todo: need to make sure that launcher was properly named, otherwise this will end up making a duplicate launcher
OSPath_icon: OS.Path.join(profToolkit.path_profilistData_launcherIcons, cProfSpec.iconNameObj.str + '.ico'),
OSPath_targetFile: cProfSpec.path_exeForProfile,
jsStr_args: getPathToProfileDir(aProfileIniKey),
jsStr_desc: 'Launches ' + getAppNameFromChan(cProfSpec.channel_exeForProfile) + ' with "' + ini[aProfileIniKey].props.Name + '" Profile'
var do_makeTheCut = function() {
var cutInfoObj = {
// keys for worker__createShortcut
dir: profToolkit.path_profilistData_launcherExes,
name: cProfSpec.launcherName,
dirNameLnk: OS.Path.join(profToolkit.path_profilistData_launcherExes, cProfSpec.launcherName + '.lnk'), // worker__makeDeskcut requires path safed dirNameLnk, specObj returns path safed name so no need to do it here
args: '-profile "' + getPathToProfileDir(for_ini_key) + '" -no-remote',
desc: 'Launches ' + getAppNameFromChan(cProfSpec.channel_exeForProfile) + ' with "' + ini[for_ini_key].props.Name + '" Profile',
icon: OS.Path.join(profToolkit.path_profilistData_launcherIcons, cProfSpec.iconNameObj.str + '.ico'),

updateIfDiff: true,
refreshIcon: 1,

// keys for worker__makeDeskcut
IDHash: core.os.version_name == '7+' ? getPathToProfileDir(for_ini_key) : null
};

console.info('ready to send msg to launch, pathsObj:', pathsObj);

var promise_doMakeDeskcut = ProfilistWorker.post('makeDeskcut', [pathsObj]);
promise_doLaunch.then(
var promise_doMakeDeskcut = ProfilistWorker.post('makeDeskcut', [cutInfoObj]);
promise_doMakeDeskcut.then(
function(aVal) {
console.log('Fullfilled - promise_doLaunch - ', aVal);
// start - do stuff here - promise_doLaunch
deferredMain_launchProfile.resolve(true);
// end - do stuff here - promise_doLaunch
console.log('Fullfilled - promise_doMakeDeskcut - ', aVal);
// start - do stuff here - promise_doMakeDeskcut
deferredMain_makeDeskCut.resolve(true);
// end - do stuff here - promise_doMakeDeskcut
},
function(aReason) {
var rejObj = {name:'promise_doLaunch', aReason:aReason};
console.warn('Rejected - promise_doLaunch - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
var rejObj = {name:'promise_doMakeDeskcut', aReason:aReason};
console.warn('Rejected - promise_doMakeDeskcut - ', rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
).catch(
function(aCaught) {
var rejObj = {name:'promise_doLaunch', aCaught:aCaught};
console.error('Caught - promise_doLaunch - ', rejObj);
deferredMain_launchProfile.reject(rejObj);
var rejObj = {name:'promise_doMakeDeskcut', aCaught:aCaught};
console.error('Caught - promise_doMakeDeskcut - ', rejObj);
deferredMain_makeDeskCut.reject(rejObj);
}
);

};
do_ensureIconExists(cProfSpec.iconNameObj, do_sendMsgToLaunch);
do_ensureIconExists(cProfSpec.iconNameObj, do_makeTheCut);
});

break;
Expand Down Expand Up @@ -8814,42 +8821,44 @@ function cpClientListener(aSubject, aTopic, aData) {
break;
/*end - generic not specific to profilist cp comm*/
case 'query-make-desktop-shortcut':
var promise_makeRequestedCut = makeDeskCut(incomingJson.key_in_ini);
promise_makeRequestedCut.then(
function(aVal) {
console.log('Fullfilled - promise_makeRequestedCut - ', aVal);
// start - do stuff here - promise_makeRequestedCut
var responseJson = {
clientId: incomingJson.clientId,
status: 1
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
// end - do stuff here - promise_makeRequestedCut
},
function(aReason) {
var rejObj = {name:'promise_makeRequestedCut', aReason:aReason};
console.warn('Rejected - promise_makeRequestedCut - ', rejObj);
var deepestReason = aReasonMax(aReason);
var responseJson = {
clientId: incomingJson.clientId,
status: 0,
explaination: deepestReason
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
}
).catch(
function(aCaught) {
var rejObj = {name:'promise_makeRequestedCut', aCaught:aCaught};
console.error('Caught - promise_makeRequestedCut - ', rejObj);
var deepestReason = aReasonMax(aCaught);
var responseJson = {
clientId: incomingJson.clientId,
status: 0,
explaination: deepestReason
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
}
);

var promise_makeRequestedCut = makeDeskCut(incomingJson.key_in_ini);
promise_makeRequestedCut.then(
function(aVal) {
console.log('Fullfilled - promise_makeRequestedCut - ', aVal);
// start - do stuff here - promise_makeRequestedCut
var responseJson = {
clientId: incomingJson.clientId,
status: 1
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
// end - do stuff here - promise_makeRequestedCut
},
function(aReason) {
var rejObj = {name:'promise_makeRequestedCut', aReason:aReason};
console.warn('Rejected - promise_makeRequestedCut - ', rejObj);
var deepestReason = aReasonMax(aReason);
var responseJson = {
clientId: incomingJson.clientId,
status: 0,
explanation: deepestReason
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
}
).catch(
function(aCaught) {
var rejObj = {name:'promise_makeRequestedCut', aCaught:aCaught};
console.error('Caught - promise_makeRequestedCut - ', rejObj);
var deepestReason = aReasonMax(aCaught);
var responseJson = {
clientId: incomingJson.clientId,
status: 0,
explanation: deepestReason
};
cpCommPostJson('response-make-desktop-shortcut', responseJson);
}
);

break;
case 'query-client-born':
if ('client-closing-if-i-no-other-clients-then-shutdown-listeners' in noResponseActiveTimers) {
Expand Down
104 changes: 55 additions & 49 deletions modules/workers/ProfilistWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,40 +351,38 @@ function makeLauncher(pathsObj) {
}
}

function makeDeskcut(pathsObj) {
function makeDeskcut(cutInfoObj) {
switch (core.os.name) {
case 'winnt':
case 'winmo':
case 'wince':
// actually no: // dont check existance of launcher, just write/overwrite
// check existance of launcher, check its props to ensure they match in pathsObj, if they dont match ten overwrite it with corrections

var cutDirPath = OS.Path.dirname(pathsObj.OSPath_makeFileAt);
var cutFileName = pathsObj.OSPath_makeFileAt.substring(cutDirPath.length+1, pathsObj.OSPath_makeFileAt.length-4);
var targetArgs = pathsObj.jsStr_args;
var desc = pathsObj.jsStr_desc;

var cutOpts = {
path_createWithIcon: pathsObj.OSPath_icon,
str_createWithDesc: pathsObj.jsStr_desc
};

if (core.os.version_name == '7+') {
console.info('pathsObj.jsStr_args:', pathsObj.jsStr_args);
cutOpts.str_createWithAppUserModelId = HashStringHelper(pathsObj.jsStr_args) + ''; // to make it a string otherwise get `expected type pointer, got 3181739213` on chrome://profilist/content/modules/ostypes_win.jsm line 6697
console.info('cutOpts.str_createWithAppUserModelId:', cutOpts.str_createWithAppUserModelId);
if (!('dirNameLnk' in cutInfoObj)) {
throw new Error('makeDeskcut requires path safed dirNameLnk');
}
if ('renameToName' in cutInfoObj) {
throw new Error('makeDeskcut requires that renameToName not be set, because it relies on the fed dirNameLnk');
}

cutOpts.str_createWithArgs = '-profile "' + pathsObj.jsStr_args + '" -no-remote';
if (!('exists' in cutInfoObj)) {
// `exists` wasnt in obj so check existance, this is required before a hard link can be made
cutInfoObj.exists = OS.File.exists(OS.Path.join(cutInfoObj.dir, cutInfoObj.name + '.lnk'));
}

console.info('cutDirPath:', cutDirPath);
console.info('cutFileName:', cutFileName);
console.info('cutOpts:', JSON.stringify(cutOpts));
if (!cutInfoObj.exists) {
if (core.os.version_name == '7+') {
if (cutInfoObj.IDHash) {
cutInfoObj.appUserModelId = HashStringHelper(cutInfoObj.IDHash) + ''; // make it a jsStr
}
}
//makeDir_Bug934283(cutDirPath, {from:OS.Constants.Path.userApplicationDataDir});
tryOsFile_ifDirsNoExistMakeThenRetry('makeDir', [cutDirPath], OS.Constants.Path.userApplicationDataDir);
createShortcuts([cutInfoObj]);
}

//makeDir_Bug934283(cutDirPath, {from:OS.Constants.Path.userApplicationDataDir});
tryOsFile_ifDirsNoExistMakeThenRetry('makeDir', [cutDirPath], OS.Constants.Path.userApplicationDataDir);
console.log('finished make dir');
return OLDcreateShortcut(cutDirPath, cutFileName, pathsObj.OSPath_targetFile, cutOpts);
return makeAlias(OS.Path.join(OS.Constants.Path.desktopDir, cutInfoObj.name), cutInfoObj.dirNameLnk);

break;
default:
Expand Down Expand Up @@ -457,7 +455,7 @@ function launchProfile(pathsObj, argsForQueryLocked) { // checkExistanceFirst to
}
}

function createShortcuts(aArrOfObjs, ) {
function createShortcuts(aArrOfObjs) {
//aArrOfObjs is array of shortcuts to make each obj is like this:
/*
{
Expand All @@ -479,8 +477,8 @@ function createShortcuts(aArrOfObjs, ) {
exists: // jsBool. set to true or false if you know it exists or not, omit if you dont know and this function will do a check // if set it to true/false and you are wrong, some quirky stuff will happen probably
// if cut does not exist, then jsStr_OSPath_targetFile is required
updateIfDiff: // jsBool. default is false. meaning by default it will overwrite. it gets the shortcut properties first, and if different from the ones provided then it will update it, else it will not // currently does not check if descriptions `desc` differ, or if workingDirectory `workDir` differs // also does not check if iconIndex differs. it does but it doesnt use that as a reponse to update it. i should fix this in future. if icon paths are same even though iconIndex's differ, it will not update the iconIndex, :todo:
refreshIcon: // jsInt. default is 0. or omitted meaning dont. if set to 1 then it will refresh at path, if set to 2 it will refresh full windows icon cache
updateIfDiff: // jsBool. default is false. meaning by default it will overwrite. it gets the shortcut properties first, and if different from the ones provided then it will update it, else it will not // currently does not check if descriptions `desc` differ, or if workingDirectory `workDir` differs // also does not check if iconIndex differs. it does but it doesnt use that as a reponse to update it. i should fix this in future. if icon paths are same even though iconIndex's differ, it will not update the iconIndex, :todo: // this means if icon, targetFile, or appUserModelId all match, then even if desc, workingDir, iconindex dont match they will not be updated
refreshIcon: // jsInt. default is 0. or omitted meaning dont. if set to 1 then it will refresh at path, if set to 2 it will refresh full windows icon cache // if icon was not updated then it will not refresh if even refreshicon is set to 1 or 2
doPathSafeWith: // jsStr. default is it wont safe it. so if you dont want to safe it, then omit this
renameToName: // omit if you dont want to rename. otherwise provide a name. without the .lnk. if it is found that the name of the current file doesnt match, then it is renamed. this does not consider updateIfDiff, test is always made, just cause the needed data is already available (the current path, and the new name)
}
Expand All @@ -491,18 +489,15 @@ function createShortcuts(aArrOfObjs, ) {
var refs = {};
ostypes.HELPER.InitShellLinkAndPersistFileConsts();

for (var i=0; i<aArrOfObjs.length; i++) {
if ('appUserModelId' in aArrOfObjs[i]) {
refs.propertyStore = undefined; // this tells winntShellFile_DoerAndFinalizer to get IPropertyStore interface
ostypes.HELPER.InitPropStoreConsts();
break;
}
}
if (aOptions.appUserModelId) {
if (!aOptions.path_linkTo) {
throw new Error('Because appUserModelId is changing devuser must provide path_linkTo and whatever else should be matched on recreate');
if (core.os.version_name == '7+') {
// check if we need IPropertyStore
for (var i=0; i<aArrOfObjs.length; i++) {
if ('appUserModelId' in aArrOfObjs[i]) {
refs.propertyStore = undefined; // this tells winntShellFile_DoerAndFinalizer to get IPropertyStore interface
ostypes.HELPER.InitPropStoreConsts();
break;
}
}
refs.propertyStore = undefined; // this tells winntShellFile_DoerAndFinalizer to get IPropertyStore interface
}

var doer = function() {
Expand All @@ -512,22 +507,33 @@ function createShortcuts(aArrOfObjs, ) {

var cObj = aArrOfObjs[i];

if (core.os.version_name != '7+') {
if ('appUserModelId' in cObj) {
delete cObj.appUserModelId;
}
}

var needToCreate = false; // if need to create or recreate the file this is set to true. if exist then if just needing to update certain properties then this is false. we start out assuming false.

// start path stuff
var fullPath;
var dir;
var name;
if (('dir' in cObj && !('name' in cObj)) || ((!('dir' in cObj) && 'name' in cObj))) {
throw new Error('In obj ' + i + ' either dir or name was provided. If either is provided MUST provided both');
} else {
fullPath = OS.Path.join(cObj.dir, cObj.name + '.lnk');
}

if (!('dir' in cObj) && !('name' in cObj) && !('dirNameLnk' in cObj)) {
throw new Error('In obj ' + i + ' neither dir or name was provided SO MUST provide dirNameLnk');
} else {
if ('dir' in cObj && 'name' in cObj && 'dirNameLnk' in cObj) { // all 3 were provided, so just use dirNameLnk, i dont test if name and dir match that of dirNameLnk, its a devuser issue he shouldnt be stupid
fullPath = cObj.dirNameLnk;
} else if (!('dir' in cObj) && !('name' in cObj) && !('dirNameLnk' in cObj)) {
throw new Error('In obj ' + i + ' NONE of the three were provided. Either provide (dir and name) OR (dirNameLnk)');
} else {
if ('dirNameLnk' in cObj) {
fullPath = cObj.dirNameLnk;
} else {
if (('dir' in cObj && !('name' in cObj)) || ((!('dir' in cObj) && 'name' in cObj))) {
throw new Error('In obj ' + i + ', dirNameLnk was not provided AND either dir or name was provided. MUST provided dir and name ELSE provide dirNameLnk');
} else {
fullPath = OS.Path.join(cObj.dir, cObj.name + '.lnk');
}
}
}

if ('doPathSafeWith' in cObj) {
Expand Down Expand Up @@ -631,8 +637,8 @@ function createShortcuts(aArrOfObjs, ) {
for (var cP in cPreExisting) {
if (cPreExisting[cP] == cObj[cP]) {
console.log('will not update ' + cP + ' because preexisting value matches what devuser set value');
delete cObj[cP]);
delete cPreExisting[cP]);
delete cObj[cP];
delete cPreExisting[cP];
} else {
console.log('WILL update ' + cP + ' because preexisting value differs from set value.', 'prexisting:', cPreExisting[cP], 'set to:', cObj[cP]);
if (cP == 'appUserModelId') {
Expand Down Expand Up @@ -703,7 +709,7 @@ function createShortcuts(aArrOfObjs, ) {
console.log('Shortcut succesfully saved on fullPath:', fullPath);
// ok end set the settings

if ('refreshIcon' in cObj) {
if ('refreshIcon' in cObj && 'icon' in cObj) { // `'icon' in cObj` means that icon was updated
if (cObj.refreshIcon == 1) {
refreshAtPath.push(fullPath);
} else if (cObj.refreshIcon == 2) {
Expand Down Expand Up @@ -2067,7 +2073,7 @@ var HashString = (function (){
})();

var _cache_HashStringHelper = {};
function HashStringHelper = function(aText) {
function HashStringHelper(aText) {
if (!(aText in _cache_HashStringHelper)) {
_cache_HashStringHelper = HashString(aText);
}
Expand Down
Loading

0 comments on commit 675f0d5

Please sign in to comment.