Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix location Permission for Desktop #57660

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
71a1efd
fix permission from in desktop
wildan-m Feb 11, 2025
a6aab02
Add loading spinner to button when confirming
wildan-m Feb 11, 2025
614bb06
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Feb 12, 2025
52c289d
Resolve conflict
wildan-m Feb 12, 2025
5784e16
pre-fetch location
wildan-m Feb 12, 2025
c36d808
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Feb 13, 2025
9ffbc71
clear user location for prefetch
wildan-m Feb 14, 2025
302b1e3
fix incorrect long lat assignment
wildan-m Feb 14, 2025
8db0bb2
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Feb 26, 2025
8af7e50
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Feb 27, 2025
eea3a21
revert unnecessary changes
wildan-m Feb 27, 2025
7489faf
listen is visible change when refocus window
wildan-m Feb 27, 2025
7baaebb
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Feb 28, 2025
40b3124
check location permission periodically and when re-focus
wildan-m Feb 28, 2025
92e78dd
Remove app relaunch
wildan-m Feb 28, 2025
964c9fa
handle web issue
wildan-m Feb 28, 2025
e323b7b
Fix desktop and web
wildan-m Feb 28, 2025
bd0da9d
remove desktop specific code
wildan-m Mar 1, 2025
73bf311
prettier lint, WIP mweb
wildan-m Mar 1, 2025
0c5de91
Lint & prettier
wildan-m Mar 3, 2025
383b288
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Mar 3, 2025
459467d
Fix lint
wildan-m Mar 3, 2025
3e7bf42
remove unnecessary code, add comment
wildan-m Mar 3, 2025
3500f6a
Add comment for new use effect
wildan-m Mar 3, 2025
7dc9f8e
prettier
wildan-m Mar 3, 2025
2abb0a0
Update src/pages/iou/request/step/IOURequestStepScan/index.tsx
wildan-m Mar 4, 2025
771ee77
Update desktop/ELECTRON_EVENTS.ts
wildan-m Mar 4, 2025
be69a58
Update src/components/LocationPermissionModal/index.tsx
wildan-m Mar 4, 2025
822bc01
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Mar 4, 2025
c328cbc
remove unnecessary code
wildan-m Mar 4, 2025
3c223f9
remove unnecessary argument
wildan-m Mar 4, 2025
4707278
remove open setting for non mac desktop
wildan-m Mar 4, 2025
463c3d3
add loading feedback after user clicking continue/setting button
wildan-m Mar 4, 2025
9d6b488
more specific prop comment
wildan-m Mar 4, 2025
b017d3a
make desktop specific code for LocationPermissionModal
wildan-m Mar 4, 2025
f14fa25
prettier & lint
wildan-m Mar 4, 2025
b7ffed7
restore setShowModal position
wildan-m Mar 4, 2025
f0646b5
Merge branch 'main' of https://github.com/wildan-m/App into wildan/fi…
wildan-m Mar 5, 2025
f15e586
remove unused code
wildan-m Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/ELECTRON_EVENTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ELECTRON_EVENTS = {
DOWNLOAD_FAILED: 'download-started',
DOWNLOAD_CANCELED: 'download-canceled',
SILENT_UPDATE: 'silent-update',
OPEN_LOCATION_SETTING: 'open-location-setting',
} as const;

export default ELECTRON_EVENTS;
1 change: 1 addition & 0 deletions desktop/contextBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [
ELECTRON_EVENTS.LOCALE_UPDATED,
ELECTRON_EVENTS.DOWNLOAD,
ELECTRON_EVENTS.SILENT_UPDATE,
ELECTRON_EVENTS.OPEN_LOCATION_SETTING,
] as const;

const WHITELIST_CHANNELS_MAIN_TO_RENDERER = [
Expand Down
81 changes: 50 additions & 31 deletions desktop/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {exec} from 'child_process';
import {app, BrowserWindow, clipboard, dialog, ipcMain, Menu, shell} from 'electron';
import type {BaseWindow, BrowserView, MenuItem, MenuItemConstructorOptions, WebContents, WebviewTag} from 'electron';
import contextMenu from 'electron-context-menu';
Expand All @@ -6,7 +7,7 @@ import type {ElectronLog} from 'electron-log';
import {autoUpdater} from 'electron-updater';
import {machineId} from 'node-machine-id';
import checkForUpdates from '@libs/checkForUpdates';
import * as Localize from '@libs/Localize';
import {translate} from '@libs/Localize';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -71,20 +72,20 @@ function pasteAsPlainText(browserWindow: BrowserWindow | BrowserView | WebviewTa
function createContextMenu(preferredLocale: Locale = LOCALES.DEFAULT): () => void {
return contextMenu({
labels: {
cut: Localize.translate(preferredLocale, 'desktopApplicationMenu.cut'),
paste: Localize.translate(preferredLocale, 'desktopApplicationMenu.paste'),
copy: Localize.translate(preferredLocale, 'desktopApplicationMenu.copy'),
cut: translate(preferredLocale, 'desktopApplicationMenu.cut'),
paste: translate(preferredLocale, 'desktopApplicationMenu.paste'),
copy: translate(preferredLocale, 'desktopApplicationMenu.copy'),
},
append: (defaultActions, parameters, browserWindow) => [
{
// Only enable the menu item for Editable context which supports paste
visible: parameters.isEditable && parameters.editFlags.canPaste,
role: 'pasteAndMatchStyle',
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE,
label: Localize.translate(preferredLocale, 'desktopApplicationMenu.pasteAndMatchStyle'),
label: translate(preferredLocale, 'desktopApplicationMenu.pasteAndMatchStyle'),
},
{
label: Localize.translate(preferredLocale, 'desktopApplicationMenu.pasteAsPlainText'),
label: translate(preferredLocale, 'desktopApplicationMenu.pasteAsPlainText'),
visible: parameters.isEditable && parameters.editFlags.canPaste && clipboard.readText().length > 0,
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT,
click: () => pasteAsPlainText(browserWindow),
Expand Down Expand Up @@ -126,7 +127,7 @@ let hasUpdate = false;
let downloadedVersion: string;
let isSilentUpdating = false;

// Note that we have to subscribe to this separately and cannot use Localize.translateLocal,
// Note that we have to subscribe to this separately and cannot use translateLocal,
// because the only way code can be shared between the main and renderer processes at runtime is via the context bridge
// So we track preferredLocale separately via ELECTRON_EVENTS.LOCALE_UPDATED
const preferredLocale: Locale = CONST.LOCALES.DEFAULT;
Expand Down Expand Up @@ -165,23 +166,23 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BaseWindow
if (downloadPromise) {
dialog.showMessageBox(browserWindow, {
type: 'info',
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdating}),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')],
message: translate(preferredLocale, 'checkForUpdatesModal.available.title'),
detail: translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdating}),
buttons: [translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')],
});
} else if (result && 'error' in result && result.error) {
dialog.showMessageBox(browserWindow, {
type: 'error',
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.message'),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
message: translate(preferredLocale, 'checkForUpdatesModal.error.title'),
detail: translate(preferredLocale, 'checkForUpdatesModal.error.message'),
buttons: [translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
});
} else {
dialog.showMessageBox(browserWindow, {
type: 'info',
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.message'),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
message: translate(preferredLocale, 'checkForUpdatesModal.notAvailable.title'),
detail: translate(preferredLocale, 'checkForUpdatesModal.notAvailable.message'),
buttons: [translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
cancelId: 2,
});
}
Expand Down Expand Up @@ -242,7 +243,7 @@ const localizeMenuItems = (submenu: MenuItemConstructorOptions[], updatedLocale:
submenu.map((menu) => {
const newMenu: MenuItemConstructorOptions = {...menu};
if (menu.id) {
const labelTranslation = Localize.translate(updatedLocale, `desktopApplicationMenu.${menu.id}` as TranslationPaths);
const labelTranslation = translate(updatedLocale, `desktopApplicationMenu.${menu.id}` as TranslationPaths);
if (labelTranslation) {
newMenu.label = labelTranslation;
}
Expand Down Expand Up @@ -310,7 +311,25 @@ const mainWindow = (): Promise<void> => {
});

ipcMain.handle(ELECTRON_EVENTS.REQUEST_DEVICE_ID, () => machineId());
ipcMain.handle(ELECTRON_EVENTS.OPEN_LOCATION_SETTING, () => {
if (process.platform !== 'darwin') {
// Platform not supported for location settings
return Promise.resolve(undefined);
}

return new Promise((resolve, reject) => {
const command = 'open x-apple.systempreferences:com.apple.preference.security?Privacy_Location';

exec(command, (error) => {
if (error) {
console.error('Error opening location settings:', error);
reject(error);
return;
}
resolve(undefined);
});
});
});
/*
* The default origin of our Electron app is app://- instead of https://new.expensify.com or https://staging.new.expensify.com
* This causes CORS errors because the referer and origin headers are wrong and the API responds with an Access-Control-Allow-Origin that doesn't match app://-
Expand Down Expand Up @@ -353,14 +372,14 @@ const mainWindow = (): Promise<void> => {
const initialMenuTemplate: MenuItemConstructorOptions[] = [
{
id: 'mainMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.mainMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.mainMenu`),
submenu: [
{id: 'about', role: 'about'},
{id: 'update', label: Localize.translate(preferredLocale, `desktopApplicationMenu.update`), click: quitAndInstallWithUpdate, visible: false},
{id: 'checkForUpdates', label: Localize.translate(preferredLocale, `desktopApplicationMenu.checkForUpdates`), click: manuallyCheckForUpdates},
{id: 'update', label: translate(preferredLocale, `desktopApplicationMenu.update`), click: quitAndInstallWithUpdate, visible: false},
{id: 'checkForUpdates', label: translate(preferredLocale, `desktopApplicationMenu.checkForUpdates`), click: manuallyCheckForUpdates},
{
id: 'viewShortcuts',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.viewShortcuts`),
label: translate(preferredLocale, `desktopApplicationMenu.viewShortcuts`),
accelerator: 'CmdOrCtrl+J',
click: () => {
showKeyboardShortcutsPage(browserWindow);
Expand All @@ -378,12 +397,12 @@ const mainWindow = (): Promise<void> => {
},
{
id: 'fileMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.fileMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.fileMenu`),
submenu: [{id: 'closeWindow', role: 'close', accelerator: 'Cmd+w'}],
},
{
id: 'editMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.editMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.editMenu`),
submenu: [
{id: 'undo', role: 'undo'},
{id: 'redo', role: 'redo'},
Expand All @@ -406,7 +425,7 @@ const mainWindow = (): Promise<void> => {
{type: 'separator'},
{
id: 'speechSubmenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.speechSubmenu`),
label: translate(preferredLocale, `desktopApplicationMenu.speechSubmenu`),
submenu: [
{id: 'startSpeaking', role: 'startSpeaking'},
{id: 'stopSpeaking', role: 'stopSpeaking'},
Expand All @@ -416,7 +435,7 @@ const mainWindow = (): Promise<void> => {
},
{
id: 'viewMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.viewMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.viewMenu`),
submenu: [
{id: 'reload', role: 'reload'},
{id: 'forceReload', role: 'forceReload'},
Expand All @@ -431,7 +450,7 @@ const mainWindow = (): Promise<void> => {
},
{
id: 'historyMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.historyMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.historyMenu`),
submenu: [
{
id: 'back',
Expand Down Expand Up @@ -472,33 +491,33 @@ const mainWindow = (): Promise<void> => {
},
{
id: 'helpMenu',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.helpMenu`),
label: translate(preferredLocale, `desktopApplicationMenu.helpMenu`),
role: 'help',
submenu: [
{
id: 'learnMore',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.learnMore`),
label: translate(preferredLocale, `desktopApplicationMenu.learnMore`),
click: () => {
shell.openExternal(CONST.MENU_HELP_URLS.LEARN_MORE);
},
},
{
id: 'documentation',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.documentation`),
label: translate(preferredLocale, `desktopApplicationMenu.documentation`),
click: () => {
shell.openExternal(CONST.MENU_HELP_URLS.DOCUMENTATION);
},
},
{
id: 'communityDiscussions',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.communityDiscussions`),
label: translate(preferredLocale, `desktopApplicationMenu.communityDiscussions`),
click: () => {
shell.openExternal(CONST.MENU_HELP_URLS.COMMUNITY_DISCUSSIONS);
},
},
{
id: 'searchIssues',
label: Localize.translate(preferredLocale, `desktopApplicationMenu.searchIssues`),
label: translate(preferredLocale, `desktopApplicationMenu.searchIssues`),
click: () => {
shell.openExternal(CONST.MENU_HELP_URLS.SEARCH_ISSUES);
},
Expand Down
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ const CONST = {
USE_DEBOUNCED_STATE_DELAY: 300,
LIST_SCROLLING_DEBOUNCE_TIME: 200,
PUSHER_PING_PONG: 'pusher_ping_pong',
LOCATION_UPDATE_INTERVAL: 5000,
},
PRIORITY_MODE: {
GSD: 'gsd',
Expand Down
6 changes: 6 additions & 0 deletions src/components/ConfirmContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type ConfirmContentProps = {

/** Whether the modal is visibile */
isVisible: boolean;

/** Whether the confirm button is loading */
isConfirmLoading?: boolean;
};

function ConfirmContent({
Expand Down Expand Up @@ -127,6 +130,7 @@ function ConfirmContent({
titleContainerStyles,
shouldReverseStackedButtons = false,
isVisible,
isConfirmLoading,
}: ConfirmContentProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand Down Expand Up @@ -209,6 +213,7 @@ function ConfirmContent({
text={confirmText || translate('common.yes')}
accessibilityLabel={confirmText || translate('common.yes')}
isDisabled={isOffline && shouldDisableConfirmButtonWhenOffline}
isLoading={isConfirmLoading}
/>
{shouldShowCancelButton && !shouldReverseStackedButtons && (
<Button
Expand Down Expand Up @@ -237,6 +242,7 @@ function ConfirmContent({
isPressOnEnterActive={isVisible}
text={confirmText || translate('common.yes')}
isDisabled={isOffline && shouldDisableConfirmButtonWhenOffline}
isLoading={isConfirmLoading}
/>
</View>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/components/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ type ConfirmModalProps = {

/** How to re-focus after the modal is dismissed */
restoreFocusType?: BaseModalProps['restoreFocusType'];

/** Whether the confirm button is loading */
isConfirmLoading?: boolean;
};

function ConfirmModal({
Expand Down Expand Up @@ -135,6 +138,7 @@ function ConfirmModal({
shouldReverseStackedButtons,
shouldEnableNewFocusManagement,
restoreFocusType,
isConfirmLoading,
}: ConfirmModalProps) {
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to use the correct modal type
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
Expand Down Expand Up @@ -182,6 +186,7 @@ function ConfirmModal({
shouldStackButtons={shouldStackButtons}
shouldReverseStackedButtons={shouldReverseStackedButtons}
image={image}
isConfirmLoading={isConfirmLoading}
/>
</Modal>
);
Expand Down
34 changes: 21 additions & 13 deletions src/components/LocationPermissionModal/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {getLocationPermission, requestLocationPermission} from '@pages/iou/request/step/IOURequestStepScan/LocationPermission';
import type {LocationPermissionModalProps} from './types';

function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDeny, onGrant}: LocationPermissionModalProps) {
function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDeny, onGrant, onInitialGetLocationCompleted}: LocationPermissionModalProps) {
const [hasError, setHasError] = useState(false);
const [showModal, setShowModal] = useState(false);
const [isLoading, setIsLoading] = useState(false);

const styles = useThemeStyles();
const {translate} = useLocalize();
Expand All @@ -21,6 +22,7 @@ function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDe
}

getLocationPermission().then((status) => {
onInitialGetLocationCompleted?.();
if (status === RESULTS.GRANTED || status === RESULTS.LIMITED) {
return onGrant();
}
Expand All @@ -32,6 +34,7 @@ function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDe
}, [startPermissionFlow]);

const handledBlockedPermission = (cb: () => void) => () => {
setIsLoading(true);
if (hasError && Linking.openSettings) {
Linking.openSettings();
setShowModal(false);
Expand All @@ -43,18 +46,22 @@ function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDe
};

const grantLocationPermission = handledBlockedPermission(() => {
requestLocationPermission().then((status) => {
if (status === RESULTS.GRANTED || status === RESULTS.LIMITED) {
onGrant();
} else if (status === RESULTS.BLOCKED) {
setHasError(true);
return;
} else {
onDeny();
}
setShowModal(false);
setHasError(false);
});
requestLocationPermission()
.then((status) => {
if (status === RESULTS.GRANTED || status === RESULTS.LIMITED) {
onGrant();
} else if (status === RESULTS.BLOCKED) {
setHasError(true);
return;
} else {
onDeny();
}
setShowModal(false);
setHasError(false);
})
.finally(() => {
setIsLoading(false);
});
});

const skipLocationPermission = () => {
Expand Down Expand Up @@ -87,6 +94,7 @@ function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDe
iconHeight={120}
shouldCenterIcon
shouldReverseStackedButtons
isConfirmLoading={isLoading}
/>
);
}
Expand Down
Loading