From a0ee73b516a5d0ff03d5bab72ed75e72ffd4f23f Mon Sep 17 00:00:00 2001 From: Benjamin Leclerc Date: Mon, 19 Apr 2021 10:05:26 +0200 Subject: [PATCH] Upgrade to Google APIs 71 --- CHANGELOG.md | 1 + craco.config.js | 3 - package.json | 2 +- public/electronIpc.js | 81 +++++++++++ public/electronPreload.js | 12 +- src/App.js | 6 +- src/actions/AutoUpdaterActions.js | 14 +- .../googlecal/GoogleCalAccountInfoActions.js | 18 +-- .../GoogleCalAuthorizationActions.js | 38 ++--- .../googlecal/GoogleCalEventActions.js | 38 +++-- src/events.js | 4 +- src/mock-fs.js | 5 - src/shortcuts.js | 58 ++++---- src/utils/ElectronIpc.js | 132 +++++++++--------- yarn.lock | 121 ++++++++-------- 15 files changed, 288 insertions(+), 245 deletions(-) delete mode 100644 src/mock-fs.js diff --git a/CHANGELOG.md b/CHANGELOG.md index cb376e54..055a62f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## New Features * Upgrade to Electron 12 +* Upgrade to Google APIs 71 ## Bug Fixes diff --git a/craco.config.js b/craco.config.js index f372f733..7d004ba4 100644 --- a/craco.config.js +++ b/craco.config.js @@ -17,9 +17,6 @@ module.exports = { } }, webpack: { - alias: { - fs: path.resolve(__dirname, 'src/mock-fs.js') - }, configure: webpackConfig => { webpackConfig.module.rules.push({ test: /\.worker\.js$/, diff --git a/package.json b/package.json index f5ef1206..a7d5a4e3 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "electron-log": "^4.3.4", "electron-updater": "^4.3.8", "fs-extra": "^9.1.0", - "googleapis": "^48.0.0", + "googleapis": "^71.0.0", "https-proxy-agent": "^5.0.0", "inputmask-core": "^2.2.0", "jspdf": "^2.3.1", diff --git a/public/electronIpc.js b/public/electronIpc.js index 18c72d6b..22b22327 100644 --- a/public/electronIpc.js +++ b/public/electronIpc.js @@ -4,10 +4,14 @@ const { app, dialog, ipcMain, shell, BrowserWindow } = require('electron'); const { autoUpdater, CancellationToken } = require('electron-updater'); const log = require('electron-log'); const fse = require('fs-extra'); +const { google } = require('googleapis'); const HttpsProxyAgent = require('https-proxy-agent'); const os = require('os'); const path = require('path'); +let googleAuthClient = null; +let googleCalendarClient = null; + async function sendRequest(axiosInstance, config) { const result = await axiosInstance(config); @@ -137,6 +141,83 @@ function initializeIpc(setQuitInitiated) { return fse.writeFile(file, data); }); + ipcMain.handle('google-set-auth-client', (event, config, settings) => { + const client = new google.auth.OAuth2( + config.clientId, + config.clientSecret, + config.redirectUri + ); + + if (settings && settings.tokens) { + client.setCredentials(settings.tokens); + } + + googleAuthClient = client; + }); + + ipcMain.handle('google-set-calendar-client', () => { + const client = google.calendar({ + version: 'v3', + auth: googleAuthClient + }); + + googleCalendarClient = client; + }); + + ipcMain.handle('google-generate-auth-url', async () => { + const url = googleAuthClient.generateAuthUrl({ + access_type: 'offline', + prompt: 'consent', + scope: [ + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile', + 'https://www.googleapis.com/auth/calendar' + ] + }); + + return url; + }); + + ipcMain.handle('google-get-tokens', async (event, code) => { + const { tokens } = await googleAuthClient.getToken(code); + return tokens; + }); + + ipcMain.handle('google-get-user-info', async () => { + const profile = google.oauth2({ + version: 'v2', + auth: googleAuthClient + }); + + const result = await profile.userinfo.get(); + return result.data; + }); + + ipcMain.handle('google-calendars-list', async (event, data) => { + const result = await googleCalendarClient.calendarList.list(data); + return result.data; + }); + + ipcMain.handle('google-calendars-insert', async (event, data) => { + const result = await googleCalendarClient.calendars.insert(data); + return result.data; + }); + + ipcMain.handle('google-events-list', async (event, data) => { + const result = await googleCalendarClient.events.list(data); + return result.data; + }); + + ipcMain.handle('google-events-insert', async (event, data) => { + const result = await googleCalendarClient.events.insert(data); + return result.data; + }); + + ipcMain.handle('google-events-delete', async (event, data) => { + const result = await googleCalendarClient.events.delete(data); + return result.data; + }); + ipcMain.handle('initiate-quit', () => { setQuitInitiated(true); }); diff --git a/public/electronPreload.js b/public/electronPreload.js index adbe9a53..51ffe0ba 100644 --- a/public/electronPreload.js +++ b/public/electronPreload.js @@ -3,10 +3,12 @@ const { contextBridge, ipcRenderer } = require('electron'); contextBridge.exposeInMainWorld( 'electron', { - invoke: (channel, ...args) => ipcRenderer.invoke(channel, ...args), - on: (channel, listener) => ipcRenderer.on(channel, listener), - removeListener: (channel, listener) => ipcRenderer.removeListener(channel, listener), - send: (channel, ...args) => ipcRenderer.send(channel, ...args), - sendSync: (channel, ...args) => ipcRenderer.sendSync(channel, ...args) + ipcRenderer: { + invoke: (channel, ...args) => ipcRenderer.invoke(channel, ...args), + on: (channel, listener) => ipcRenderer.on(channel, listener), + removeListener: (channel, listener) => ipcRenderer.removeListener(channel, listener), + send: (channel, ...args) => ipcRenderer.send(channel, ...args), + sendSync: (channel, ...args) => ipcRenderer.sendSync(channel, ...args) + } } ); \ No newline at end of file diff --git a/src/App.js b/src/App.js index a8daefc0..98e4c3b9 100644 --- a/src/App.js +++ b/src/App.js @@ -104,12 +104,12 @@ function App() { } }; - const electron = window.electron; + const { ipcRenderer } = window.electron; - electron.on('window-close', onClose); + ipcRenderer.on('window-close', onClose); return () => { - electron.removeListener('window-close', onClose); + ipcRenderer.removeListener('window-close', onClose); }; } }, [ // eslint-disable-line react-hooks/exhaustive-deps diff --git a/src/actions/AutoUpdaterActions.js b/src/actions/AutoUpdaterActions.js index 4e827aa2..272d99ca 100644 --- a/src/actions/AutoUpdaterActions.js +++ b/src/actions/AutoUpdaterActions.js @@ -84,7 +84,7 @@ export function checkForUpdates(quiet) { export function downloadUpdate() { return async dispatch => { return new Promise((resolve, reject) => { - const electron = window.electron; + const { ipcRenderer } = window.electron; const downloadProgressHandler = (event, info) => { logger.debug('Download progress', info.percent); @@ -94,13 +94,13 @@ export function downloadUpdate() { const updateDownloadedHandler = (event, info) => { logger.debug('Update downloaded', info); dispatch(setUpdateDownloaded(info)); - electron.removeListener('download-progress', downloadProgressHandler); - electron.removeListener('update-downloaded', updateDownloadedHandler); + ipcRenderer.removeListener('download-progress', downloadProgressHandler); + ipcRenderer.removeListener('update-downloaded', updateDownloadedHandler); resolve(info); }; - electron.on('download-progress', downloadProgressHandler); - electron.on('update-downloaded', updateDownloadedHandler); + ipcRenderer.on('download-progress', downloadProgressHandler); + ipcRenderer.on('update-downloaded', updateDownloadedHandler); logger.info('Download update'); @@ -109,8 +109,8 @@ export function downloadUpdate() { electronDownloadUpdate().catch(e => { logger.error('Download update error', e); - electron.removeListener('download-progress', downloadProgressHandler); - electron.removeListener('update-downloaded', updateDownloadedHandler); + ipcRenderer.removeListener('download-progress', downloadProgressHandler); + ipcRenderer.removeListener('update-downloaded', updateDownloadedHandler); reject(e); }); }); diff --git a/src/actions/publication/googlecal/GoogleCalAccountInfoActions.js b/src/actions/publication/googlecal/GoogleCalAccountInfoActions.js index 5b8b6bbe..b95498cb 100644 --- a/src/actions/publication/googlecal/GoogleCalAccountInfoActions.js +++ b/src/actions/publication/googlecal/GoogleCalAccountInfoActions.js @@ -1,26 +1,20 @@ -import { google } from 'googleapis'; import { setPublicationData } from 'actions/PublicationActions'; -import { getClient } from 'actions/publication/googlecal/GoogleCalAuthorizationActions'; +import { setAuthClient } from 'actions/publication/googlecal/GoogleCalAuthorizationActions'; import { getSettings } from 'selectors/SettingSelectors'; import logger from 'utils/LogUtils'; export function getGoogleCalAccountInfo() { return async (dispatch, getState) => { const settings = getSettings(getState()); + setAuthClient(settings); - const client = getClient(settings); + const { ipcRenderer } = window.electron; + const userInfo = await ipcRenderer.invoke('google-get-user-info'); - const profile = google.oauth2({ - version: 'v2', - auth: client - }); - - const result = await profile.userinfo.get(); - - logger.debug('Get account info', result.data); + logger.debug('Get account info', userInfo); await dispatch(setPublicationData('googlecal', { - accountInfo: result.data + accountInfo: userInfo })); }; } \ No newline at end of file diff --git a/src/actions/publication/googlecal/GoogleCalAuthorizationActions.js b/src/actions/publication/googlecal/GoogleCalAuthorizationActions.js index fe2e9883..0d03c420 100644 --- a/src/actions/publication/googlecal/GoogleCalAuthorizationActions.js +++ b/src/actions/publication/googlecal/GoogleCalAuthorizationActions.js @@ -1,37 +1,24 @@ -import { google } from 'googleapis'; import { updateSettings } from 'actions/SettingActions'; import { getConfig } from 'config/Config'; import { openExternal } from 'utils/ElectronIpc'; import logger from 'utils/LogUtils'; -export function getClient(settings = null) { - const client = new google.auth.OAuth2( - getConfig().publication.googlecal.clientId, - getConfig().publication.googlecal.clientSecret, - getConfig().publication.googlecal.redirectUri - ); - - if (settings && settings.googlecal && settings.googlecal.tokens) { - client.setCredentials(settings.googlecal.tokens); - } +export function setAuthClient(settings = null) { + const { ipcRenderer } = window.electron; + ipcRenderer.invoke('google-set-auth-client', getConfig().publication.googlecal, settings ? settings.googlecal : null); +} - return client; +export function setCalendarClient() { + const { ipcRenderer } = window.electron; + ipcRenderer.invoke('google-set-calendar-client'); } export function authorize() { return async () => { - const client = getClient(); - - const url = client.generateAuthUrl({ - access_type: 'offline', - prompt: 'consent', - scope: [ - 'https://www.googleapis.com/auth/userinfo.email', - 'https://www.googleapis.com/auth/userinfo.profile', - 'https://www.googleapis.com/auth/calendar' - ] - }); + setAuthClient(); + const { ipcRenderer } = window.electron; + const url = await ipcRenderer.invoke('google-generate-auth-url'); openExternal(url); }; } @@ -40,9 +27,10 @@ export function createToken(code) { logger.debug('Create token', code); return async dispatch => { - const client = getClient(); + setAuthClient(); - const { tokens } = await client.getToken(code); + const { ipcRenderer } = window.electron; + const tokens = await ipcRenderer.invoke('google-get-tokens', code); await dispatch(updateSettings({ googlecal: { diff --git a/src/actions/publication/googlecal/GoogleCalEventActions.js b/src/actions/publication/googlecal/GoogleCalEventActions.js index c0addc02..b0b2ae7c 100644 --- a/src/actions/publication/googlecal/GoogleCalEventActions.js +++ b/src/actions/publication/googlecal/GoogleCalEventActions.js @@ -1,6 +1,5 @@ -import { google } from 'googleapis'; import moment from 'moment'; -import { getClient } from 'actions/publication/googlecal/GoogleCalAuthorizationActions'; +import { setAuthClient, setCalendarClient } from 'actions/publication/googlecal/GoogleCalAuthorizationActions'; import { getLocationsFilteredByVisibleState } from 'selectors/LocationSelectors'; import { getSettings } from 'selectors/SettingSelectors'; import { getTasksFilteredByVisibleState } from 'selectors/TaskSelectors'; @@ -26,39 +25,37 @@ export function publishEvents() { const publishMaxDaysInPast = settings.googlecalPublishMaxDaysInPast; const publishMaxDaysInFuture = settings.googlecalPublishMaxDaysInFuture; - const client = getClient(settings); + setAuthClient(settings); + setCalendarClient(); - const calendarClient = google.calendar({ - version: 'v3', - auth: client - }); + const { ipcRenderer } = window.electron; - const calendarListResult = await calendarClient.calendarList.list(); + const calendarListResult = await ipcRenderer.invoke('google-calendars-list'); - let calendar = calendarListResult.data.items.find(item => item.summary === calendarName); + let calendar = calendarListResult.items.find(item => item.summary === calendarName); const events = []; if (calendar) { logger.debug('Calendar found', calendar.id); - const eventListResult = await calendarClient.events.list({ + const eventListResult = await ipcRenderer.invoke('google-events-list', { calendarId: calendar.id }); - logger.debug('Calendar events retrieved', eventListResult.data.items.length); + logger.debug('Calendar events retrieved', eventListResult.items.length); - events.push(...eventListResult.data.items); + events.push(...eventListResult.items); } else { - const calendarInsertResult = await calendarClient.calendars.insert({ + const calendarInsertResult = await ipcRenderer.invoke('google-calendars-insert', { requestBody: { summary: calendarName, description: 'Created by TaskUnifier' } }); - logger.debug('Calendar created', calendarInsertResult.data); + logger.debug('Calendar created', calendarInsertResult); - calendar = calendarInsertResult.data; + calendar = calendarInsertResult; } for (let task of tasks) { @@ -76,7 +73,6 @@ export function publishEvents() { } await publishEvent( - calendarClient, events, calendar, task, @@ -95,7 +91,6 @@ export function publishEvents() { } await publishEvent( - calendarClient, events, calendar, task, @@ -117,7 +112,6 @@ export function publishEvents() { } await publishEvent( - calendarClient, events, calendar, task, @@ -132,7 +126,7 @@ export function publishEvents() { } for (let event of events) { - await calendarClient.events.delete({ + await ipcRenderer.invoke('google-events-delete', { calendarId: calendar.id, eventId: event.id }); @@ -177,7 +171,7 @@ function createEvent(task, startDate, endDate, colorId, useTime, locations) { return event; } -async function publishEvent(calendarClient, events, calendar, task, startDate, endDate, colorId, useTime, locations) { +async function publishEvent(events, calendar, task, startDate, endDate, colorId, useTime, locations) { const newEvent = createEvent(task, startDate, endDate, colorId, useTime, locations); let event = events.find(event => { @@ -204,7 +198,9 @@ async function publishEvent(calendarClient, events, calendar, task, startDate, e return; } - await calendarClient.events.insert({ + const { ipcRenderer } = window.electron; + + await ipcRenderer.invoke('google-events-insert', { calendarId: calendar.id, requestBody: newEvent }); diff --git a/src/events.js b/src/events.js index 704422cf..66eba08f 100644 --- a/src/events.js +++ b/src/events.js @@ -3,9 +3,9 @@ import logger from 'utils/LogUtils'; export function initializeEvents() { if (process.env.REACT_APP_MODE === 'electron') { - const electron = window.electron; + const { ipcRenderer } = window.electron; - electron.on('open-url', async (event, url) => { + ipcRenderer.on('open-url', async (event, url) => { logger.debug('Open URL', url); const u = new URL(url); diff --git a/src/mock-fs.js b/src/mock-fs.js deleted file mode 100644 index 953c34a5..00000000 --- a/src/mock-fs.js +++ /dev/null @@ -1,5 +0,0 @@ -// For googleapis (#1775) -module.exports = { - readFile() { }, - readFileSync() { } -}; \ No newline at end of file diff --git a/src/shortcuts.js b/src/shortcuts.js index a9cfeef7..4f706cfd 100644 --- a/src/shortcuts.js +++ b/src/shortcuts.js @@ -41,117 +41,117 @@ import { applyNoteTemplateFromNoteFilter, applyTaskTemplate, applyTaskTemplateFr export function initializeShortcuts() { if (process.env.REACT_APP_MODE === 'electron') { - const electron = window.electron; + const { ipcRenderer } = window.electron; - electron.on('menu-save', async () => { + ipcRenderer.on('menu-save', async () => { await executeSave(); }); - electron.on('menu-backup', async () => { + ipcRenderer.on('menu-backup', async () => { await executeBackup(); }); - electron.on('menu-import-data', async () => { + ipcRenderer.on('menu-import-data', async () => { await executeImportData(); }); - electron.on('menu-export-data', async () => { + ipcRenderer.on('menu-export-data', async () => { await executeExportData(); }); - electron.on('menu-settings', async () => { + ipcRenderer.on('menu-settings', async () => { await executeSettings(); }); - electron.on('menu-undo', async () => { + ipcRenderer.on('menu-undo', async () => { await executeUndo(); }); - electron.on('menu-redo', async () => { + ipcRenderer.on('menu-redo', async () => { await executeRedo(); }); - electron.on('menu-add-note', async () => { + ipcRenderer.on('menu-add-note', async () => { await executeAddNote(); }); - electron.on('menu-remove-notes', async () => { + ipcRenderer.on('menu-remove-notes', async () => { await executeRemoveNotes(); }); - electron.on('menu-print-notes', async () => { + ipcRenderer.on('menu-print-notes', async () => { await executePrintNotes(); }); - electron.on('menu-note-filter-manager', async () => { + ipcRenderer.on('menu-note-filter-manager', async () => { await executeNoteFilterManager(); }); - electron.on('menu-note-field-manager', async () => { + ipcRenderer.on('menu-note-field-manager', async () => { await executeNoteFieldManager(); }); - electron.on('menu-add-task', async () => { + ipcRenderer.on('menu-add-task', async () => { await executeAddTask(); }); - electron.on('menu-add-sub-task', async () => { + ipcRenderer.on('menu-add-sub-task', async () => { await executeAddSubTask(); }); - electron.on('menu-batch-add-tasks', async () => { + ipcRenderer.on('menu-batch-add-tasks', async () => { await executeBatchAddTasks(); }); - electron.on('menu-edit-tasks', async () => { + ipcRenderer.on('menu-edit-tasks', async () => { await executeEditTasks(); }); - electron.on('menu-remove-tasks', async () => { + ipcRenderer.on('menu-remove-tasks', async () => { await executeRemoveTasks(); }); - electron.on('menu-print-tasks', async () => { + ipcRenderer.on('menu-print-tasks', async () => { await executePrintTasks(); }); - electron.on('menu-task-filter-manager', async () => { + ipcRenderer.on('menu-task-filter-manager', async () => { await executeTaskFilterManager(); }); - electron.on('menu-task-template-manager', async () => { + ipcRenderer.on('menu-task-template-manager', async () => { await executeTaskTemplateManager(); }); - electron.on('menu-task-field-manager', async () => { + ipcRenderer.on('menu-task-field-manager', async () => { await executeTaskFieldManager(); }); - electron.on('menu-synchronize', async () => { + ipcRenderer.on('menu-synchronize', async () => { await executeSynchronize(); }); - electron.on('menu-publish', async () => { + ipcRenderer.on('menu-publish', async () => { await executePublish(); }); - electron.on('menu-category-manager', async () => { + ipcRenderer.on('menu-category-manager', async () => { await executeCategoryManager(); }); - electron.on('menu-reminder-manager', async () => { + ipcRenderer.on('menu-reminder-manager', async () => { await executeReminderManager(); }); - electron.on('menu-show-tasks', async () => { + ipcRenderer.on('menu-show-tasks', async () => { await executeShowTasks(); }); - electron.on('menu-show-calendar', async () => { + ipcRenderer.on('menu-show-calendar', async () => { await executeShowCalendar(); }); - electron.on('menu-show-notes', async () => { + ipcRenderer.on('menu-show-notes', async () => { await executeShowNotes(); }); } else { diff --git a/src/utils/ElectronIpc.js b/src/utils/ElectronIpc.js index 273dbec1..e1a1c546 100644 --- a/src/utils/ElectronIpc.js +++ b/src/utils/ElectronIpc.js @@ -1,194 +1,194 @@ // app-get-path export function getPath(path) { - const electron = window.electron; - return electron.invoke('app-get-path', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('app-get-path', path); } // app-get-path-sync export function getPathSync(path) { - const electron = window.electron; - return electron.sendSync('app-get-path-sync', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.sendSync('app-get-path-sync', path); } // app-get-version export function getAppVersion() { - const electron = window.electron; - return electron.invoke('app-get-version'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('app-get-version'); } // app-set-badge-count export function setBadgeCount(count) { - const electron = window.electron; - return electron.invoke('app-set-badge-count', count); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('app-set-badge-count', count); } // auto-updater-check-updates export function checkForUpdates() { - const electron = window.electron; - return electron.invoke('auto-updater-check-updates'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('auto-updater-check-updates'); } // auto-updater-download-update export function downloadUpdate() { - const electron = window.electron; - return electron.invoke('auto-updater-download-update'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('auto-updater-download-update'); } // auto-updater-quit-and-install export function quitAndInstall() { - const electron = window.electron; - return electron.invoke('auto-updater-quit-and-install'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('auto-updater-quit-and-install'); } // axios export function axios(config) { - const electron = window.electron; - return electron.invoke('axios', config); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('axios', config); } // axios-create export function axiosCreate(config, createConfig, httpsAgent) { - const electron = window.electron; - return electron.invoke('axios-create', config, createConfig, httpsAgent); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('axios-create', config, createConfig, httpsAgent); } // crypto-verify-sync export function verifyCryptoSync(algorithm, message, object, signature, signatureFormat) { - const electron = window.electron; - return electron.sendSync('crypto-verify-sync', algorithm, message, object, signature, signatureFormat); + const { ipcRenderer } = window.electron; + return ipcRenderer.sendSync('crypto-verify-sync', algorithm, message, object, signature, signatureFormat); } // current-window-close export function closeCurrentWindow() { - const electron = window.electron; - return electron.invoke('current-window-close'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('current-window-close'); } // current-window-get-position export function getCurrentWindowPosition() { - const electron = window.electron; - return electron.invoke('current-window-get-position'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('current-window-get-position'); } // current-window-get-size export function getCurrentWindowSize() { - const electron = window.electron; - return electron.invoke('current-window-get-size'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('current-window-get-size'); } // dialog-show-open-dialog export function showOpenDialog(options) { - const electron = window.electron; - return electron.invoke('dialog-show-open-dialog', options); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('dialog-show-open-dialog', options); } // dialog-show-save-dialog export function showSaveDialog(options) { - const electron = window.electron; - return electron.invoke('dialog-show-save-dialog', options); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('dialog-show-save-dialog', options); } // fse-access export function exists(path) { - const electron = window.electron; - return electron.invoke('fse-access', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-access', path); } // fse-copy-file export function copyFile(src, dest) { - const electron = window.electron; - return electron.invoke('fse-copy-file', src, dest); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-copy-file', src, dest); } // fse-ensure-dir export function ensureDir(path) { - const electron = window.electron; - return electron.invoke('fse-ensure-dir', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-ensure-dir', path); } // fse-lstat export function lstat(path) { - const electron = window.electron; - return electron.invoke('fse-lstat', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-lstat', path); } // fse-read-file export function readFile(path, encoding) { - const electron = window.electron; - return electron.invoke('fse-read-file', path, encoding); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-read-file', path, encoding); } // fse-readdir export function readdir(path) { - const electron = window.electron; - return electron.invoke('fse-readdir', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-readdir', path); } // fse-remove export function remove(path) { - const electron = window.electron; - return electron.invoke('fse-remove', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-remove', path); } // fse-write-file export function writeFile(file, data) { - const electron = window.electron; - return electron.invoke('fse-write-file', file, data); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('fse-write-file', file, data); } // initiate-quit export function initiateQuit() { - const electron = window.electron; - return electron.invoke('initiate-quit'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('initiate-quit'); } // log export function log(type, ...params) { - const electron = window.electron; - return electron.invoke('log', type, ...params); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('log', type, ...params); } // log-get-file export function getLogFile() { - const electron = window.electron; - return electron.invoke('log-get-file'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('log-get-file'); } // log-set-level export function setLogLevel(level) { - const electron = window.electron; - return electron.invoke('log-set-level', level); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('log-set-level', level); } // os-platform export function getPlatform() { - const electron = window.electron; - return electron.invoke('os-platform'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('os-platform'); } // path-dirname export function dirname(path) { - const electron = window.electron; - return electron.invoke('path-dirname', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('path-dirname', path); } // path-join-sync export function joinSync(...paths) { - const electron = window.electron; - return electron.sendSync('path-join-sync', ...paths); + const { ipcRenderer } = window.electron; + return ipcRenderer.sendSync('path-join-sync', ...paths); } // process-get-env export function getProcessEnv() { - const electron = window.electron; - return electron.invoke('process-get-env'); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('process-get-env'); } // shell-open-external export function openExternal(url) { if (process.env.REACT_APP_MODE === 'electron') { - const electron = window.electron; - return electron.invoke('shell-open-external', url); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('shell-open-external', url); } else { window.open(url, '_blank').focus(); } @@ -196,6 +196,6 @@ export function openExternal(url) { // shell-open-path export function openPath(path) { - const electron = window.electron; - return electron.invoke('shell-open-path', path); + const { ipcRenderer } = window.electron; + return ipcRenderer.invoke('shell-open-path', path); } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 80835ddb..3bd5604c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7647,10 +7647,10 @@ functions-have-names@^1.2.2: resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.2.tgz#98d93991c39da9361f8e50b337c4f6e41f120e21" integrity sha512-bLgc3asbWdwPbx2mNk2S49kmJCuQeu0nfmaOgbs8WIyzzkw3r4htszdIi9Q9EMezDPTYuJx2wvjZ/EwgAthpnA== -gaxios@^2.0.1, gaxios@^2.1.0: - version "2.3.4" - resolved "https://registry.yarnpkg.com/gaxios/-/gaxios-2.3.4.tgz#eea99353f341c270c5f3c29fc46b8ead56f0a173" - integrity sha512-US8UMj8C5pRnao3Zykc4AAVr+cffoNKRTg9Rsf2GiuZCW69vgJj38VK2PzlPuQU73FZ/nTk9/Av6/JGcE1N9vA== +gaxios@^4.0.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/gaxios/-/gaxios-4.2.0.tgz#33bdc4fc241fc33b8915a4b8c07cfb368b932e46" + integrity sha512-Ms7fNifGv0XVU+6eIyL9LB7RVESeML9+cMvkwGS70xyD6w2Z80wl6RiqiJ9k1KFlJCUTQqFFc8tXmPQfSKUe8g== dependencies: abort-controller "^3.0.0" extend "^3.0.2" @@ -7658,13 +7658,13 @@ gaxios@^2.0.1, gaxios@^2.1.0: is-stream "^2.0.0" node-fetch "^2.3.0" -gcp-metadata@^3.4.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/gcp-metadata/-/gcp-metadata-3.5.0.tgz#6d28343f65a6bbf8449886a0c0e4a71c77577055" - integrity sha512-ZQf+DLZ5aKcRpLzYUyBS3yo3N0JSa82lNDO8rj3nMSlovLcz2riKFBsYgDzeXcv75oo5eqB2lx+B14UvPoCRnA== +gcp-metadata@^4.2.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/gcp-metadata/-/gcp-metadata-4.2.1.tgz#31849fbcf9025ef34c2297c32a89a1e7e9f2cd62" + integrity sha512-tSk+REe5iq/N+K+SK1XjZJUrFPuDqGZVzCy2vocIHIGmPlTGsa8owXMJwGkrXr73NO0AzhPW4MF2DEHz7P2AVw== dependencies: - gaxios "^2.1.0" - json-bigint "^0.3.0" + gaxios "^4.0.0" + json-bigint "^1.0.0" gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2: version "1.0.0-beta.2" @@ -7855,47 +7855,47 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" -google-auth-library@^5.6.1: - version "5.10.1" - resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-5.10.1.tgz#504ec75487ad140e68dd577c21affa363c87ddff" - integrity sha512-rOlaok5vlpV9rSiUu5EpR0vVpc+PhN62oF4RyX/6++DG1VsaulAFEMlDYBLjJDDPI6OcNOCGAKy9UVB/3NIDXg== +google-auth-library@^7.0.2: + version "7.0.4" + resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-7.0.4.tgz#610cb010de71435dca47dfbe8dc7fbff23055d2c" + integrity sha512-o8irYyeijEiecTXeoEe8UKNEzV1X+uhR4b2oNdapDMZixypp0J+eHimGOyx5Joa3UAeokGngdtDLXtq9vDqG2Q== dependencies: arrify "^2.0.0" base64-js "^1.3.0" ecdsa-sig-formatter "^1.0.11" fast-text-encoding "^1.0.0" - gaxios "^2.1.0" - gcp-metadata "^3.4.0" - gtoken "^4.1.0" + gaxios "^4.0.0" + gcp-metadata "^4.2.0" + gtoken "^5.0.4" jws "^4.0.0" - lru-cache "^5.0.0" + lru-cache "^6.0.0" -google-p12-pem@^2.0.0: - version "2.0.4" - resolved "https://registry.yarnpkg.com/google-p12-pem/-/google-p12-pem-2.0.4.tgz#036462394e266472632a78b685f0cc3df4ef337b" - integrity sha512-S4blHBQWZRnEW44OcR7TL9WR+QCqByRvhNDZ/uuQfpxywfupikf/miba8js1jZi6ZOGv5slgSuoshCWh6EMDzg== +google-p12-pem@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/google-p12-pem/-/google-p12-pem-3.0.3.tgz#673ac3a75d3903a87f05878f3c75e06fc151669e" + integrity sha512-wS0ek4ZtFx/ACKYF3JhyGe5kzH7pgiQ7J5otlumqR9psmWMYc+U9cErKlCYVYHoUaidXHdZ2xbo34kB+S+24hA== dependencies: - node-forge "^0.9.0" + node-forge "^0.10.0" -googleapis-common@^3.2.0: - version "3.2.2" - resolved "https://registry.yarnpkg.com/googleapis-common/-/googleapis-common-3.2.2.tgz#f8631f94b3a5c58d8ce955c3290bb65fdb6d7ba4" - integrity sha512-sTEXlauVce4eMX0S6hVoiWgxVzQZ7dc16KcGF7eh+A+uIyDgXqnuwOMZw+svX4gOJv6w4ACecm23Qh9UDaldsw== +googleapis-common@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/googleapis-common/-/googleapis-common-5.0.2.tgz#e2c4e777050b921e90657de1f2edec4e7c64a3e0" + integrity sha512-TL7qronKNZwE/XBvqshwzCPmZGq2gz/beXzANF7EVoO7FsQjOd7dk40DYrXkoCpvbnJHCQKWESq6NansiIPFqA== dependencies: extend "^3.0.2" - gaxios "^2.0.1" - google-auth-library "^5.6.1" + gaxios "^4.0.0" + google-auth-library "^7.0.2" qs "^6.7.0" url-template "^2.0.8" - uuid "^7.0.0" + uuid "^8.0.0" -googleapis@^48.0.0: - version "48.0.0" - resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-48.0.0.tgz#2c3f7628d414f8cc27c5dd7ca2d9bba6b03c4179" - integrity sha512-ysp0/GN1BdOC8no1M6Pn/jS445xLL/FiTRa+aYJXD/HhtWFb+NOlNSfHIVnLjlQZsCn6L4qj1EpOaM/979nnEw== +googleapis@^71.0.0: + version "71.0.0" + resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-71.0.0.tgz#93f81d3b0a67529502803d655ab7968b386e981d" + integrity sha512-pi3aWckvsEJbZmJ/+MeO8eIWOK2wmSKRRLvCQbgqTLrFce/jEHLusPly+H3FkpmbO3oTtYRUMJJ07Y4F3DeOgA== dependencies: - google-auth-library "^5.6.1" - googleapis-common "^3.2.0" + google-auth-library "^7.0.2" + googleapis-common "^5.0.2" got@^9.6.0: version "9.6.0" @@ -7936,15 +7936,14 @@ growly@^1.3.0: resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE= -gtoken@^4.1.0: - version "4.1.4" - resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-4.1.4.tgz#925ff1e7df3aaada06611d30ea2d2abf60fcd6a7" - integrity sha512-VxirzD0SWoFUo5p8RDP8Jt2AGyOmyYcT/pOUgDKJCK+iSw0TMqwrVfY37RXTNmoKwrzmDHSk0GMT9FsgVmnVSA== +gtoken@^5.0.4: + version "5.2.1" + resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-5.2.1.tgz#4dae1fea17270f457954b4a45234bba5fc796d16" + integrity sha512-OY0BfPKe3QnMsY9MzTHTSKn+Vl2l1CcLe6BwDEQj00mbbkl5nyQ/7EUREstg4fQNZ8iYE7br4JJ7TdKeDOPWmw== dependencies: - gaxios "^2.1.0" - google-p12-pem "^2.0.0" + gaxios "^4.0.0" + google-p12-pem "^3.0.3" jws "^4.0.0" - mime "^2.2.0" gzip-size@5.1.1: version "5.1.1" @@ -9537,10 +9536,10 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0= -json-bigint@^0.3.0: - version "0.3.1" - resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-0.3.1.tgz#0c1729d679f580d550899d6a2226c228564afe60" - integrity sha512-DGWnSzmusIreWlEupsUelHrhwmPPE+FiQvg+drKfk2p+bdEYa5mp4PJ8JsCWqae0M2jQNb0HPvnwvf1qOTThzQ== +json-bigint@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1" + integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ== dependencies: bignumber.js "^9.0.0" @@ -10020,7 +10019,7 @@ lowercase-keys@^2.0.0: resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== -lru-cache@^5.0.0, lru-cache@^5.1.1: +lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w== @@ -10221,7 +10220,7 @@ mime@1.6.0, mime@^1.4.1: resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== -mime@^2.2.0, mime@^2.4.4, mime@^2.5.0: +mime@^2.4.4, mime@^2.5.0: version "2.5.2" resolved "https://registry.yarnpkg.com/mime/-/mime-2.5.2.tgz#6e3dc6cc2b9510643830e5f19d5cb753da5eeabe" integrity sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg== @@ -10526,11 +10525,6 @@ node-forge@^0.10.0: resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3" integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA== -node-forge@^0.9.0: - version "0.9.2" - resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.2.tgz#b35a44c28889b2ea55cabf8c79e3563f9676190a" - integrity sha512-naKSScof4Wn+aoHU6HBsifh92Zeicm1GDQKd1vp3Y/kOi8ub0DozCa9KpvYNCXslFHYRmLNiqRopGdTGwNLpNw== - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -10710,9 +10704,9 @@ object-copy@^0.1.0: kind-of "^3.0.3" object-inspect@^1.7.0, object-inspect@^1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.9.0.tgz#c90521d74e1127b67266ded3394ad6116986533a" - integrity sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw== + version "1.10.2" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.10.2.tgz#b6385a3e2b7cae0b5eafcf90cddf85d128767f30" + integrity sha512-gz58rdPpadwztRrPjZE9DZLOABUpTGdcANUgOwBFO1C+HZZhePoP83M65WGDmbpwFYJSWqavbl4SgDn4k8RYTA== object-is@^1.0.1, object-is@^1.0.2, object-is@^1.1.2: version "1.1.5" @@ -15129,12 +15123,7 @@ uuid@^3.0.0, uuid@^3.2.1, uuid@^3.3.2, uuid@^3.4.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^7.0.0: - version "7.0.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.3.tgz#c5c9f2c8cf25dc0a372c4df1441c41f5bd0c680b" - integrity sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg== - -uuid@^8.3.0, uuid@^8.3.2: +uuid@^8.0.0, uuid@^8.3.0, uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== @@ -15679,9 +15668,9 @@ ws@^6.2.1: async-limiter "~1.0.0" ws@^7.4.4: - version "7.4.4" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.4.tgz#383bc9742cb202292c9077ceab6f6047b17f2d59" - integrity sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw== + version "7.4.5" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.5.tgz#a484dd851e9beb6fdb420027e3885e8ce48986c1" + integrity sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g== xdg-basedir@^4.0.0: version "4.0.0"