This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from Siderus/feature/add-share-capability
Add share option to properties and storagelist
- Loading branch information
Showing
4 changed files
with
81 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Settings from 'electron-settings' | ||
import { shell, remote } from 'electron' | ||
|
||
/** | ||
* Open hashes in a browser | ||
* @param {string[]} hashes | ||
*/ | ||
export function openInBrowser (hashes) { | ||
hashes.forEach(hash => { | ||
shell.openExternal(getURLFromHash(hash)) | ||
}) | ||
return Promise.resolve(hashes) | ||
} | ||
|
||
/** | ||
* Constructs a shareable url with the gateway from settings or the default one | ||
* | ||
* @param {string} hash | ||
* @returns {string} | ||
*/ | ||
export function getURLFromHash (hash) { | ||
const gatewayURL = Settings.get('gatewayURL') || 'https://siderus.io' | ||
return `${gatewayURL}/ipfs/${hash}` | ||
} | ||
|
||
export function shareViaFacebook (hash) { | ||
return shell.openExternal(`https://www.facebook.com/sharer.php?u=${getURLFromHash(hash)}`) | ||
} | ||
|
||
export function shareViaTwitter (hash) { | ||
return shell.openExternal(`https://twitter.com/intent/tweet?text=${getURLFromHash(hash)}`) | ||
} | ||
|
||
export function shareViaEmail (hash) { | ||
return shell.openExternal(`mailto:?body=${getURLFromHash(hash)}`) | ||
} | ||
|
||
export const shareMenuTemplate = (hash) => ([{ | ||
label: 'Copy URL', | ||
click: () => { | ||
remote.clipboard.writeText(getURLFromHash(hash)) | ||
} | ||
}, { | ||
label: 'via Email', | ||
click: () => { | ||
shareViaEmail(hash) | ||
} | ||
}, { | ||
label: 'via Facebook', | ||
click: () => { | ||
shareViaFacebook(hash) | ||
} | ||
}, { | ||
label: 'via Twitter', | ||
click: () => { | ||
shareViaTwitter(hash) | ||
} | ||
}]) |
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