Skip to content

Commit

Permalink
Merge pull request #27 from syncpoint/auto-update
Browse files Browse the repository at this point in the history
disable self-update with environment variable
  • Loading branch information
ThomasHalwax committed Sep 20, 2023
2 parents c1ff2c4 + af0a133 commit f263427
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* @param {String} name The environment variable name to check
* @param {Boolean} defaultValue Can either be true or false. If omitted the default value is always true
* @returns {Boolean} Either the value of the environment variable or the default value
*/
export const isEnabled = (name, defaultValue = true) => {
if (!process.env[name]) return defaultValue
if (process.env[name].toUpperCase() === 'TRUE') return true
if (process.env[name] === '1') return true
return false
}
38 changes: 38 additions & 0 deletions src/main/environment.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import assert from 'assert'
import { isEnabled } from './environment'

describe('environment isEnabled', function () {
it('return default=false if not set', function () {
const value = isEnabled('TEST_SELF_UPDATE', false)
assert.equal(value, false)
})

it('return default=true if not set', function () {
const value = isEnabled('TEST_SELF_UPDATE', true)
assert.equal(value, true)
})

it('return true if value=TRUE', function () {
process.env.TEST_SELF_UPDATE = 'true'
const value = isEnabled('TEST_SELF_UPDATE', false)
assert.equal(value, true)
})

it('return true if value=1', function () {
process.env.TEST_SELF_UPDATE = '1'
const value = isEnabled('TEST_SELF_UPDATE', false)
assert.equal(value, true)
})

it('return true if value=FALSE', function () {
process.env.TEST_SELF_UPDATE = 'false'
const value = isEnabled('TEST_SELF_UPDATE', true)
assert.equal(value, false)
})

it('return true if value=0', function () {
process.env.TEST_SELF_UPDATE = '0'
const value = isEnabled('TEST_SELF_UPDATE', true)
assert.equal(value, false)
})
})
7 changes: 5 additions & 2 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { exportLayer } from './export.js'
import { ipc } from './ipc'
import * as dotenv from 'dotenv'
import SelfUpdate from './SelfUpdate'
import { isEnabled } from './environment'

/**
* Emitted once, when Electron has finished initializing.
Expand Down Expand Up @@ -107,8 +108,10 @@ const ready = async () => {
await session.restore()
await menu.show()

const selfUpdate = new SelfUpdate()
selfUpdate.checkForUpdates()
if (isEnabled('ODIN_SELF_UPDATE', true)) {
const selfUpdate = new SelfUpdate()
selfUpdate.checkForUpdates()
}
}


Expand Down

0 comments on commit f263427

Please sign in to comment.