Skip to content

Commit

Permalink
Merge pull request #91 from evsar3/wip-iss85-auto-drive-letter
Browse files Browse the repository at this point in the history
Support for automatic drive letter
  • Loading branch information
evsar3 authored Apr 27, 2021
2 parents 81eaf10 + 0244699 commit 33c4ed0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
34 changes: 32 additions & 2 deletions src/renderer/ProcessHandlerWin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ class ProcessHandlerWin {
}

create (conn) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (this.settings.sshfsBinary.endsWith('sshfs-win.exe')) {
this.settings.sshfsBinary = this.settings.sshfsBinary.replace(/sshfs-win\.exe$/, 'sshfs.exe')
}

let mountPoint = conn.mountPoint

if (mountPoint === 'auto') {
mountPoint = await this.getFirstAvailableDriveLetter(conn.preferredMountPoint)

conn.preferredMountPoint = mountPoint
}

let cmdArgs = [
`${conn.user}@${conn.host}:${conn.folder}`,
conn.mountPoint,
mountPoint,
`-p${conn.port}`,
`-ovolname=${conn.name.substr(0, 32)}`,
'-odebug',
Expand Down Expand Up @@ -216,6 +224,28 @@ class ProcessHandlerWin {
})
})
}

getFirstAvailableDriveLetter (preferredMountPoint = null) {
return new Promise((resolve, reject) => {
exec(`wmic logicaldisk get name`, (err, stdout) => {
const driveLetters = 'DEFGHIJKLMNOPQRSTUVWXYZ'.split('')

if (!err) {
const drivers = stdout.toString().trim().split('\n').slice(1)
.map(i => i.substr(0, 1).toUpperCase())
const availableDriveLetters = driveLetters.filter(i => !drivers.includes(i))

if (preferredMountPoint && availableDriveLetters.includes(preferredMountPoint.substr(0, 1))) {
resolve(preferredMountPoint)
} else {
resolve(availableDriveLetters[0] + ':')
}
} else {
reject(new Error('Process not found'))
}
})
})
}
}

export default ProcessHandlerWin
3 changes: 2 additions & 1 deletion src/renderer/components/AddEditConnectionWindow/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<div class="form-item">
<label>Drive letter</label>
<select v-model="conn.mountPoint">
<option value="auto">Auto</option>
<option v-for="drive in drives" :value="drive + ':'" :key="drive">{{drive}}:</option>
</select>
</div>
Expand Down Expand Up @@ -167,7 +168,7 @@ export default {
password: '',
keyFile: process.env.USERPROFILE + '\\.ssh\\id_rsa',
key: '',
mountPoint: 'E:',
mountPoint: 'auto',
status: 'disconnected',
pid: 0,
advanced: {
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/components/MainWindow/ConnectionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div class="details">
<span class="local-path">
{{conn.mountPoint}}
{{mountPointLabel}}
</span>

<span class="sep">•</span>
Expand All @@ -26,7 +26,7 @@
</div>

<div class="controls">
<button v-show="isConnected" @click="$emit('open', conn.mountPoint)">
<button v-show="isConnected" @click="$emit('open', conn.mountPoint === 'auto' ? conn.preferredMountPoint : conn.mountPoint)">
<Icon icon="openFolder"/>
</button>

Expand Down Expand Up @@ -101,6 +101,16 @@ export default {
showDeleteButton () {
return this.mode === 'delete' && !this.isConnected && !this.isConnectingOrDisconnecting
},
mountPointLabel () {
if (this.isConnected && this.conn.mountPoint === 'auto') {
return `Auto (${this.conn.preferredMountPoint})`
} else if (this.conn.mountPoint === 'auto') {
return 'Auto'
} else {
return this.conn.mountPoint
}
}
}
}
Expand Down

0 comments on commit 33c4ed0

Please sign in to comment.