Skip to content

Commit

Permalink
fix: Adjust new webview behavior and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann committed Apr 4, 2018
1 parent 57879a0 commit 87164b3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 94 deletions.
4 changes: 4 additions & 0 deletions electron/renderer/src/components/Sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
border-radius: 50%;
}

.Sidebar-icon-cursor {
cursor: pointer;
}

.Sidebar-account-add {
width: 28px;
height: 28px;
Expand Down
21 changes: 10 additions & 11 deletions electron/renderer/src/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ import {

import './Sidebar.css';

function className(account) {
return [
'Sidebar-icon',
account.badgeCount > 0 ? 'Sidebar-icon-badge' : '',
].join(' ');
}

const centerOfEventTarget = event => {
const cRect = event.target.getBoundingClientRect();
return [cRect.left + cRect.width / 2, cRect.top + cRect.height / 2];
};

const getClassName = account => {
const showIconBadge = account.badgeCount > 0 ? ' Sidebar-icon-badge' : '';
const showIconCursor = account.visible ? '' : ' Sidebar-icon-cursor';
return `Sidebar-icon${showIconBadge}${showIconCursor}`;
};

const Sidebar = ({
accounts,
currentAccentID,
Expand All @@ -59,15 +58,15 @@ const Sidebar = ({
}) => (
<div
className="Sidebar"
style={hasCreatedAccount ? {} : { display: 'none' }}
style={hasCreatedAccount ? {} : {display: 'none'}}
onMouseDown={preventFocus()}
onClick={connected.setAccountContextHidden}
>
{accounts.map(account => (
<div className="Sidebar-cell" key={account.id}>
<div
style={{ color: colorFromId(currentAccentID) }}
className={className(account)}
style={{color: colorFromId(currentAccentID)}}
className={getClassName(account)}
onClick={() => connected.switchAccount(account.id)}
onContextMenu={preventFocus(event => {
const isAtLeastAdmin = [
Expand Down Expand Up @@ -110,7 +109,7 @@ const Sidebar = ({
);

export default connect(
({ accounts, contextMenuState }) => ({
({accounts, contextMenuState}) => ({
accounts,
currentAccentID: (accounts.find(account => account.visible) || {}).accentID,
hasCreatedAccount: accounts.some(account => account.userID !== undefined),
Expand Down
1 change: 1 addition & 0 deletions electron/renderer/src/components/Webviews.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}

.Webviews-close {
cursor: pointer;
position: absolute;
top: 24px;
right: 24px;
Expand Down
3 changes: 0 additions & 3 deletions electron/renderer/src/components/Webviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class Webviews extends Component {
// pass account id to webview so we can access it in the preload script
url.searchParams.set('id', account.id);

// when landing on auth page for login mode
url.hash = 'login';

return url.href;
}

Expand Down
137 changes: 57 additions & 80 deletions electron/renderer/static/webview-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ const fs = require('fs-extra');
const path = require('path');
const winston = require('winston');

const { desktopCapturer, ipcRenderer, remote, webFrame } = require('electron');
const { app } = remote;
const {desktopCapturer, ipcRenderer, remote, webFrame} = require('electron');
const {app} = remote;

webFrame.setVisualZoomLevelLimits(1, 1);
webFrame.setLayoutZoomLevelLimits(1, 1);
webFrame.registerURLSchemeAsBypassingCSP('file');

const subscribeToWebappEvents = () => {
amplify.subscribe(z.event.WebApp.LIFECYCLE.RESTART, update_source => {
if (update_source === z.lifecycle.UPDATE_SOURCE.DESKTOP) {
ipcRenderer.send('wrapper-update');
} else {
ipcRenderer.send('wrapper-relaunch');
}
const isUpdateSourceDesktop = update_source === z.lifecycle.UPDATE_SOURCE.DESKTOP;
ipcRenderer.send(isUpdateSourceDesktop ? 'wrapper-update' : 'wrapper-relaunch');
});

amplify.subscribe(z.event.WebApp.LIFECYCLE.LOADED, () => {
Expand Down Expand Up @@ -68,60 +65,57 @@ const subscribeToWebappEvents = () => {
};

const subscribeToMainProcessEvents = () => {
ipcRenderer.on('conversation-add-people', () =>
amplify.publish(z.event.WebApp.SHORTCUT.ADD_PEOPLE)
);
ipcRenderer.on('conversation-archive', () =>
amplify.publish(z.event.WebApp.SHORTCUT.ARCHIVE)
);
ipcRenderer.on('conversation-call', () =>
amplify.publish(z.event.WebApp.CALL.STATE.TOGGLE, false)
);
ipcRenderer.on('conversation-delete', () =>
amplify.publish(z.event.WebApp.SHORTCUT.DELETE)
);
ipcRenderer.on('conversation-next', () =>
amplify.publish(z.event.WebApp.SHORTCUT.NEXT)
);
ipcRenderer.on('conversation-people', () =>
amplify.publish(z.event.WebApp.SHORTCUT.PEOPLE)
);
ipcRenderer.on('conversation-ping', () =>
amplify.publish(z.event.WebApp.SHORTCUT.PING)
);
ipcRenderer.on('conversation-prev', () =>
amplify.publish(z.event.WebApp.SHORTCUT.PREV)
);
ipcRenderer.on('conversation-show', conversation_id =>
amplify.publish(z.event.WebApp.CONVERSATION.SHOW, conversation_id)
);
ipcRenderer.on('conversation-silence', () =>
amplify.publish(z.event.WebApp.SHORTCUT.SILENCE)
);
ipcRenderer.on('conversation-start', () =>
amplify.publish(z.event.WebApp.SHORTCUT.START)
);
ipcRenderer.on('conversation-video-call', () =>
amplify.publish(z.event.WebApp.CALL.STATE.TOGGLE, true)
);
ipcRenderer.on('preferences-show', () =>
amplify.publish(z.event.WebApp.PREFERENCES.MANAGE_ACCOUNT)
);
ipcRenderer.on('sign-out', () =>
amplify.publish(z.event.WebApp.LIFECYCLE.ASK_TO_CLEAR_DATA)
);
ipcRenderer.on('wrapper-update-available', () =>
amplify.publish(
z.event.WebApp.LIFECYCLE.UPDATE,
z.announce.UPDATE_SOURCE.DESKTOP
)
);
ipcRenderer.on('conversation-add-people', () => {
amplify.publish(z.event.WebApp.SHORTCUT.ADD_PEOPLE);
});
ipcRenderer.on('conversation-archive', () => {
amplify.publish(z.event.WebApp.SHORTCUT.ARCHIVE);
});
ipcRenderer.on('conversation-call', () => {
amplify.publish(z.event.WebApp.CALL.STATE.TOGGLE, false);
});
ipcRenderer.on('conversation-delete', () => {
amplify.publish(z.event.WebApp.SHORTCUT.DELETE);
});
ipcRenderer.on('conversation-next', () => {
amplify.publish(z.event.WebApp.SHORTCUT.NEXT);
});
ipcRenderer.on('conversation-people', () => {
amplify.publish(z.event.WebApp.SHORTCUT.PEOPLE);
});
ipcRenderer.on('conversation-ping', () => {
amplify.publish(z.event.WebApp.SHORTCUT.PING);
});
ipcRenderer.on('conversation-prev', () => {
amplify.publish(z.event.WebApp.SHORTCUT.PREV);
});
ipcRenderer.on('conversation-show', conversationId => {
amplify.publish(z.event.WebApp.CONVERSATION.SHOW, conversationId)
});
ipcRenderer.on('conversation-silence', () => {
amplify.publish(z.event.WebApp.SHORTCUT.SILENCE);
});
ipcRenderer.on('conversation-start', () => {
amplify.publish(z.event.WebApp.SHORTCUT.START);
});
ipcRenderer.on('conversation-video-call', () => {
amplify.publish(z.event.WebApp.CALL.STATE.TOGGLE, true);
});
ipcRenderer.on('preferences-show', () => {
amplify.publish(z.event.WebApp.PREFERENCES.MANAGE_ACCOUNT);
});
ipcRenderer.on('sign-out', () => {
amplify.publish(z.event.WebApp.LIFECYCLE.ASK_TO_CLEAR_DATA);
});
ipcRenderer.on('wrapper-update-available', () => {
amplify.publish(z.event.WebApp.LIFECYCLE.UPDATE, z.lifecycle.UPDATE_SOURCE.DESKTOP);
});
};

const exposeAddressbook = () => {
const exposeAddressBook = () => {
let cachedAddressBook;

const getAdressBook = () => {
const getAddressBook = () => {
if (!cachedAddressBook) {
try {
cachedAddressBook = require('node-addressbook');
Expand All @@ -133,7 +127,7 @@ const exposeAddressbook = () => {
};

if (environment.platform.IS_MAC_OS) {
Object.defineProperty(window, 'wAddressBook', { get: getAdressBook });
Object.defineProperty(window, 'wAddressBook', { get: getAddressBook });
}
};

Expand All @@ -156,12 +150,7 @@ const enableFileLogging = () => {
const id = new URL(window.location).searchParams.get('id');

if (id) {
const logFilePath = path.join(
app.getPath('userData'),
'logs',
id,
config.LOG_FILE_NAME
);
const logFilePath = path.join(app.getPath('userData'), 'logs', id, config.LOG_FILE_NAME);
fs.createFileSync(logFilePath);

const logger = new winston.Logger();
Expand All @@ -177,16 +166,13 @@ const enableFileLogging = () => {
}
};

const reportWebappVersion = () => {
ipcRenderer.send('webapp-version', z.util.Environment.version(false));
};
const reportWebappVersion = () => ipcRenderer.send('webapp-version', z.util.Environment.version(false));

const checkAvailability = callback => {
const intervalId = setInterval(() => {
if (window.wire) {
clearInterval(intervalId);
callback();
return;
return callback();
}

if (navigator.onLine) {
Expand All @@ -197,29 +183,20 @@ const checkAvailability = callback => {
}, 500);
};

const forceEmailLogin = () => {
window.location.hash = '#login';
};

// https://github.com/electron/electron/issues/2984
const _setImmediate = setImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate;
global.desktopCapturer = desktopCapturer;
global.environment = environment;
global.openGraph = require('../../js/lib/openGraph');
global.notification_icon = path.join(
app.getAppPath(),
'img',
'notification.png'
);
global.notification_icon = path.join(app.getAppPath(), 'img', 'notification.png');
enableFileLogging();
forceEmailLogin();
});

window.addEventListener('DOMContentLoaded', () => {
checkAvailability(() => {
exposeAddressbook();
exposeAddressBook();

subscribeToMainProcessEvents();
subscribeToWebappEvents();
Expand Down

0 comments on commit 87164b3

Please sign in to comment.