forked from Molunerfinn/PicGo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
250a014
commit 927d913
Showing
6 changed files
with
195 additions
and
28 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,85 @@ | ||
import { | ||
dialog, | ||
BrowserWindow, | ||
clipboard, | ||
Notification | ||
} from 'electron' | ||
import db from '../../datastore' | ||
import Uploader from './uploader' | ||
import pasteTemplate from './pasteTemplate' | ||
const WEBCONTENTS = Symbol('WEBCONTENTS') | ||
const IPCMAIN = Symbol('IPCMAIN') | ||
|
||
class GuiApi { | ||
constructor (ipcMain, webcontents) { | ||
this[WEBCONTENTS] = webcontents | ||
this[IPCMAIN] = ipcMain | ||
} | ||
|
||
/** | ||
* for plugin showInputBox | ||
* @param {object} options | ||
* return type is string or '' | ||
*/ | ||
showInputBox (options) { | ||
if (options === undefined) { | ||
options = { | ||
title: '', | ||
placeholder: '' | ||
} | ||
} | ||
this[WEBCONTENTS].send('showInputBox', options) | ||
return new Promise((resolve, reject) => { | ||
this[IPCMAIN].once('showInputBox', (event, value) => { | ||
resolve(value) | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* for plugin show file explorer | ||
* @param {object} options | ||
*/ | ||
showFileExplorer (options) { | ||
if (options === undefined) { | ||
options = {} | ||
} | ||
return new Promise((resolve, reject) => { | ||
dialog.showOpenDialog(BrowserWindow.fromWebContents(this[WEBCONTENTS]), options, filename => { | ||
resolve(filename) | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* for plugin to upload file | ||
* @param {array} input | ||
*/ | ||
async upload (input) { | ||
const imgs = await new Uploader(input, this[WEBCONTENTS]).upload() | ||
if (imgs !== false) { | ||
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown' | ||
let pasteText = '' | ||
for (let i in imgs) { | ||
const url = imgs[i].url || imgs[i].imgUrl | ||
pasteText += pasteTemplate(pasteStyle, url) + '\r\n' | ||
const notification = new Notification({ | ||
title: '上传成功', | ||
body: imgs[i].imgUrl, | ||
icon: imgs[i].imgUrl | ||
}) | ||
setTimeout(() => { | ||
notification.show() | ||
}, i * 100) | ||
db.read().get('uploaded').insert(imgs[i]).write() | ||
} | ||
clipboard.writeText(pasteText) | ||
this[WEBCONTENTS].send('uploadFiles', imgs) | ||
this[WEBCONTENTS].send('updateGallery') | ||
return imgs | ||
} | ||
return [] | ||
} | ||
} | ||
|
||
export default GuiApi |
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
Oops, something went wrong.