mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-23 04:49:59 +00:00
42 lines
854 B
TypeScript
42 lines
854 B
TypeScript
import * as fs from 'fs'
|
|
const untildify = require('untildify')
|
|
|
|
import { Injectable } from '@angular/core'
|
|
import { LinkHandler } from './api'
|
|
import { ElectronService } from 'api'
|
|
|
|
|
|
@Injectable()
|
|
export class URLHandler extends LinkHandler {
|
|
regex = 'http(s)?://[^\\s;\'"]+[^,;\\s]'
|
|
|
|
constructor (private electron: ElectronService) {
|
|
super()
|
|
}
|
|
|
|
handle (uri: string) {
|
|
this.electron.shell.openExternal(uri)
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class FileHandler extends LinkHandler {
|
|
regex = '[~/][^\\s.,;\'"]+'
|
|
|
|
constructor (private electron: ElectronService) {
|
|
super()
|
|
}
|
|
|
|
convert (uri: string): string {
|
|
return untildify(uri)
|
|
}
|
|
|
|
verify (uri: string) {
|
|
return fs.existsSync(uri)
|
|
}
|
|
|
|
handle (uri: string) {
|
|
this.electron.shell.openExternal('file://' + uri)
|
|
}
|
|
}
|