Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split config #578

Merged
merged 12 commits into from
Jan 11, 2019
72 changes: 72 additions & 0 deletions src/application-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const appConfig = require('application-config')('DeltaChat')
const path = require('path')
const version = require('../package.json').version

function appName () {
return 'DeltaChat'
}

function appVersion () {
return `${version}-PREVIEW`
}

function appWindowTitle () {
return `${appName()} (${appVersion()})`
}

function appIcon () {
// TODO Add .ico file for windows
return path.join(__dirname, '..', 'images', 'deltachat.png')
}

function homePageUrl () {
return 'https://delta.chat'
}

function gitHubUrl () {
return 'https://github.com/deltachat/deltachat-desktop'
}

function gitHubIssuesUrl () {
return `${gitHubUrl()}/issues`
}

function gitHubLicenseUrl () {
return `${gitHubUrl()}/blob/master/LICENSE`
}

function windowDefaults () {
const headerHeight = 38
const messageHeight = 100
return {
bounds: {
width: 500,
height: headerHeight + messageHeight * 6
},
headerHeight,
minWidth: 450,
minHeight: 450,
main: 'file://' + path.join(__dirname, '..', 'static', 'main.html')
}
}

function getConfigPath () {
if (process.env.NODE_ENV === 'test') {
return path.join(process.platform === 'win32' ? 'C:\\Windows\\Temp' : '/tmp', 'DeltaChatTest')
} else {
return path.dirname(appConfig.filePath)
}
}

module.exports = {
appName,
appVersion,
appWindowTitle,
appIcon,
homePageUrl,
gitHubUrl,
gitHubIssuesUrl,
gitHubLicenseUrl,
windowDefaults,
getConfigPath
}
47 changes: 0 additions & 47 deletions src/config.js

This file was deleted.

10 changes: 4 additions & 6 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const parallel = require('run-parallel')
const mkdirp = require('mkdirp')

const localize = require('../localize')
/* *CONFIG* */
const config = require('../config')
const { getConfigPath } = require('../application-constants')
const rc = require('../rc')
const logins = require('./logins')
const ipc = require('./ipc')
Expand All @@ -25,16 +24,15 @@ process.on('exit', function () {
logHandler.closeWriteStream()
})

// Ensure CONFIG_PATH exists.
mkdirp.sync(config.CONFIG_PATH)
mkdirp.sync(getConfigPath())

const ipcMain = electron.ipcMain

app.ipcReady = false // main window has finished loading and IPC is ready
app.isQuitting = false

parallel({
logins: (cb) => logins(config.CONFIG_PATH, cb),
logins: (cb) => logins(getConfigPath(), cb),
appReady: (cb) => app.on('ready', () => cb(null)),
state: (cb) => State.load(cb)
}, onReady)
Expand All @@ -45,7 +43,7 @@ function onReady (err, results) {
const state = results.state
app.logins = results.logins

var cwd = process.env.TEST_DIR || config.CONFIG_PATH
var cwd = process.env.TEST_DIR || getConfigPath()
log.info('cwd', cwd, 'cwd')
ralphtheninja marked this conversation as resolved.
Show resolved Hide resolved
ipc.init(cwd, state)

Expand Down
13 changes: 8 additions & 5 deletions src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const fs = require('fs')
const path = require('path')
const log = require('../logger').getLogger('main/menu')
const windows = require('./windows')
/* *CONFIG* */
const config = require('../config')
const {
homePageUrl,
gitHubUrl,
gitHubIssuesUrl
} = require('../application-constants')
const { getFullLogFilePath } = require('./developerTools/logHandler')

const app = electron.app
Expand Down Expand Up @@ -155,13 +158,13 @@ function getMenuTemplate () {
{
translate: 'global_menu_help_learn_desktop',
click: () => {
electron.shell.openExternal(config.HOME_PAGE_URL)
electron.shell.openExternal(homePageUrl())
}
},
{
translate: 'global_menu_help_contribute_desktop',
click: () => {
electron.shell.openExternal(config.GITHUB_URL)
electron.shell.openExternal(gitHubUrl())
}
},
{
Expand All @@ -170,7 +173,7 @@ function getMenuTemplate () {
{
translate: 'global_menu_help_report_desktop',
click: () => {
electron.shell.openExternal(config.GITHUB_URL_ISSUES)
electron.shell.openExternal(gitHubIssuesUrl())
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions src/main/notifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const windows = require('./windows')
/* *CONFIG* */
const config = require('../config')
const { appName, appIcon } = require('../application-constants')

const {
app,
Expand All @@ -23,9 +22,9 @@ module.exports = function (dc, settings) {
dc.on('DC_EVENT_INCOMING_MSG', (chatId, msgId) => {
if (!notify && settings.notifications && windows.main.win.hidden) {
notify = new Notification({
title: config.APP_NAME,
title: appName(),
body: getMsgBody(msgId),
icon: config.APP_ICON
icon: appIcon()
})
notify.show()
notify.on('click', () => {
Expand Down
38 changes: 18 additions & 20 deletions src/main/windows/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,52 @@ const main = module.exports = {

const electron = require('electron')
const debounce = require('debounce')
const {
appIcon,
appWindowTitle,
windowDefaults
} = require('../../application-constants')

/* *CONFIG* */
const config = require('../../config')
const log = require('../../logger').getLogger('main/mainWindow')

function init (state, options) {
if (main.win) {
return main.win.show()
}

const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
ralphtheninja marked this conversation as resolved.
Show resolved Hide resolved
const defaults = windowDefaults()
const initialBounds = Object.assign(
defaults.bounds,
state.saved.bounds
)

const win = main.win = new electron.BrowserWindow({
backgroundColor: '#282828',
backgroundThrottling: false, // do not throttle animations/timers when page is background
darkTheme: true, // Forces dark theme (GTK+3)
height: initialBounds.height,
icon: getIconPath(), // Window icon (Windows, Linux)
minHeight: config.WINDOW_MIN_HEIGHT,
minWidth: config.WINDOW_MIN_WIDTH,
icon: appIcon(),
minHeight: defaults.minHeight,
minWidth: defaults.minWidth,
show: false,
title: config.APP_WINDOW_TITLE,
title: appWindowTitle(),
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
useContentSize: true, // Specify web page size without OS chrome
width: initialBounds.width,
x: initialBounds.x,
y: initialBounds.y
})

win.loadURL(config.WINDOW_MAIN)
win.loadURL(defaults.main)

win.once('ready-to-show', () => {
if (!options.hidden) win.show()
})

if (win.setSheetOffset) {
win.setSheetOffset(config.UI_HEADER_HEIGHT)
win.setSheetOffset(defaults.headerHeight)
}

win.webContents.on('dom-ready', () => {
})

win.webContents.on('will-navigate', (e, url) => {
// Prevent drag-and-drop from navigating the Electron window, which can happen
// before our drag-and-drop handlers have been initialized.
Expand Down Expand Up @@ -144,9 +148,9 @@ function setProgress (progress) {
function setTitle (title) {
if (!main.win) return
if (title) {
main.win.setTitle(`${config.APP_WINDOW_TITLE} - ${title}`)
main.win.setTitle(`${appWindowTitle()} - ${title}`)
} else {
main.win.setTitle(config.APP_WINDOW_TITLE)
main.win.setTitle(appWindowTitle())
}
}

Expand Down Expand Up @@ -176,12 +180,6 @@ function toggleDevTools () {
}
}

function getIconPath () {
return process.platform === 'win32'
? config.APP_ICON + '.ico'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken. Lets fix this when we need .ico file for windows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a TODO comment about it in application-constants.js.

: config.APP_ICON + '.png'
}

function chooseLanguage (locale) {
main.win.send('chooseLanguage', locale)
}
13 changes: 8 additions & 5 deletions src/renderer/components/dialogs/About.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const React = require('react')
const { remote } = require('electron')
const { Classes, Dialog } = require('@blueprintjs/core')
/* *CONFIG* */
const { APP_VERSION } = require('../../../config')
const {
appVersion,
gitHubUrl,
gitHubLicenseUrl
} = require('../../../application-constants')
const Unselectable = require('../helpers/Unselectable')

class ClickableLink extends React.Component {
Expand Down Expand Up @@ -32,10 +35,10 @@ class About extends React.Component {
canOutsideClickClose={false}>
<div className={Classes.DIALOG_BODY}>
<Unselectable>
<p style={{ color: 'grey' }}>{`Version ${APP_VERSION}`}</p>
<p style={{ color: 'grey' }}>{`Version ${appVersion()}`}</p>
<p>Official Delta Chat Desktop app.</p>
<p>This software is licensed under <ClickableLink href='https://github.com/deltachat/deltachat-desktop/blob/master/LICENSE' text='GNU GPL version 3' />.</p>
<p>Source code is available on <ClickableLink href='https://github.com/deltachat/deltachat-desktop' text='GitHub' />.</p>
<p>This software is licensed under <ClickableLink href={gitHubLicenseUrl()} text='GNU GPL version 3' />.</p>
<p>Source code is available on <ClickableLink href={gitHubUrl()} text='GitHub' />.</p>
ralphtheninja marked this conversation as resolved.
Show resolved Hide resolved
</Unselectable>
</div>
</Dialog>
Expand Down
4 changes: 0 additions & 4 deletions src/renderer/lib/state.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const appConfig = require('application-config')('DeltaChat')
const path = require('path')
const { EventEmitter } = require('events')
/* *CONFIG* */
const config = require('../../config')
const log = require('../../logger').getLogger('renderer/state')

const SAVE_DEBOUNCE_INTERVAL = 1000

appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, appConfig.filePath defaults to /path/to/config.json


const State = module.exports = Object.assign(new EventEmitter(), {
load,
// state.save() calls are rate-limited. Use state.saveImmediate() to skip limit.
Expand Down
4 changes: 2 additions & 2 deletions test/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const PNG = require('pngjs').PNG
const tempy = require('tempy')
const mkdirp = require('mkdirp')

const config = require('../../src/config')
mkdirp.sync(config.CONFIG_PATH)
const { getConfigPath } = require('../../src/application-constants')
mkdirp.sync(getConfigPath())
ralphtheninja marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
createApp,
Expand Down