(extraOptions: any = {})
| 124 | }); |
| 125 | |
| 126 | function createSession(extraOptions: any = {}) { |
| 127 | const uid = uuidv4(); |
| 128 | const extraOptionsFiltered: any = {}; |
| 129 | Object.keys(extraOptions).forEach((key) => { |
| 130 | if (extraOptions[key] !== undefined) extraOptionsFiltered[key] = extraOptions[key]; |
| 131 | }); |
| 132 | |
| 133 | let cwd = ''; |
| 134 | if (cfg.preserveCWD === undefined || cfg.preserveCWD) { |
| 135 | const activePID = extraOptionsFiltered.activeUid && sessions.get(extraOptionsFiltered.activeUid)?.pty?.pid; |
| 136 | try { |
| 137 | cwd = activePID && getWorkingDirectoryFromPID(activePID); |
| 138 | } catch (error) { |
| 139 | console.error(error); |
| 140 | } |
| 141 | cwd = cwd && isAbsolute(cwd) ? cwd : ''; |
| 142 | } |
| 143 | |
| 144 | // remove the rows and cols, the wrong value of them will break layout when init create |
| 145 | const defaultOptions = Object.assign( |
| 146 | { |
| 147 | cwd: cwd || workingDirectory, |
| 148 | splitDirection: undefined, |
| 149 | shell: cfg.shell, |
| 150 | shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs) |
| 151 | }, |
| 152 | extraOptionsFiltered, |
| 153 | {uid} |
| 154 | ); |
| 155 | const options = decorateSessionOptions(defaultOptions); |
| 156 | const DecoratedSession = decorateSessionClass(Session); |
| 157 | const session = new DecoratedSession(options); |
| 158 | sessions.set(uid, session); |
| 159 | return {session, options}; |
| 160 | } |
| 161 | |
| 162 | rpc.on('new', (extraOptions) => { |
| 163 | const {session, options} = createSession(extraOptions); |
no test coverage detected