-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle mailto in argv, support full syntax
- Loading branch information
Showing
5 changed files
with
159 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { sendToSelectedAccountView } from './account-views' | ||
import { instanceOfNodeError } from '../utils/type-helpers' | ||
|
||
function parse(uri: string) { | ||
try { | ||
return new URL(uri) | ||
} catch (error: unknown) { | ||
if ( | ||
instanceOfNodeError(error, TypeError) && | ||
error.code === 'ERR_INVALID_URL' | ||
) { | ||
return | ||
} | ||
|
||
throw error | ||
} | ||
} | ||
|
||
const spaceAfterComma = (x: string | null) => x?.replaceAll(',', ', ') | ||
|
||
export function handleMailto(uri?: string) { | ||
if (!uri) return // Empty string doesn't cut it either | ||
const x = parse(uri) | ||
if (!x) return | ||
sendToSelectedAccountView( | ||
'gmail:compose-mail', | ||
spaceAfterComma(x.pathname), | ||
spaceAfterComma(x.searchParams.get('cc')), | ||
spaceAfterComma(x.searchParams.get('bcc')), | ||
x.searchParams.get('subject'), | ||
x.searchParams.get('body') | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// https://dev.to/jdbar/the-problem-with-handling-node-js-errors-in-typescript-and-the-workaround-m64 | ||
export function instanceOfNodeError<T extends new (...args: any) => Error>( | ||
value: unknown, | ||
errorType: T | ||
): value is InstanceType<T> & NodeJS.ErrnoException { | ||
return value instanceof errorType | ||
} |