From 675f0d5bca3d99399bd51887a677c478b2237ac4 Mon Sep 17 00:00:00 2001 From: Noitidart Date: Tue, 26 May 2015 00:59:21 -0700 Subject: [PATCH] 1.2.rev177 COMMIT TO SAVE --- bootstrap.js | 153 +++++++++++++++-------------- modules/workers/ProfilistWorker.js | 104 +++++++++++--------- resources/scripts/options.js | 2 +- 3 files changed, 137 insertions(+), 122 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 19ae329..25e62c1 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -7088,6 +7088,7 @@ 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) { @@ -7095,7 +7096,7 @@ function makeDeskCut(for_ini_key, useSpecObj) { 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); @@ -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); } ); }; @@ -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; @@ -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) { diff --git a/modules/workers/ProfilistWorker.js b/modules/workers/ProfilistWorker.js index bffbe9a..ce00c04 100644 --- a/modules/workers/ProfilistWorker.js +++ b/modules/workers/ProfilistWorker.js @@ -351,7 +351,7 @@ function makeLauncher(pathsObj) { } } -function makeDeskcut(pathsObj) { +function makeDeskcut(cutInfoObj) { switch (core.os.name) { case 'winnt': case 'winmo': @@ -359,32 +359,30 @@ function makeDeskcut(pathsObj) { // 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: @@ -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: /* { @@ -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) } @@ -491,18 +489,15 @@ function createShortcuts(aArrOfObjs, ) { var refs = {}; ostypes.HELPER.InitShellLinkAndPersistFileConsts(); - for (var i=0; i