File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,3 +70,11 @@ globalThis.matchMedia = (query: string): MediaQueryList => ({
7070 removeEventListener : ( ) => { } ,
7171 dispatchEvent : ( ) => false ,
7272} ) ;
73+
74+ Object . defineProperty ( navigator , 'clipboard' , {
75+ value : {
76+ writeText : jest . fn ( ) . mockResolvedValue ( undefined ) ,
77+ readText : jest . fn ( ) . mockResolvedValue ( '' ) ,
78+ } ,
79+ configurable : true ,
80+ } ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,12 @@ export interface DeviceFlowSession {
3434 expiresAt : number ;
3535}
3636
37+ export type DeviceFlowErrorResponse = {
38+ error : string ;
39+ error_description : string ;
40+ error_uri : string ;
41+ } ;
42+
3743export interface LoginPersonalAccessTokenOptions {
3844 hostname : Hostname ;
3945 token : Token ;
Original file line number Diff line number Diff line change 55 getWebFlowAuthorizationUrl ,
66} from '@octokit/oauth-methods' ;
77import { request } from '@octokit/request' ;
8+ import { RequestError } from '@octokit/request-error' ;
89
910import { format } from 'date-fns' ;
1011import semver from 'semver' ;
@@ -26,6 +27,7 @@ import type {
2627import type {
2728 AuthMethod ,
2829 AuthResponse ,
30+ DeviceFlowErrorResponse ,
2931 DeviceFlowSession ,
3032 LoginOAuthDeviceOptions ,
3133 LoginOAuthWebOptions ,
@@ -124,13 +126,21 @@ export async function pollGitHubDeviceFlow(
124126
125127 return authentication . token as Token ;
126128 } catch ( err ) {
127- const errorCode = ( err as { response ?: { data ?: { error ?: string } } } )
128- ?. response ?. data ?. error ;
129+ if ( err instanceof RequestError ) {
130+ const response = err . response . data as DeviceFlowErrorResponse ;
131+ const errorCode = response . error ;
129132
130- if ( errorCode === 'authorization_pending' || errorCode === 'slow_down' ) {
131- return null ;
133+ if ( errorCode === 'authorization_pending' || errorCode === 'slow_down' ) {
134+ return null ;
135+ }
132136 }
133137
138+ rendererLogError (
139+ 'pollGitHubDeviceFlow' ,
140+ 'Error exchanging device code' ,
141+ err ,
142+ ) ;
143+
134144 throw err ;
135145 }
136146}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { mockSettings } from '../__mocks__/state-mocks';
33import { type Link , OpenPreference } from '../types' ;
44
55import {
6+ copyToClipboard ,
67 decryptValue ,
78 encryptValue ,
89 getAppVersion ,
@@ -156,4 +157,11 @@ describe('renderer/utils/comms.ts', () => {
156157 expect ( window . gitify . tray . updateTitle ) . toHaveBeenCalledWith ( 'gitify' ) ;
157158 } ) ;
158159 } ) ;
160+
161+ it ( 'copy to clipboard' , async ( ) => {
162+ copyToClipboard ( 'some-value' ) ;
163+
164+ expect ( navigator . clipboard . writeText ) . toHaveBeenCalledTimes ( 1 ) ;
165+ expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( 'some-value' ) ;
166+ } ) ;
159167} ) ;
Original file line number Diff line number Diff line change @@ -50,9 +50,7 @@ export function setAutoLaunch(value: boolean): void {
5050export function setUseAlternateIdleIcon ( value : boolean ) : void {
5151 window . gitify . tray . useAlternateIdleIcon ( value ) ;
5252}
53- export async function copyToClipboard ( text : string ) : Promise < void > {
54- await navigator . clipboard . writeText ( text ) ;
55- }
53+
5654export function setUseUnreadActiveIcon ( value : boolean ) : void {
5755 window . gitify . tray . useUnreadActiveIcon ( value ) ;
5856}
@@ -80,3 +78,7 @@ export function updateTrayColor(notificationsLength: number): void {
8078export function updateTrayTitle ( title : string ) : void {
8179 window . gitify . tray . updateTitle ( title ) ;
8280}
81+
82+ export async function copyToClipboard ( text : string ) : Promise < void > {
83+ await navigator . clipboard . writeText ( text ) ;
84+ }
You can’t perform that action at this time.
0 commit comments