mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
d3ce502c13
* Install plugins from npm * A bit more * Error handling and messaging
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
// @flow
|
|
import type {Plugin} from '../';
|
|
import * as electron from 'electron';
|
|
import {showAlert} from '../../ui/components/modals/index';
|
|
|
|
export function init (plugin: Plugin): {app: Object} {
|
|
return {
|
|
app: {
|
|
alert (message: string): Promise<void> {
|
|
return showAlert({title: `Plugin ${plugin.name}`, message: message || ''});
|
|
},
|
|
getPath (name: string): string {
|
|
switch (name.toLowerCase()) {
|
|
case 'desktop':
|
|
return electron.remote.app.getPath('desktop');
|
|
default:
|
|
throw new Error(`Unknown path name ${name}`);
|
|
}
|
|
},
|
|
async showSaveDialog (options: {defaultPath?: string} = {}): Promise<string | null> {
|
|
return new Promise(resolve => {
|
|
const saveOptions = {
|
|
title: 'Save File',
|
|
buttonLabel: 'Save',
|
|
defaultPath: options.defaultPath
|
|
};
|
|
|
|
electron.remote.dialog.showSaveDialog(saveOptions, filename => {
|
|
resolve(filename || null);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}
|