Skip to content

Commit

Permalink
Merge branch 'Expensify:main' into arrow-feature-signed
Browse files Browse the repository at this point in the history
  • Loading branch information
JediWattson authored Dec 27, 2022
2 parents 7b7a5a0 + 276f177 commit 3738f1f
Show file tree
Hide file tree
Showing 45 changed files with 537 additions and 666 deletions.
10 changes: 10 additions & 0 deletions __mocks__/urbanairship-react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const EventType = {
PushReceived: 'pushReceived',
};

const iOS = {
ForegroundPresentationOption: {
Alert: 'alert',
Sound: 'sound',
Badge: 'badge',
},
};

const UrbanAirship = {
setUserNotificationsEnabled: jest.fn(),
clearNotifications: jest.fn(),
Expand All @@ -12,11 +20,13 @@ const UrbanAirship = {
setNamedUser: jest.fn(),
removeAllListeners: jest.fn(),
setBadgeNumber: jest.fn(),
setForegroundPresentationOptions: jest.fn(),
};

export default UrbanAirship;

export {
EventType,
iOS,
UrbanAirship,
};
14 changes: 14 additions & 0 deletions config/webpack/webpack.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ module.exports = (env) => {
__dirname: false,
__filename: false,
},
module: {
rules: [
{
test: /react-native-onyx/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react'],

},
},
},
],
},
};

return [mainProcessConfig, rendererConfig];
Expand Down
1 change: 1 addition & 0 deletions desktop/ELECTRON_EVENTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ELECTRON_EVENTS = {
UPDATE_DOWNLOADED: 'update-downloaded',
FOCUS: 'focus',
BLUR: 'blur',
LOCALE_UPDATED: 'locale-updated',
};

module.exports = ELECTRON_EVENTS;
1 change: 1 addition & 0 deletions desktop/contextBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [
ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT,
ELECTRON_EVENTS.REQUEST_VISIBILITY,
ELECTRON_EVENTS.START_UPDATE,
ELECTRON_EVENTS.LOCALE_UPDATED,
];

const WHITELIST_CHANNELS_MAIN_TO_RENDERER = [
Expand Down
163 changes: 107 additions & 56 deletions desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const log = require('electron-log');
const ELECTRON_EVENTS = require('./ELECTRON_EVENTS');
const checkForUpdates = require('../src/libs/checkForUpdates');
const CONFIG = require('../src/CONFIG').default;
const CONST = require('../src/CONST');
const Localize = require('../src/libs/Localize');

const port = process.env.PORT || 8080;

Expand Down Expand Up @@ -73,6 +75,11 @@ for (let i = 0; i < process.argv.length; i++) {
let hasUpdate = false;
let downloadedVersion;

// Note that we have to subscribe to this separately and cannot use Localize.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
let preferredLocale = CONST.DEFAULT_LOCALE;

const quitAndInstallWithUpdate = () => {
if (!downloadedVersion) {
return;
Expand Down Expand Up @@ -100,23 +107,23 @@ const manuallyCheckForUpdates = (menuItem, browserWindow) => {
if (downloadPromise) {
dialog.showMessageBox(browserWindow, {
type: 'info',
message: 'Update Available',
detail: 'The new version will be available shortly. We’ll notify you when we’re ready to update.',
buttons: ['Sounds good'],
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message'),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')],
});
} else if (result && result.error) {
dialog.showMessageBox(browserWindow, {
type: 'error',
message: 'Update Check Failed',
detail: 'We couldn’t look for an update. Please check again in a bit!',
buttons: ['Okay'],
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.message'),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
});
} else {
dialog.showMessageBox(browserWindow, {
type: 'info',
message: 'Update Not Available',
detail: 'There is no update available as of now! Check again at a later time.',
buttons: ['Okay'],
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.message'),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')],
cancelId: 2,
});
}
Expand All @@ -141,34 +148,14 @@ const showKeyboardShortcutsModal = (browserWindow) => {
browserWindow.webContents.send(ELECTRON_EVENTS.SHOW_KEYBOARD_SHORTCUTS_MODAL);
};

// Defines the system-level menu item to manually apply an update
// This menu item should become visible after an update is downloaded and ready to be applied
const updateAppMenuItem = new MenuItem({
label: 'Update New Expensify',
visible: false,
click: quitAndInstallWithUpdate,
});

// System-level menu item to manually check for App updates
const checkForUpdateMenuItem = new MenuItem({
label: 'Check For Updates',
visible: true,
click: manuallyCheckForUpdates,
});

// Defines the system-level menu item for opening keyboard shortcuts modal
const keyboardShortcutsMenu = new MenuItem({
label: 'View Keyboard Shortcuts',
accelerator: 'CmdOrCtrl+I',
});

// Actual auto-update listeners
const electronUpdater = browserWindow => ({
init: () => {
autoUpdater.on(ELECTRON_EVENTS.UPDATE_DOWNLOADED, (info) => {
const systemMenu = Menu.getApplicationMenu();
downloadedVersion = info.version;
updateAppMenuItem.visible = true;
checkForUpdateMenuItem.visible = false;
systemMenu.getMenuItemById(`updateAppMenuItem-${preferredLocale}`).visible = true;
systemMenu.getMenuItemById(`checkForUpdateMenuItem-${preferredLocale}`).visible = false;
if (browserWindow.isVisible()) {
browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version);
} else {
Expand All @@ -184,6 +171,61 @@ const electronUpdater = browserWindow => ({
},
});

/*
* @param {Menu} systemMenu
*/
const localizeMenuItems = (browserWindow, systemMenu) => {
// List the Expensify Chat instance under the Window menu, even when it's hidden
systemMenu.insert(4, new MenuItem({
id: `historyMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'desktopApplicationMenu.history'),
submenu: [{
id: `backMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'historyMenu.back'),
accelerator: process.platform === 'darwin' ? 'Cmd+[' : 'Shift+[',
click: () => { browserWindow.webContents.goBack(); },
},
{
id: `forwardMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'historyMenu.forward'),
accelerator: process.platform === 'darwin' ? 'Cmd+]' : 'Shift+]',
click: () => { browserWindow.webContents.goForward(); },
}],
}));

// Defines the system-level menu item to manually apply an update
// This menu item should become visible after an update is downloaded and ready to be applied
const updateAppMenuItem = new MenuItem({
id: `updateAppMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'desktopApplicationMenu.updateExpensify'),
visible: false,
click: quitAndInstallWithUpdate,
});

// System-level menu item to manually check for App updates
const checkForUpdateMenuItem = new MenuItem({
id: `checkForUpdateMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'desktopApplicationMenu.checkForUpdates'),
visible: true,
click: manuallyCheckForUpdates,
});

// Defines the system-level menu item for opening keyboard shortcuts modal
const keyboardShortcutsMenuItem = new MenuItem({
id: `keyboardShortcutsMenuItem-${preferredLocale}`,
label: Localize.translate(preferredLocale, 'initialSettingsPage.aboutPage.viewKeyboardShortcuts'),
accelerator: 'CmdOrCtrl+I',
click: () => {
showKeyboardShortcutsModal(browserWindow);
},
});

const appMenu = _.find(systemMenu.items, item => item.role === 'appmenu');
appMenu.submenu.insert(1, updateAppMenuItem);
appMenu.submenu.insert(2, checkForUpdateMenuItem);
appMenu.submenu.insert(3, keyboardShortcutsMenuItem);
};

const mainWindow = (() => {
const loadURL = __DEV__
? win => win.loadURL(`http://localhost:${port}`)
Expand Down Expand Up @@ -256,27 +298,7 @@ const mainWindow = (() => {
browserWindow.setTitle('New Expensify');
}

keyboardShortcutsMenu.click = () => {
showKeyboardShortcutsModal(browserWindow);
};

// List the Expensify Chat instance under the Window menu, even when it's hidden
const systemMenu = Menu.getApplicationMenu();
systemMenu.insert(4, new MenuItem({
label: 'History',
submenu: [{
role: 'back',
label: 'Back',
accelerator: process.platform === 'darwin' ? 'Cmd+[' : 'Shift+[',
click: () => { browserWindow.webContents.goBack(); },
},
{
role: 'forward',
label: 'Forward',
accelerator: process.platform === 'darwin' ? 'Cmd+]' : 'Shift+]',
click: () => { browserWindow.webContents.goForward(); },
}],
}));

// Register the custom Paste and Match Style command and place it near the default shortcut of the same role.
const editMenu = _.find(systemMenu.items, item => item.role === 'editmenu');
Expand All @@ -285,10 +307,8 @@ const mainWindow = (() => {
accelerator: 'CmdOrCtrl+Shift+V',
}));

const appMenu = _.find(systemMenu.items, item => item.role === 'appmenu');
appMenu.submenu.insert(1, updateAppMenuItem);
appMenu.submenu.insert(2, checkForUpdateMenuItem);
appMenu.submenu.insert(3, keyboardShortcutsMenu);
// Append custom context menu items using the preferred language of the user.
localizeMenuItems(browserWindow, systemMenu);

// On mac, pressing cmd++ actually sends a cmd+=. cmd++ is generally the zoom in shortcut, but this is
// not properly listened for by electron. Adding in an invisible cmd+= listener fixes this.
Expand Down Expand Up @@ -374,6 +394,37 @@ const mainWindow = (() => {
app.hide();
}

ipcMain.on(ELECTRON_EVENTS.LOCALE_UPDATED, (event, updatedLocale) => {
// Store the old locale so we can hide/remove these items after adding/showing the new ones.
const outdatedLocale = preferredLocale;
preferredLocale = updatedLocale;

const currentHistoryMenuItem = systemMenu.getMenuItemById(`historyMenuItem-${outdatedLocale}`);
const currentUpdateAppMenuItem = systemMenu.getMenuItemById(`updateAppMenuItem-${outdatedLocale}`);
const currentCheckForUpdateMenuItem = systemMenu.getMenuItemById(`checkForUpdateMenuItem-${outdatedLocale}`);
const currentKeyboardShortcutsMenuItem = systemMenu.getMenuItemById(`keyboardShortcutsMenuItem-${outdatedLocale}`);

// If we have previously added those languages, don't add new menu items, reshow them.
if (!systemMenu.getMenuItemById(`updateAppMenuItem-${updatedLocale}`)) {
// Update the labels and ids to use the translations.
localizeMenuItems(browserWindow, systemMenu);
}

// Show the localized menu items if there were visible before we updated the locale.
systemMenu.getMenuItemById(`updateAppMenuItem-${updatedLocale}`).visible = currentUpdateAppMenuItem.visible;
systemMenu.getMenuItemById(`checkForUpdateMenuItem-${updatedLocale}`).visible = currentCheckForUpdateMenuItem.visible;
systemMenu.getMenuItemById(`keyboardShortcutsMenuItem-${updatedLocale}`).visible = currentKeyboardShortcutsMenuItem.visible;
systemMenu.getMenuItemById(`historyMenuItem-${updatedLocale}`).visible = currentHistoryMenuItem.visible;

// Since we can't remove menu items, we hide the old ones.
currentUpdateAppMenuItem.visible = false;
currentCheckForUpdateMenuItem.visible = false;
currentKeyboardShortcutsMenuItem.visible = false;
currentHistoryMenuItem.visible = false;

Menu.setApplicationMenu(systemMenu);
});

ipcMain.on(ELECTRON_EVENTS.REQUEST_VISIBILITY, (event) => {
// This is how synchronous messages work in Electron
// eslint-disable-next-line no-param-reassign
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"copy-webpack-plugin": "^6.4.1",
"css-loader": "^5.2.4",
"diff-so-fancy": "^1.3.0",
"electron": "^21.0.0",
"electron": "^21.2.2",
"electron-builder": "23.5.0",
"electron-notarize": "^1.2.1",
"eslint": "^7.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarWithImagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class AvatarWithImagePicker extends React.Component {
src={Expensicons.Camera}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
fill={themeColors.iconReversed}
fill={themeColors.textLight}
/>
</View>
</Tooltip>
Expand Down
Loading

0 comments on commit 3738f1f

Please sign in to comment.