1+ import { Response } from '@/lib/api/response' ;
12import type { Config } from '@/lib/config/validate' ;
23import {
34 Anchor ,
@@ -16,10 +17,10 @@ import {
1617import { IconDownload , IconEyeFilled , IconGlobe , IconPercentage , IconWriting } from '@tabler/icons-react' ;
1718import Link from 'next/link' ;
1819import React , { useReducer , useState } from 'react' ;
20+ import useSWR from 'swr' ;
1921import { flameshot } from './generators/flameshot' ;
2022import { sharex } from './generators/sharex' ;
2123import { shell } from './generators/shell' ;
22- import { useUserStore } from '@/lib/store/user' ;
2324
2425export type GeneratorOptions = {
2526 deletesAt : string | null ;
@@ -30,6 +31,9 @@ export type GeneratorOptions = {
3031 overrides_returnDomain : string | null ;
3132 noJson : boolean | null ;
3233
34+ // changes {json:...} to $json:...$ for the Xshare app on Android
35+ sharex_xshareCompatibility : boolean | null ;
36+
3337 // echo instead of copying
3438 unix_useEcho : boolean | null ;
3539 // uses pbcopy instead of xclip
@@ -69,6 +73,8 @@ export const defaultGeneratorOptions: GeneratorOptions = {
6973 overrides_returnDomain : null ,
7074 noJson : null ,
7175
76+ sharex_xshareCompatibility : null ,
77+
7278 unix_useEcho : null ,
7379 mac_enableCompatibility : null ,
7480 wl_enableCompatibility : null ,
@@ -90,7 +96,6 @@ export default function GeneratorButton({
9096 icon : React . ReactNode ;
9197 desc ?: React . ReactNode ;
9298} ) {
93- const user = useUserStore ( ( state ) => state . user ) ;
9499 const [ opened , setOpen ] = useState ( false ) ;
95100
96101 const [ generatorType , setGeneratorType ] = useState ( 'file' ) ;
@@ -99,6 +104,8 @@ export default function GeneratorButton({
99104 defaultGeneratorOptions ,
100105 ) ;
101106
107+ const { data : tokenData , isLoading, error } = useSWR < Response [ '/api/user/token' ] > ( '/api/user/token' ) ;
108+
102109 const isUnixLike = name === 'Flameshot' || name === 'Shell Script' ;
103110 const onlyFile = generatorType === 'file' ;
104111
@@ -204,6 +211,16 @@ export default function GeneratorButton({
204211 disabled = { ! onlyFile }
205212 />
206213
214+ { name === 'ShareX' && (
215+ < Switch
216+ label = 'Xshare Compatibility'
217+ description = 'If you choose to use the Xshare app on Android, enable this option for compatibility. The genereated config will not work with ShareX.'
218+ checked = { options . sharex_xshareCompatibility ?? false }
219+ onChange = { ( event ) => setOption ( { sharex_xshareCompatibility : event . currentTarget . checked } ) }
220+ disabled = { ! onlyFile }
221+ />
222+ ) }
223+
207224 { isUnixLike && (
208225 < >
209226 < Switch
@@ -281,7 +298,7 @@ export default function GeneratorButton({
281298
282299 < Button
283300 onClick = { ( ) =>
284- generators [ name as keyof typeof generators ] ( user ! . token ! , generatorType as any , options )
301+ generators [ name as keyof typeof generators ] ( tokenData ! . token ! , generatorType as any , options )
285302 }
286303 fullWidth
287304 leftSection = { < IconDownload size = '1rem' /> }
@@ -292,7 +309,7 @@ export default function GeneratorButton({
292309 </ Stack >
293310 </ Modal >
294311
295- < Button size = 'sm' leftSection = { icon } onClick = { ( ) => setOpen ( true ) } >
312+ < Button size = 'sm' leftSection = { icon } onClick = { ( ) => setOpen ( true ) } disabled = { isLoading || error } >
296313 { name }
297314 </ Button >
298315 </ >
0 commit comments