-
-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to command-line arguments #2013
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ var PDFViewer = require('pdfViewer.js') | |
var tabEditor = require('navbar/tabEditor.js') | ||
var readerView = require('readerView.js') | ||
var taskOverlay = require('taskOverlay/taskOverlay.js') | ||
var { searchAndSortTasks, moveToTaskCommand } = require('searchbar/customBangs.js') | ||
|
||
module.exports = { | ||
initialize: function () { | ||
|
@@ -94,6 +95,58 @@ module.exports = { | |
browserUI.addTab(newTab, { | ||
enterEditMode: !data.url // only enter edit mode if the new tab is empty | ||
}) | ||
|
||
if (data.taskQuery) { | ||
// use the first search result | ||
// if there is no result, need to create a new task | ||
let task | ||
|
||
if (/^\d+$/.test(data.taskQuery)) { | ||
task = tasks.get(data.taskQuery) | ||
} else { | ||
task = searchAndSortTasks(data.taskQuery, excludeSelected=false)[0]?.task | ||
} | ||
|
||
if (!task) { | ||
task = tasks.get(tasks.add(undefined, tasks.getIndex(tasks.getSelected().id) + 1)) | ||
task.name = data.taskQuery | ||
} | ||
|
||
moveToTaskCommand(task.id) | ||
} | ||
|
||
}) | ||
|
||
ipc.on('switchToTask', function (e, data) { | ||
/* new tabs can't be created in modal mode */ | ||
if (modalMode.enabled()) { | ||
return | ||
} | ||
|
||
/* new tabs can't be created in focus mode */ | ||
if (focusMode.enabled()) { | ||
focusMode.warn() | ||
return | ||
} | ||
|
||
if (data.taskQuery) { | ||
// use the first search result | ||
// if there is no result, need to create a new task | ||
let task | ||
|
||
if (/^\d+$/.test(data.taskQuery)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this would be simpler / better as:
So task IDs would work, but any number that's not a task ID would be used for search or to create a new task. |
||
task = tasks.get(data.taskQuery) | ||
} else { | ||
task = searchAndSortTasks(data.taskQuery, excludeSelected=false)[0]?.task | ||
} | ||
|
||
if (!task) { | ||
task = tasks.get(tasks.add(undefined, tasks.getIndex(tasks.getSelected().id) + 1)) | ||
task.name = data.taskQuery | ||
} | ||
|
||
browserUI.switchToTask(task.id) | ||
} | ||
}) | ||
|
||
ipc.on('saveCurrentPage', async function () { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ var secondaryMenu = null | |
var isFocusMode = false | ||
var appIsReady = false | ||
|
||
const isFirstInstance = app.requestSingleInstanceLock() | ||
const isFirstInstance = app.requestSingleInstanceLock(process.argv) | ||
|
||
if (!isFirstInstance) { | ||
app.quit() | ||
|
@@ -116,23 +116,38 @@ function openTabInWindow (url) { | |
|
||
function handleCommandLineArguments (argv) { | ||
// the "ready" event must occur before this function can be used | ||
var initTaskQuery = undefined | ||
if (argv) { | ||
|
||
// check for -t task query | ||
if (argv.includes('-t') && argv.indexOf('-t') > 0){ | ||
// query for specific task to add search to | ||
initTaskQuery = argv[argv.indexOf('-t') + 1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can assume that IPC messages will be received in the order they're sent, in which case we can just send a |
||
} | ||
|
||
argv.forEach(function (arg, idx) { | ||
if (arg && arg.toLowerCase() !== __dirname.toLowerCase()) { | ||
// URL | ||
if (arg.indexOf('://') !== -1) { | ||
// URL | ||
sendIPCToWindow(mainWindow, 'addTab', { | ||
url: arg | ||
url: arg, | ||
taskQuery: initTaskQuery | ||
}) | ||
} else if (idx > 0 && argv[idx - 1] === '-s') { | ||
// search | ||
sendIPCToWindow(mainWindow, 'addTab', { | ||
url: arg | ||
url: arg, | ||
taskQuery: initTaskQuery | ||
}) | ||
} else if (/\.(m?ht(ml)?|pdf)$/.test(arg) && fs.existsSync(arg)) { | ||
// local files (.html, .mht, mhtml, .pdf) | ||
sendIPCToWindow(mainWindow, 'addTab', { | ||
url: 'file://' + path.resolve(arg) | ||
url: 'file://' + path.resolve(arg), | ||
taskQuery: initTaskQuery | ||
}) | ||
} else if (initTaskQuery) { | ||
sendIPCToWindow(mainWindow, 'switchToTask', { | ||
taskQuery: initTaskQuery | ||
}) | ||
} | ||
} | ||
|
@@ -367,14 +382,14 @@ app.on('continue-activity', function(e, type, userInfo, details) { | |
} | ||
}) | ||
|
||
app.on('second-instance', function (e, argv, workingDir) { | ||
app.on('second-instance', function (e, argv, workingDir, additionalData) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (mainWindow) { | ||
if (mainWindow.isMinimized()) { | ||
mainWindow.restore() | ||
} | ||
mainWindow.focus() | ||
// add a tab with the new URL | ||
handleCommandLineArguments(argv) | ||
handleCommandLineArguments(additionalData) | ||
} | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this is creating a tab in the current task, then using
moveToTaskCommand
to move it to the new task. This should just be a switchToTask call before the addTab call instead.(However, if we send a switchToTask IPC from the main process, as I suggested in my other comment, this whole block of code should go away anyway).