Skip to content

Commit

Permalink
Impl open from url modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukaii committed Mar 25, 2017
1 parent 7bb62cb commit f0f123d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ <h4 class="modal-title">Customize HackMD server</h4>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="open-from-url-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Open HackMD from url</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" placeholder="https://hackmd.io/features">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="submit-file-url">Go</button>
</div>
</div>
</div>
</div>
<div class="electronSearchText-box">
<input type="text" class="electronSearchText-input">
<span class="electronSearchText-count"></span>
Expand Down
3 changes: 3 additions & 0 deletions ipc/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function (commandId, args = {}) {
case 'configServerUrl':
BrowserWindow.getFocusedWindow().webContents.send('config-serverurl')
break
case 'openFromUrl':
BrowserWindow.getFocusedWindow().webContents.send('open-from-url')
break
case 'checkVersion':
return fetch(url.resolve(getServerUrl(), '/status')).then(response => {
var browserWindows = BrowserWindow.getAllWindows()
Expand Down
7 changes: 7 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const template = [
click () {
exec('createWindow', {url: `file://${path.join(__dirname, 'index.html')}`})
}
},
{
label: 'Open from url',
accelerator: 'CmdOrCtrl+O',
click () {
exec('openFromUrl')
}
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ window.onload = () => {
$('#serverurl-config-modal.modal').modal()
})

ipcRenderer.on('open-from-url', () => {
$('#open-from-url-modal.modal').modal()
})

ipcRenderer.on('unsupported-version', () => {
$('navbar').addClass('unsupported')
})
Expand Down Expand Up @@ -197,6 +201,14 @@ window.onload = () => {
}
})

$('#open-from-url-modal.modal #submit-file-url').click(function () {
let url = $('#open-from-url-modal.modal input[type="text"]').val()
if (url.length > 0) {
ipcClient('createWindow', { url: `file://${path.join(__dirname, `index.html?target=${url}`)}` })
$('#open-from-url-modal.modal').modal('hide')
}
})

/* handle _target=blank pages */
webview.addEventListener('new-window', (event) => {
ipcClient('createWindow', { url: `file://${path.join(__dirname, `index.html?target=${event.url}`)}` })
Expand Down

0 comments on commit f0f123d

Please sign in to comment.