Skip to content
Permalink
Browse files

Impl open from url modal

  • Loading branch information...
Yukaii committed Mar 25, 2017
1 parent 7bb62cb commit f0f123d687360d185fbfc7b937b5b92289c86a31
Showing with 41 additions and 0 deletions.
  1. +19 −0 index.html
  2. +3 −0 ipc/consumer.js
  3. +7 −0 menu.js
  4. +12 −0 renderer.js
@@ -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>
@@ -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()
@@ -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')
}
}
]
},
@@ -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')
})
@@ -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}`)}` })

0 comments on commit f0f123d

Please sign in to comment.
You can’t perform that action at this time.