Skip to content

Commit

Permalink
Dialogs on do not show a title on OS X, so the window title is used i…
Browse files Browse the repository at this point in the history
…nstead.
  • Loading branch information
feross committed May 29, 2016
1 parent 8b773c5 commit 7833f6b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
46 changes: 37 additions & 9 deletions main/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,46 @@ module.exports = {
openTorrentAddress
}

var config = require('../config')
var electron = require('electron')
var windows = require('./windows')

/**
* Show open dialog to create a single-file torrent.
*/
function openSeedFile () {
if (!windows.main.win) return
var opts = {
title: 'Select a file for the torrent file.',
title: 'Select a file for the torrent.',
properties: [ 'openFile' ]
}
electron.dialog.showOpenDialog(opts, function (selectedPaths) {
setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
windows.main.send('dispatch', 'showCreateTorrent', selectedPaths)
})
}

/*
* Show open dialog to create a single-file or single-directory torrent. On
* Windows and Linux, open dialogs are for files *or* directories only, not both.
* This function shows a directory dialog.
* Windows and Linux, open dialogs are for files *or* directories only, not both,
* so this function shows a directory dialog on those platforms.
*/
function openSeedDirectory () {
var opts = {
title: 'Select a file or folder for the torrent file.',
properties: [ 'openFile', 'openDirectory' ]
}
electron.dialog.showOpenDialog(opts, function (selectedPaths) {
if (!windows.main.win) return
var opts = process.platform === 'darwin'
? {
title: 'Select a file or folder for the torrent.',
properties: [ 'openFile', 'openDirectory' ]
}
: {
title: 'Select a folder for the torrent.',
properties: [ 'openDirectory' ]
}
setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
windows.main.send('dispatch', 'showCreateTorrent', selectedPaths)
})
Expand All @@ -42,12 +54,15 @@ function openSeedDirectory () {
* Show open dialog to open a .torrent file.
*/
function openTorrentFile () {
if (!windows.main.win) return
var opts = {
title: 'Select a .torrent file to open.',
filters: [{ name: 'Torrent Files', extensions: ['torrent'] }],
properties: [ 'openFile', 'multiSelections' ]
}
setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
selectedPaths.forEach(function (selectedPath) {
windows.main.send('dispatch', 'addTorrent', selectedPath)
Expand All @@ -61,3 +76,16 @@ function openTorrentFile () {
function openTorrentAddress () {
windows.main.send('showOpenTorrentAddress')
}

/**
* Dialogs on do not show a title on OS X, so the window title is used instead.
*/
function setTitle (title) {
if (process.platform === 'darwin') {
windows.main.send('dispatch', 'setTitle', title)
}
}

function resetTitle () {
setTitle(config.APP_WINDOW_TITLE)
}
3 changes: 3 additions & 0 deletions renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ function dispatch (action, ...args) {
if (action === 'saveState') {
saveState()
}
if (action === 'setTitle') {
state.window.title = args[0] /* title */
}

// Update the virtual-dom, unless it's just a mouse move event
if (action !== 'mediaMouseMoved' || showOrHidePlayerControls()) {
Expand Down

0 comments on commit 7833f6b

Please sign in to comment.