Skip to content

Commit

Permalink
feat: improve DX with env variables
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Feb 28, 2023
1 parent daa1e4a commit 231374e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Path to talk repository
TALK_PATH=spreed

# List of Nextcloud development server hosts separetad by comma
# For example: https://nextcloud.local,https://stable25.local
NEXTCLOUD_DEV_SERVER_HOSTS=https://nextcloud.local
# List of Nextcloud development server hosts separetad by space (incl. signaling WS server host)
# Example: https://nextcloud.local https://stable26.local
NEXTCLOUD_DEV_SERVER_HOSTS=https://nextcloud.local https://stable26.local
4 changes: 1 addition & 3 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

require('dotenv').config()

const DEV_SERVER_HOST = process.env.NEXTCLOUD_DEV_SERVER_HOSTS ?? 'https://nextcloud.local'

module.exports = {
packagerConfig: {
icon: './spreed/img/favicon.ico',
Expand Down Expand Up @@ -51,7 +49,7 @@ module.exports = {
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack.main.config.js',
devContentSecurityPolicy: `default-src 'self' 'unsafe-inline' data: blob: ${DEV_SERVER_HOST}; script-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob:`,
devContentSecurityPolicy: `default-src 'self' 'unsafe-inline' data: blob: ${process.env.NEXTCLOUD_DEV_SERVER_HOSTS}; script-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob:`,
renderer: {
config: './webpack.renderer.config.js',
entryPoints: [
Expand Down
5 changes: 4 additions & 1 deletion src/accounts/accounts.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function createAccountsWindow() {
preload: ACCOUNTS_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
})
window.removeMenu()

if (process.env.NODE_ENV === 'production') {
window.removeMenu()
}

window.loadURL(ACCOUNTS_WINDOW_WEBPACK_ENTRY)

Expand Down
2 changes: 1 addition & 1 deletion src/accounts/renderer/WindowAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default {

data() {
return {
serverUrl: process.env.NODE_ENV !== 'production' ? 'https://nextcloud.local' : '',
serverUrl: process.env.NODE_ENV !== 'production' ? process.env.NEXTCLOUD_DEV_SERVER_HOSTS?.split?.(' ')?.[0] : '',
/** @type {'idle'|'loading'|'error'|'success'} */
state: 'idle',
stateText: '',
Expand Down
4 changes: 2 additions & 2 deletions src/app/webRequestInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

const { session } = require('electron')
const { DEVSERVER_HOST } = require('../constants.js')
const { DEV_SERVER_ORIGIN } = require('../constants.js')

/**
* Patch requests on the default session to a specific Nextcloud server for Cookies or CORS.
Expand Down Expand Up @@ -65,7 +65,7 @@ function enableWebRequestInterceptor(serverUrl, {
}
}

const ALLOWED_ORIGIN = [process.env.NODE_ENV === 'production' ? 'file://' : `${DEVSERVER_HOST}`]
const ALLOWED_ORIGIN = [process.env.NODE_ENV === 'production' ? 'file://' : `${DEV_SERVER_ORIGIN}`]
const ALLOWED_CREDENTIALS_TRUE = ['true']
const ALLOWED_HEADERS = [[
// Common headers
Expand Down
6 changes: 2 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

const BASE_TITLE = 'Talk Desktop'
const USER_AGENT = 'Talk Desktop'
const DEVSERVER_HOST = 'http://localhost:3000'
const SERVER_URL = process.env.NEXTCLOUD_DEV_SERVER_HOSTS
const DEV_SERVER_ORIGIN = 'http://localhost:3000'

module.exports = {
BASE_TITLE,
USER_AGENT,
DEVSERVER_HOST,
SERVER_URL,
DEV_SERVER_ORIGIN,
}
5 changes: 4 additions & 1 deletion src/talk/talk.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function createTalkWindow() {
preload: TALK_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
})
window.removeMenu()

if (process.env.NODE_ENV === 'production') {
window.removeMenu()
}

window.once('ready-to-show', () => {
window.maximize()
Expand Down
5 changes: 4 additions & 1 deletion webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module.exports = merge(commonTalkWebpackConfig, {
t: ['@nextcloud/l10n', 'translate'],
}),

new webpack.DefinePlugin({ IS_TALK_DESKTOP: true }),
new webpack.DefinePlugin({
IS_TALK_DESKTOP: true,
'process.env.NEXTCLOUD_DEV_SERVER_HOSTS': JSON.stringify(process.env.NEXTCLOUD_DEV_SERVER_HOSTS),
}),
],
})

0 comments on commit 231374e

Please sign in to comment.