-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add input arguments to the applications #66
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
Open
RodrigoATorres
wants to merge
22
commits into
johannesjo:master
Choose a base branch
from
RodrigoATorres:feature/exec_args
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
764c2c4
Added execution arguments for .desktop programs
RodrigoATorres 9eff5df
Adding possibility to add arguments to regular executable files
RodrigoATorres 3f764a0
Added funcionality to guarantee that the windows are open and moved i…
RodrigoATorres f831f63
Fixing arguments for executable files
RodrigoATorres ea43efa
Merge branch 'feature/exec_args'
RodrigoATorres 38056e4
Fixing bug when there are no args for executable files
RodrigoATorres ee22ad3
Added flag --allowInputArgs to make possible to run lwsm with origini…
RodrigoATorres 30abb05
Running prettier to index.ts (should have done it before)
RodrigoATorres 13b2166
Added POLL_ALL_MAX_TIMEOUT_ALLOW_ARGS to configs
RodrigoATorres c555b58
Bug fixed on return promisses from restoreSession
RodrigoATorres 89a23c7
Merge branch 'master' into feature/exec_args
RodrigoATorres 0fba482
Merge remote-tracking branch 'upstream/master'
RodrigoATorres 55e71f8
Merging
RodrigoATorres 3f56d70
Adjusting startProgram to allow multiple input arguments for executab…
RodrigoATorres f64de0a
Merge remote-tracking branch 'upstream/master'
RodrigoATorres d10d030
Merging master
RodrigoATorres d437643
Merging
RodrigoATorres 79c14e7
Removed executable arguments when flag is off, replaced var declarati…
RodrigoATorres 9280827
Merging master
RodrigoATorres 2c9b961
Merge branch 'master' into feature/exec_args
RodrigoATorres 0bf45c9
Empty executable args paramenters automaticlly added to json when sav…
RodrigoATorres 0ab548f
Updated README to include instructions on how to use --allowInputArgs…
RodrigoATorres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,7 +173,8 @@ function saveSessionForDisplayToDb( | |
|
|
||
| function restoreSession( | ||
| sessionName: string, | ||
| isCloseAllOpenWindows: boolean | ||
| isCloseAllOpenWindows: boolean, | ||
| isAllowInputArgs: boolean | ||
| ): Promise<any> { | ||
| const sessionToHandle = sessionName || "DEFAULT"; | ||
|
|
||
|
|
@@ -213,14 +214,23 @@ function restoreSession( | |
| return getActiveWindowListFlow(); | ||
| }) | ||
| .then(currentWindowList => { | ||
| return _startSessionPrograms(savedWindowList, currentWindowList); | ||
| if (isAllowInputArgs) { | ||
| return _startAndWaitPrograms(savedWindowList); | ||
| } else { | ||
| return _startSessionPrograms(savedWindowList, currentWindowList) | ||
| .then(() => { | ||
| // gets current window list by itself and returns the updated variant | ||
| return _waitForAllAppsToStart(savedWindowList); | ||
| }) | ||
| .then((updatedCurrentWindowList: WinObj[]) => { | ||
| return _updateWindowIds( | ||
| savedWindowList, | ||
| updatedCurrentWindowList | ||
| ); | ||
| }); | ||
| } | ||
| }) | ||
| .then(() => { | ||
| // gets current window list by itself and returns the updated variant | ||
| return _waitForAllAppsToStart(savedWindowList); | ||
| }) | ||
| .then((updatedCurrentWindowList: WinObj[]) => { | ||
| _updateWindowIds(savedWindowList, updatedCurrentWindowList); | ||
| return _restoreWindowPositions(savedWindowList); | ||
| }) | ||
| .then(() => { | ||
|
|
@@ -461,12 +471,141 @@ async function _startSessionPrograms( | |
| }) | ||
| .map(win => { | ||
| win.instancesStarted += 1; | ||
| return startProgram(win.executableFile, win.desktopFilePath); | ||
| return startProgram( | ||
| win.executableFile, | ||
| win.desktopFilePath, | ||
| win.executableArgs | ||
| ); | ||
| }); | ||
|
|
||
| await Promise.all(promises); | ||
| } | ||
|
|
||
| // This function is necessary to make possible sending custom arguments to applications to start, | ||
| // making sure it will keep track of which windows correspond to which instance of the applications | ||
| async function _startAndWaitPrograms(windowList: WinObj[]) { | ||
| // Clear the windowIds from the window objects | ||
| windowList.forEach(win => { | ||
| win.windowId = null; | ||
| win.windowIdDec = null; | ||
| }); | ||
|
|
||
| // Get the windowIds of all Ids that were previously opened in order to | ||
| // avoid these windows from being used isntead of the newly created windows | ||
| // (necessary for windows with custom input arguments) | ||
| var activeWindows = await getActiveWindowListFlow(); | ||
|
||
| var blackWinIdList = activeWindows.map(win => win.windowId); | ||
|
|
||
| // Match all the previously opened windows with the windows that do not have | ||
| // custom arguments (in this case, no blacklist needed) | ||
| await _matchWindows(windowList, false, []); | ||
|
|
||
| var windowsNotStarted = windowList.filter(win => win.windowId === null); | ||
| var windowStarted = windowList.filter(win => win.windowId !== null); | ||
| var windowsToStart = _getWindowsToStart(windowsNotStarted, windowStarted); | ||
|
|
||
| let totalTimeWaited = 0; | ||
| // Runs the loop until all windows have been opened or time limit is over | ||
| while (windowList.find(win => win.windowId === null)) { | ||
| totalTimeWaited += CFG.POLL_ALL_APPS_STARTED_INTERVAL; | ||
| if (totalTimeWaited > CFG.POLL_ALL_MAX_TIMEOUT_ALLOW_ARGS) { | ||
| console.error("POLL_ALL_MAX_TIMEOUT_ALLOW_ARGS reached"); | ||
| windowList | ||
| .filter(win => win.windowId === null) | ||
| .forEach(e => { | ||
| console.log("Unable to start: ", e.wmClassName); | ||
| }); | ||
| break; | ||
| } | ||
|
|
||
| let promises = windowsToStart.map(win => { | ||
| startProgram(win.executableFile, win.desktopFilePath, win.executableArgs); | ||
| }); | ||
| await Promise.all(promises); | ||
|
|
||
| // Try to match newly started windows, the black list is needed to avoid matching | ||
| // windows that have custom arguments with windows oppened before running lwsm | ||
| await _matchWindows(windowList, true, blackWinIdList); | ||
| // Update the lists with the windows not to be started yet, the windows to be started next | ||
| // and the ones that already have the command to start sent | ||
| windowsNotStarted = windowsNotStarted.filter( | ||
| winNotStarted => | ||
| !windowsToStart.find(winToStart => winToStart === winNotStarted) | ||
| ); | ||
| windowStarted = windowStarted.concat(windowsToStart); | ||
| windowsToStart = _getWindowsToStart(windowsNotStarted, windowStarted); | ||
| } | ||
|
|
||
| windowList.forEach(win => { | ||
| win.windowIdDec = parseInt(win.windowId, 16); | ||
| }); | ||
| } | ||
|
|
||
| // Get, from windowList, all the windows that can be started without the risk of | ||
| // mixing same application windows with different arguments. The others will have to wait for the | ||
| // previous windows to start, before the command can be issued | ||
| function _getWindowsToStart(windowList: WinObj[], windowsStarted: WinObj[]) { | ||
| var windowsToStart = []; | ||
| for (var win of windowList) { | ||
| let shouldAdd = true; | ||
| // If another instance of the same application with different input arguments | ||
| // is in the list of windows to start, then the current one should not be added | ||
| windowsToStart.forEach(winToRun => { | ||
| if ( | ||
| win.executableFile === winToRun.executableFile && | ||
| win.executableArgs !== winToRun.executableArgs | ||
| ) { | ||
| shouldAdd = false; | ||
| } | ||
| }); | ||
| // If another instance of the same application is in the list of windows that | ||
| // have been sent command to start, but still don't have a windowId, the current one should not be added | ||
| if ( | ||
| windowsStarted.find( | ||
| winStarted => | ||
| winStarted.windowId === null && | ||
| winStarted.wmClassName === win.wmClassName | ||
| ) | ||
| ) { | ||
| shouldAdd = false; | ||
| } | ||
| if (!win.windowId && shouldAdd) { | ||
| windowsToStart.push(win); | ||
| } | ||
| } | ||
| return windowsToStart; | ||
| } | ||
|
|
||
| // Match the windows that have been opened already to the windows on windowList | ||
| async function _matchWindows( | ||
| windowList: WinObj[], | ||
| includeExecsWithArgs: boolean, | ||
| blackWinIdList: String[] | ||
| ) { | ||
| var activeWindows = await getActiveWindowListFlow(); | ||
| // Remove the active windows that already have a window assigned on windowList | ||
| // and the ones that are on the black list | ||
| activeWindows = activeWindows.filter( | ||
| actWin => !windowList.find(win => win.windowId === actWin.windowId) | ||
| ); | ||
| activeWindows = activeWindows.filter( | ||
| actWin => !blackWinIdList.find(windowId => windowId === actWin.windowId) | ||
| ); | ||
|
|
||
| for (var win of windowList.filter(win => win.windowId === null)) { | ||
| let activeWindowMatch = activeWindows.find( | ||
| actWin => actWin.wmClassName == win.wmClassName | ||
| ); | ||
| if ( | ||
| activeWindowMatch && | ||
| (!win.executableArgs || win.executableArgs === "" || includeExecsWithArgs) | ||
| ) { | ||
| win.windowId = activeWindowMatch.windowId; | ||
| activeWindows = activeWindows.filter(e => e !== activeWindowMatch); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function _getNumberOfInstancesToRun( | ||
| windowToMatch: WinObj, | ||
| windowList: WinObj[] | ||
|
|
@@ -554,10 +693,10 @@ async function _restoreWindowPositions( | |
| ): Promise<void> { | ||
| const promises = []; | ||
| let last_desktop_nr = 0; | ||
|
|
||
| // Sort the window objects based on which workspace they are locate, | ||
| // so the windows can be moved workspace by workspace | ||
| // This is needed because the window manager just creates an aditional workspace when | ||
| // This is needed because the window manager just creates an aditional workspace when | ||
| // the previous one has some window on it. | ||
| savedWindowList = savedWindowList.concat().sort((a, b) => { | ||
| return a.wmCurrentDesktopNr - b.wmCurrentDesktopNr; | ||
|
|
@@ -566,11 +705,13 @@ async function _restoreWindowPositions( | |
| for (const win of savedWindowList) { | ||
| promises.push(restoreWindowPosition(win)); | ||
| promises.push(moveToWorkspace(win.windowId, win.wmCurrentDesktopNr)); | ||
|
|
||
| // The promises are not executed until the last item is reached or | ||
| // the desktop_nr is different from the previous entry and which case | ||
| // the app waits for those to finish before continuing the process | ||
| if ( (win.wmCurrentDesktopNr !== last_desktop_nr) || (win === savedWindowList.slice(-1)[0])) { | ||
| if ( | ||
| win.wmCurrentDesktopNr != last_desktop_nr || | ||
| win == savedWindowList.slice(-1)[0] | ||
| ) { | ||
| for (const promise of promises) { | ||
| try { | ||
| await promise; | ||
|
|
@@ -579,7 +720,7 @@ async function _restoreWindowPositions( | |
| } | ||
| } | ||
| last_desktop_nr = win.wmCurrentDesktopNr; | ||
| promises.length = 0 | ||
| promises.length = 0; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken this would lead to
isAllowInputArgsbeing false to have no effect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to answer,
The code would start the programs with arguments, in case there were input arguments in the json file, if the
isAllowInputArgswas set to false.The effect
isAllowInputArgsbeing set to false would be running_startSessionProgramsinstead of_startAndWaitPrograms.I believe I did that way because the input arguments themselves were not a big change on the code, that could lead to instabilities (like
_startAndWaitPrograms).But, now that you said, I agree that makes much more sense to remove them. I will just pass a empty string as an argument then, so the code will behave exactly as before.