Files
Ponder b31a48677d
Package-Build / Lint (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docs / build (push) Has been cancelled
Package-Build / macOS-Build (arm64, aarch64-apple-darwin) (push) Has been cancelled
Package-Build / macOS-Build (x86_64, x86_64-apple-darwin) (push) Has been cancelled
Package-Build / Linux-Build (amd64, x64, ubuntu-24.04, x86_64-unknown-linux-gnu) (push) Has been cancelled
Package-Build / Linux-Build (arm64, arm64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu, aarch64-linux-gnu-) (push) Has been cancelled
Package-Build / Linux-Build (armhf, arm, ubuntu-24.04, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-) (push) Has been cancelled
Package-Build / Windows-Build (arm64, aarch64-pc-windows-msvc) (push) Has been cancelled
Package-Build / Windows-Build (x64, x86_64-pc-windows-msvc) (push) Has been cancelled
feat: Implement tabby:// URL scheme handler (#11005)
Co-authored-by: Eugene <inbox@null.page>
2026-02-01 22:43:02 +01:00

112 lines
2.6 KiB
TypeScript

import { app, ipcMain, Menu, dialog } from 'electron'
// set userData Path on portable version
import './portable'
// set defaults of environment variables
import 'dotenv/config'
process.env.TABBY_PLUGINS ??= ''
process.env.TABBY_CONFIG_DIRECTORY ??= app.getPath('userData')
import 'v8-compile-cache'
import 'source-map-support/register'
import './sentry'
import './lru'
import { parseArgs } from './cli'
import { Application } from './app'
import electronDebug from 'electron-debug'
import { loadConfig } from './config'
const argv = parseArgs(process.argv, process.cwd())
// eslint-disable-next-line @typescript-eslint/init-declarations
let configStore: any
try {
configStore = loadConfig()
} catch (err) {
dialog.showErrorBox('Could not read config', err.message)
app.exit(1)
}
process.mainModule = module
const application = new Application(configStore)
// Register tabby:// URL scheme
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('tabby', process.execPath, [process.argv[1]])
}
} else {
app.setAsDefaultProtocolClient('tabby')
}
ipcMain.on('app:new-window', () => {
application.newWindow()
})
process.on('uncaughtException' as any, err => {
console.log(err)
application.broadcast('uncaughtException', err)
})
if (argv.d) {
electronDebug({
isEnabled: true,
showDevTools: true,
devToolsMode: 'undocked',
})
}
app.on('activate', async () => {
if (!application.hasWindows()) {
application.newWindow()
} else {
application.focus()
}
})
// Handle URL scheme on macOS
app.on('open-url', async (event, url) => {
event.preventDefault()
console.log('Received open-url event:', url)
if (!application.hasWindows()) {
process.argv.push(url)
} else {
await app.whenReady()
application.handleSecondInstance([url], process.cwd())
}
})
app.on('second-instance', async (_event, newArgv, cwd) => {
application.handleSecondInstance(newArgv, cwd)
})
if (!app.requestSingleInstanceLock()) {
app.quit()
app.exit(0)
}
app.on('ready', async () => {
if (process.platform === 'darwin') {
app.dock.setMenu(Menu.buildFromTemplate([
{
label: 'New window',
click () {
this.app.newWindow()
},
},
]))
}
application.init()
const window = await application.newWindow({ hidden: argv.hidden })
await window.ready
window.passCliArguments(process.argv, process.cwd(), false)
window.focus()
})