Skip to content

Commit 8f91151

Browse files
committed
app: change locations without leaking IP
1 parent 52e7545 commit 8f91151

File tree

6 files changed

+22
-32
lines changed

6 files changed

+22
-32
lines changed

apple/client/command.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func handleWebViewCommand(command: Command) async throws(String) -> String {
5252
try unregisterAsLoginItem()
5353
case .isRegisteredAsLoginItem:
5454
return try isRegisteredAsLoginItem().json()
55-
5655
case .resetUserDefaults:
5756
// NOTE: only shown in the Developer View
5857
appState.resetUserDefaults()

obscura-ui/src/App.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ export default function () {
9393
})
9494
}, []);
9595

96-
async function tryConnect(exit: string | null = null, changingLocation = false) {
97-
if (!changingLocation) {
96+
async function tryConnect(exit: string | null = null) {
97+
if (vpnConnected) {
98+
setConnectionInProgress(ConnectionInProgress.ChangingLocations);
99+
} else {
98100
setConnectionInProgress(ConnectionInProgress.Connecting);
99101
}
100102
ignoreConnectingErrors.current = false;
@@ -132,21 +134,6 @@ export default function () {
132134
}
133135
}
134136

135-
async function disconnectThenConnect(exitId: string) {
136-
if (vpnConnected) {
137-
setConnectionInProgress(ConnectionInProgress.ChangingLocations);
138-
await commands.disconnectBlocking();
139-
notifications.update({
140-
id: NotificationId.VPN_DISCONNECT_CONNECT,
141-
color: theme.primaryColor,
142-
autoClose: 10_000,
143-
// keep same message
144-
message: undefined
145-
});
146-
await tryConnect(exitId, true);
147-
}
148-
}
149-
150137
function notifyVpnError(errorEnum: string) {
151138
// see enum JsVpnError in commands.swift
152139
if (errorEnum !== null) {
@@ -195,6 +182,7 @@ export default function () {
195182
notifyVpnError(connectError);
196183
}
197184
} else if (vpnStatus.disconnected !== undefined) {
185+
console.log('got disconnected')
198186
setConnectionInProgress(value => {
199187
if (value === ConnectionInProgress.ChangingLocations) return value;
200188
return ConnectionInProgress.UNSET;
@@ -361,7 +349,6 @@ export default function () {
361349
vpnConnect: tryConnect,
362350
vpnConnected,
363351
vpnDisconnect: disconnectFromVpn,
364-
vpnDisconnectConnect: disconnectThenConnect,
365352
}
366353

367354
const exitsContext = {

obscura-ui/src/common/appContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ interface IAppContext {
8989
toggleVpnConnection: () => Promise<void>,
9090
vpnConnect: (exit?: string) => Promise<void>,
9191
vpnDisconnect: () => Promise<void>,
92-
vpnDisconnectConnect: (exit: string) => Promise<void>,
9392
pollAccount: () => Promise<void>,
9493
accountLoading: boolean,
9594
appStatus: AppStatus,

obscura-ui/src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
"toggleTheme": "Toggle theme",
187187
"tosAndPrivacyPolicy": "Terms of Service and Privacy Policy",
188188
"trafficProtected": "Traffic is protected",
189+
"trafficSuspended": "Traffic is suspended",
189190
"trafficVulnerable": "Traffic is vulnerable",
190191
"unresponsiveDaemonError": "Daemon is Unresponsive ({{ timeStamp }})",
191192
"updateAvailable": "update available: v{{ version }}",

obscura-ui/src/views/ConnectionView.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ interface LocationSelectProps {
404404
function LocationSelect({ cityConnectingTo, setCityConnectingTo }: LocationSelectProps) {
405405
const { t } = useTranslation();
406406
const { exitList } = useContext(ExitsContext);
407-
const { appStatus, vpnConnect, vpnConnected, vpnDisconnectConnect, connectionInProgress, osStatus } = useContext(AppContext);
407+
const { appStatus, vpnConnect, vpnConnected, connectionInProgress, osStatus } = useContext(AppContext);
408408
const { internetAvailable } = osStatus;
409409
const { lastChosenExit, pinnedLocations } = appStatus;
410410
const connectedExit = appStatus.vpnStatus.connected?.exit;
@@ -506,11 +506,7 @@ function LocationSelect({ cityConnectingTo, setCityConnectingTo }: LocationSelec
506506
const exit = getRandomExitFromCity(exitList, country_code, city_code);
507507
setSelectedExit(exit);
508508
setCityConnectingTo(exit.city_name);
509-
if (vpnConnected) {
510-
vpnDisconnectConnect(exit.id);
511-
} else {
512-
vpnConnect(exit.id);
513-
}
509+
vpnConnect(exit.id);
514510
} catch (error) {
515511
const e = normalizeError(error);
516512
if (e instanceof CityNotFoundError) {

obscura-ui/src/views/LocationView.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import classes from './Location.module.css';
2626

2727
export default function LocationView() {
2828
const { t } = useTranslation();
29-
const { vpnConnected, vpnConnect, connectionInProgress, vpnDisconnectConnect, appStatus } = useContext(AppContext);
29+
const { vpnConnected, vpnConnect, connectionInProgress, appStatus } = useContext(AppContext);
3030
const { exitList } = useContext(ExitsContext);
3131

3232
const onExitSelect = async (exit: Exit) => {
@@ -42,7 +42,7 @@ export default function LocationView() {
4242
color: 'yellow.4',
4343
id: NotificationId.VPN_DISCONNECT_CONNECT
4444
});
45-
await vpnDisconnectConnect(exit.id);
45+
await vpnConnect(exit.id);
4646
} else if (exitList !== null) {
4747
try {
4848
exit = getRandomExitFromCity(exitList, exit.country_code, exit.city_code);
@@ -265,7 +265,7 @@ function VpnStatusCard() {
265265

266266
const getStatusTitle = () => {
267267
if (isOffline) return t('Offline');
268-
if (connectionInProgress !== ConnectionInProgress.UNSET && connectionInProgress !== ConnectionInProgress.ChangingLocations) return t(connectionInProgress) + '...';
268+
if (connectionInProgress !== ConnectionInProgress.UNSET) return t(connectionInProgress) + '...';
269269
const selectedLocation = appStatus.vpnStatus.connected?.exit.city_name;
270270
// vpnConnected <-> vpnStatus.connected.exit defined
271271
if (selectedLocation !== undefined) return t('connectedToLocation', { location: selectedLocation });
@@ -274,6 +274,9 @@ function VpnStatusCard() {
274274

275275
const getStatusSubtitle = () => {
276276
if (isOffline) return t('connectToInternet');
277+
if (connectionInProgress === ConnectionInProgress.ChangingLocations) {
278+
return t('trafficSuspended');
279+
}
277280
return vpnConnected ? t('trafficProtected') : t('trafficVulnerable');
278281
};
279282

@@ -294,15 +297,20 @@ function VpnStatusCard() {
294297
return t('busyConnection');
295298
};
296299

300+
const statusColor = vpnConnected ? 'green.7' : (connectionInProgress === ConnectionInProgress.ChangingLocations ? 'gray' : 'red.7');
301+
297302
return (
298303
<Card shadow='sm' padding='lg' radius='md' withBorder w='90%' mb='xs'>
299304
<Group justify='space-between'>
300305
<Stack gap={0}>
301306
<Group align='center' gap={5}>
302-
<ThemeIcon color={vpnConnected ? 'green.7' : 'red.7'} variant='transparent'>
303-
{vpnConnected ? <BsShieldFillCheck size={25} /> : <BsShieldFillExclamation size={25} />}
307+
<ThemeIcon color={statusColor} variant='transparent'>
308+
{connectionInProgress === ConnectionInProgress.ChangingLocations
309+
? <Loader size='xs' color='gray' /> : vpnConnected
310+
? <BsShieldFillCheck size={25} />
311+
: <BsShieldFillExclamation size={25} />}
304312
</ThemeIcon>
305-
<Title order={4} fw={600} c={vpnConnected ? 'green.7' : 'red.7'}>{getStatusTitle()}</Title>
313+
<Title order={4} fw={600} c={statusColor}>{getStatusTitle()}</Title>
306314
</Group>
307315
<Text c='gray' size='sm' ml={34}>{getStatusSubtitle()}</Text>
308316
</Stack>

0 commit comments

Comments
 (0)