-
Notifications
You must be signed in to change notification settings - Fork 869
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable ipns over pubsub via settings menu (#1739)
* feat: enable ipns over pubsub via settings menu Part of #1647 Very similar approach to #1735 * refactor: move pubsub experiments to exp. section making it easier to find if someone edits config by hand Co-authored-by: Marcin Rataj <[email protected]>
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const createToggler = require('./utils/create-toggler') | ||
const logger = require('./common/logger') | ||
const store = require('./common/store') | ||
const { ipcMain } = require('electron') | ||
|
||
const CONFIG_KEY = 'experiments.pubsubNamesys' | ||
const namesysPubsubFlag = '--enable-namesys-pubsub' | ||
const isEnabled = flags => flags.some(f => f === namesysPubsubFlag) | ||
|
||
function enable () { | ||
const flags = store.get('ipfsConfig.flags', []) | ||
if (!isEnabled(flags)) { | ||
flags.push(namesysPubsubFlag) | ||
applyConfig(flags) | ||
} | ||
} | ||
|
||
function disable () { | ||
let flags = store.get('ipfsConfig.flags', []) | ||
if (isEnabled(flags)) { | ||
flags = flags.filter(item => item !== namesysPubsubFlag) // remove flag | ||
applyConfig(flags) | ||
} | ||
} | ||
|
||
function applyConfig (newFlags) { | ||
store.set('ipfsConfig.flags', newFlags) | ||
ipcMain.emit('ipfsConfigChanged') // trigger node restart | ||
} | ||
|
||
module.exports = async function () { | ||
const activate = ({ newValue, oldValue }) => { | ||
if (newValue === oldValue) return | ||
|
||
try { | ||
if (newValue === true) { | ||
enable() | ||
} else { | ||
disable() | ||
} | ||
|
||
return true | ||
} catch (err) { | ||
logger.error(`[ipns over pubsub] ${err.toString()}`) | ||
|
||
return false | ||
} | ||
} | ||
activate({ newValue: store.get(CONFIG_KEY, false) }) | ||
createToggler(CONFIG_KEY, activate) | ||
logger.info(`[ipns over pubsub] ${store.get(CONFIG_KEY, false) ? 'enabled' : 'disabled'}`) | ||
} | ||
|
||
module.exports.CONFIG_KEY = CONFIG_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters