- + {isRecording && ( )} diff --git a/ts/components/leftpane/ActionsPanel.tsx b/ts/components/leftpane/ActionsPanel.tsx index e30b3ede6..189f86103 100644 --- a/ts/components/leftpane/ActionsPanel.tsx +++ b/ts/components/leftpane/ActionsPanel.tsx @@ -34,7 +34,7 @@ import { conversationChanged, conversationRemoved } from '../../state/ducks/conv import { editProfileModal, onionPathModal } from '../../state/ducks/modalDialog'; import { uploadOurAvatar } from '../../interactions/conversationInteractions'; import { ModalContainer } from '../dialog/ModalContainer'; -import { debounce } from 'lodash'; +import { debounce, isEmpty, isString } from 'lodash'; // tslint:disable-next-line: no-import-side-effect no-submodule-imports @@ -51,6 +51,8 @@ import { IncomingCallDialog } from '../calling/IncomingCallDialog'; import { SessionIconButton } from '../icon'; import { SessionToastContainer } from '../SessionToastContainer'; import { LeftPaneSectionContainer } from './LeftPaneSectionContainer'; +import { getLatestDesktopReleaseFileToFsV2 } from '../../session/apis/file_server_api/FileServerApiV2'; +import { ipcRenderer } from 'electron'; const Section = (props: { type: SectionType }) => { const ourNumber = useSelector(getOurNumber); @@ -162,7 +164,12 @@ const Section = (props: { type: SectionType }) => { } }; -const cleanUpMediasInterval = DURATION.MINUTES * 30; +const cleanUpMediasInterval = DURATION.MINUTES * 60; + +// every 10 minutes we fetch from the fileserver to check for a new release +// * if there is none, no request to github are made. +// * if there is a version on the fileserver more recent than our current, we fetch github to get the UpdateInfos and trigger an update as usual (asking user via dialog) +const fetchReleaseFromFileServerInterval = 1000 * 60; // try to fetch the latest release from the fileserver every minute const setupTheme = () => { const theme = window.Events.getThemeSetting(); @@ -265,6 +272,22 @@ const CallContainer = () => { ); }; +async function fetchReleaseFromFSAndUpdateMain() { + try { + window.log.warn('[updater] about to fetchReleaseFromFSAndUpdateMain'); + + const latest = await getLatestDesktopReleaseFileToFsV2(); + window.log.warn('[updater] fetched latest release from fsv2: ', latest); + + if (isString(latest) && !isEmpty(latest)) { + ipcRenderer.send('set-release-from-file-server', latest); + window.readyForUpdates(); + } + } catch (e) { + window.log.warn(e); + } +} + /** * ActionsPanel is the far left banner (not the left pane). * The panel with buttons to switch between the message/contact/settings/theme views @@ -289,6 +312,10 @@ export const ActionsPanel = () => { useInterval(cleanUpOldDecryptedMedias, startCleanUpMedia ? cleanUpMediasInterval : null); + useInterval(() => { + void fetchReleaseFromFSAndUpdateMain(); + }, fetchReleaseFromFileServerInterval); + if (!ourPrimaryConversation) { window?.log?.warn('ActionsPanel: ourPrimaryConversation is not set'); return null; diff --git a/ts/session/constants.ts b/ts/session/constants.ts index 7cb80abae..36c14e356 100644 --- a/ts/session/constants.ts +++ b/ts/session/constants.ts @@ -50,28 +50,8 @@ export const VALIDATION = { }; export const UI = { - // Pixels (scroll) from the top of the top of message container - // at which more messages should be loaded - MESSAGE_CONTAINER_BUFFER_OFFSET_PX: 1, - COLORS: { // COMMON - WHITE: '#FFFFFF', - WHITE_PALE: '#AFAFAF', GREEN: '#00F782', - - // CAUTION - WARNING: '#FFC02E', - - // SEMANTIC COLORS - DANGER: '#FF453A', - DANGER_ALT: '#FF4538', - }, - - SPACING: { - marginXs: '5px', - marginSm: '10px', - marginMd: '15px', - marginLg: '20px', }, }; diff --git a/ts/session/sending/MessageSender.ts b/ts/session/sending/MessageSender.ts index fa0819186..d65ceb7f4 100644 --- a/ts/session/sending/MessageSender.ts +++ b/ts/session/sending/MessageSender.ts @@ -130,7 +130,14 @@ export async function TEST_sendMessageToSnode( const data64 = window.dcodeIO.ByteBuffer.wrap(data).toString('base64'); const swarm = await getSwarmFor(pubKey); - window?.log?.debug('Sending envelope with timestamp: ', timestamp, ' to ', ed25519Str(pubKey)); + window?.log?.debug( + 'Sending envelope with timestamp: ', + timestamp, + ' to ', + ed25519Str(pubKey), + ' size base64:', + data64.length + ); // send parameters const params = { pubKey, diff --git a/ts/updater/index.ts b/ts/updater/index.ts index 4327b7155..1bc27bc14 100644 --- a/ts/updater/index.ts +++ b/ts/updater/index.ts @@ -1,23 +1,24 @@ -import { get as getFromConfig } from 'config'; import { BrowserWindow } from 'electron'; import { start as startUpdater, stop as stopUpdater } from './updater'; import { LoggerType, MessagesType } from './common'; import { UserConfig } from '../../app/user_config'; let initialized = false; -let config: UserConfig; +let localUserConfig: UserConfig; export async function start( getMainWindow: () => BrowserWindow, userConfig: UserConfig, - messages?: MessagesType, - logger?: LoggerType + messages: MessagesType, + logger: LoggerType ) { if (initialized) { throw new Error('updater/start: Updates have already been initialized!'); } - initialized = true; - config = userConfig; + + if (!userConfig) { + throw new Error('updater/start: userConfig is needed!'); + } if (!messages) { throw new Error('updater/start: Must provide messages!'); @@ -25,15 +26,10 @@ export async function start( if (!logger) { throw new Error('updater/start: Must provide logger!'); } + initialized = true; + localUserConfig = userConfig; // reused below if (autoUpdateDisabled()) { - /* - If you really want to enable auto-updating in dev mode - You need to create a dev-app-update.yml file. - A sample can be found in dev-app-update.yml.sample. - After that you can change `updatesEnabled` to `true` in the default config. - */ - logger.info('updater/start: Updates disabled - not starting new version checks'); return; @@ -51,12 +47,11 @@ export function stop() { function autoUpdateDisabled() { // We need to ensure that if auto update is not present in the user config then we assume it is on by default - const userSetting = config.get('autoUpdate'); + const userSetting = localUserConfig.get('autoUpdate'); const autoUpdate = typeof userSetting !== 'boolean' || userSetting; return ( process.mas || // From Electron: Mac App Store build - !getFromConfig('updatesEnabled') || // Hard coded config // tslint:disable-next-line: no-backbone-get-set-outside-model !autoUpdate // User setting ); diff --git a/ts/updater/updater.ts b/ts/updater/updater.ts index aa1918b51..2867fcae0 100644 --- a/ts/updater/updater.ts +++ b/ts/updater/updater.ts @@ -19,10 +19,6 @@ let downloadIgnored = false; let interval: NodeJS.Timeout | undefined; let stopped = false; -const SECOND = 1000; -const MINUTE = SECOND * 60; -const INTERVAL = MINUTE * 30; - export async function start( getMainWindow: () => BrowserWindow, messages: MessagesType, @@ -45,7 +41,7 @@ export async function start( } catch (error) { logger.error('auto-update: error:', getPrintableError(error)); } - }, INTERVAL); + }, 1000 * 60 * 10); // trigger and try to update every 10 minutes to let the file gets downloaded if we are updating stopped = false; await checkForUpdates(getMainWindow, messages, logger); @@ -64,38 +60,70 @@ async function checkForUpdates( messages: MessagesType, logger: LoggerType ) { + logger.info('[updater] checkForUpdates'); if (stopped || isUpdating || downloadIgnored) { return; } const canUpdate = await canAutoUpdate(); + logger.info('[updater] canUpdate', canUpdate); if (!canUpdate) { + logger.info('checkForUpdates canAutoUpdate false'); return; } - logger.info('auto-update: checking for update...'); + logger.info('[updater] checkForUpdates...'); isUpdating = true; try { - // Get the update using electron-updater + const latestVersionFromFsFromRenderer = getMainWindow() + ? ((getMainWindow() as any).getLatestDesktopRelease() as string | undefined) + : undefined; + + logger.info('[updater] latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer); + if (!latestVersionFromFsFromRenderer || !latestVersionFromFsFromRenderer?.length) { + logger.info( + '[updater] testVersionFromFsFromRenderer was not updated yet by renderer. Skipping update check' + ); + return; + } + + const currentVersion = autoUpdater.currentVersion.toString(); + const isMoreRecent = isVersionGreaterThan(latestVersionFromFsFromRenderer, currentVersion); + logger.info('[updater] checkForUpdates isMoreRecent', isMoreRecent); + if (!isMoreRecent) { + logger.info( + `Fileserver has no update so we are not looking for an update from github current:${currentVersion} fromFileServer:${latestVersionFromFsFromRenderer}` + ); + return; + } + + // Get the update using electron-updater, this fetches from github const result = await autoUpdater.checkForUpdates(); + + logger.info('[updater] checkForUpdates got github response back '); + if (!result.updateInfo) { - logger.info('auto-update: no update info received'); + logger.info('[updater] no update info received'); return; } try { const hasUpdate = isUpdateAvailable(result.updateInfo); + logger.info('[updater] hasUpdate:', hasUpdate); + if (!hasUpdate) { - logger.info('auto-update: no update available'); + logger.info('[updater] no update available'); return; } - logger.info('auto-update: showing download dialog...'); + logger.info('[updater] showing download dialog...'); const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages); + logger.info('[updater] shouldDownload:', shouldDownload); + if (!shouldDownload) { downloadIgnored = true; @@ -109,13 +137,13 @@ async function checkForUpdates( } // Update downloaded successfully, we should ask the user to update - logger.info('auto-update: showing update dialog...'); + logger.info('[updater] showing update dialog...'); const shouldUpdate = await showUpdateDialog(getMainWindow(), messages); if (!shouldUpdate) { return; } - logger.info('auto-update: calling quitAndInstall...'); + logger.info('[updater] calling quitAndInstall...'); markShouldQuit(); autoUpdater.quitAndInstall(); } finally { diff --git a/ts/window.d.ts b/ts/window.d.ts index a075e8a5b..bfb8aa8c7 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -59,6 +59,7 @@ declare global { userConfig: any; versionInfo: any; getConversations: () => ConversationCollection; + readyForUpdates: () => void; MediaRecorder: any; contextMenuShown: boolean;