diff --git a/src/common/utils/util.js b/src/common/utils/util.js index 9f82be65..4c81c50c 100644 --- a/src/common/utils/util.js +++ b/src/common/utils/util.js @@ -44,8 +44,19 @@ function browserWindowFromWebContents(content) { return window; } +const DEFAULT_MAX = 20; + +function shorten(string, max) { + const maxLength = (max && max >= 4) ? max : DEFAULT_MAX; + if (string.length >= maxLength) { + return `${string.slice(0, maxLength - 3)}...`; + } + return string; +} + export default { getDisplayBoundaries, runMode, browserWindowFromWebContents, + shorten, }; diff --git a/src/main/views/MattermostView.js b/src/main/views/MattermostView.js index 9454b946..662103eb 100644 --- a/src/main/views/MattermostView.js +++ b/src/main/views/MattermostView.js @@ -6,6 +6,7 @@ import log from 'electron-log'; import {EventEmitter} from 'events'; +import Util from 'common/utils/util'; import {RELOAD_INTERVAL, MAX_SERVER_RETRIES, SECOND} from 'common/utils/constants'; import urlUtils from 'common/utils/url'; import {LOAD_RETRY, LOAD_SUCCESS, LOAD_FAILED, UPDATE_TARGET_URL, IS_UNREAD, UNREAD_RESULT, TOGGLE_BACK_BUTTON, SET_SERVER_NAME} from 'common/communication'; @@ -87,7 +88,7 @@ export class MattermostView extends EventEmitter { load = (someURL) => { const loadURL = (typeof someURL === 'undefined') ? `${this.server.url.toString()}` : urlUtils.parseURL(someURL).toString(); - log.info(`[${this.server.name}] Loading ${loadURL}`); + log.info(`[${Util.shorten(this.server.name)}] Loading ${loadURL}`); const loading = this.view.webContents.loadURL(loadURL, {userAgent}); loading.then(this.loadSuccess(loadURL)).catch((err) => { this.loadRetry(loadURL, err); @@ -107,7 +108,7 @@ export class MattermostView extends EventEmitter { } else { WindowManager.sendToRenderer(LOAD_FAILED, this.server.name, err.toString(), loadURL.toString()); this.emit(LOAD_FAILED, this.server.name, err.toString(), loadURL.toString()); - log.info(`[${this.server.name}] Couldn't stablish a connection with ${loadURL}: ${err}.`); + log.info(`[${Util.shorten(this.server.name)}] Couldn't stablish a connection with ${loadURL}: ${err}.`); this.status = ERROR; } }); @@ -117,12 +118,12 @@ export class MattermostView extends EventEmitter { loadRetry = (loadURL, err) => { this.retryLoad = setTimeout(this.retry(loadURL), RELOAD_INTERVAL); WindowManager.sendToRenderer(LOAD_RETRY, this.server.name, Date.now() + RELOAD_INTERVAL, err.toString(), loadURL.toString()); - log.info(`[${this.server.name}] failed loading ${loadURL}: ${err}, retrying in ${RELOAD_INTERVAL / SECOND} seconds`); + log.info(`[${Util.shorten(this.server.name)}] failed loading ${loadURL}: ${err}, retrying in ${RELOAD_INTERVAL / SECOND} seconds`); } loadSuccess = (loadURL) => { return () => { - log.info(`[${this.server.name}] finished loading ${loadURL}`); + log.info(`[${Util.shorten(this.server.name)}] finished loading ${loadURL}`); WindowManager.sendToRenderer(LOAD_SUCCESS, this.server.name); this.maxRetries = MAX_SERVER_RETRIES; if (this.status === LOADING) { diff --git a/src/main/views/webContentEvents.js b/src/main/views/webContentEvents.js index fbdb103a..47941390 100644 --- a/src/main/views/webContentEvents.js +++ b/src/main/views/webContentEvents.js @@ -7,7 +7,6 @@ import log from 'electron-log'; import {DEVELOPMENT, PRODUCTION} from 'common/utils/constants'; import urlUtils from 'common/utils/url'; import Utils from 'common/utils/util'; -import {FOUND_IN_PAGE} from 'common/communication'; import * as WindowManager from '../windows/windowManager'; @@ -210,6 +209,7 @@ export const addWebContentsEventListeners = (mmview, getServersFunction) => { if (listeners[contents.id]) { removeWebContentsListeners(contents.id); } + const willNavigate = generateWillNavigate(getServersFunction); contents.on('will-navigate', willNavigate); @@ -228,7 +228,6 @@ export const addWebContentsEventListeners = (mmview, getServersFunction) => { contents.on('page-title-updated', mmview.handleTitleUpdate); contents.on('page-favicon-updated', mmview.handleFaviconUpdate); contents.on('update-target-url', mmview.handleUpdateTarget); - contents.on(FOUND_IN_PAGE, mmview.handleFoundInPage); contents.on('did-navigate', mmview.handleDidNavigate); const removeListeners = () => { @@ -239,7 +238,6 @@ export const addWebContentsEventListeners = (mmview, getServersFunction) => { contents.removeListener('page-title-updated', mmview.handleTitleUpdate); contents.removeListener('page-favicon-updated', mmview.handleFaviconUpdate); contents.removeListener('update-target-url', mmview.handleUpdateTarget); - contents.removeListener(FOUND_IN_PAGE, mmview.handleFoundInPage); contents.removeListener('did-navigate', mmview.handleDidNavigate); } catch (e) { log.error(`Error while trying to detach listeners, this might be ok if the process crashed: ${e}`); diff --git a/src/renderer/css/components/TabBar.css b/src/renderer/css/components/TabBar.css index 5d733ed2..660eb167 100644 --- a/src/renderer/css/components/TabBar.css +++ b/src/renderer/css/components/TabBar.css @@ -16,6 +16,8 @@ .TabBar .teamTabItem span { flex: 0 1 auto; overflow: hidden; + text-overflow: ellipsis; + max-width: 200px; white-space: nowrap; text-align: center; } diff --git a/src/renderer/css/settings.css b/src/renderer/css/settings.css index f5591a88..4c37c868 100644 --- a/src/renderer/css/settings.css +++ b/src/renderer/css/settings.css @@ -18,9 +18,14 @@ } .TeamListItem p { - overflow-wrap: break-word; + overflow-wrap: break-word; } +.TeamListItem h4 { + overflow: hidden; + text-overflow: ellipsis; +}; + .checkbox > label { width: 100%; }