forked from ipfs/ipfs-desktop
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
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 = 'namesys-pubsub' | ||
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