mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-08 05:57:02 +09:00
JS-6410: export import
This commit is contained in:
parent
66a7a33704
commit
edf33963e8
2 changed files with 28 additions and 1 deletions
|
@ -259,6 +259,20 @@ class Api {
|
|||
};
|
||||
};
|
||||
|
||||
shortcutExport (win, dst, data) {
|
||||
try {
|
||||
fs.writeFileSync(path.join(dst, 'shortcut.json'), JSON.stringify(data, null, '\t'), 'utf8');
|
||||
} catch (err) {};
|
||||
};
|
||||
|
||||
shortcutImport (win, src) {
|
||||
let data = {};
|
||||
if (fs.existsSync(src)) {
|
||||
try { data = JSON.parse(fs.readFileSync(src, 'utf8')); } catch (err) {};
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
module.exports = new Api();
|
|
@ -1,7 +1,7 @@
|
|||
import React, { forwardRef, useState, useEffect, useRef } from 'react';
|
||||
import $ from 'jquery';
|
||||
import { Filter, Icon, Select, Label, Error } from 'Component';
|
||||
import { I, U, J, S, translate, keyboard, Key, Storage } from 'Lib';
|
||||
import { I, U, J, S, translate, keyboard, Key, Storage, Renderer, Action } from 'Lib';
|
||||
|
||||
const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
|
||||
|
||||
|
@ -39,10 +39,23 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
|
|||
onSelect: (e: any, item: any) => {
|
||||
switch (item.id) {
|
||||
case 'export': {
|
||||
Action.openDirectoryDialog({}, paths => {
|
||||
if (paths.length) {
|
||||
Renderer.send('shortcutExport', paths[0], Storage.getShortcuts());
|
||||
};
|
||||
});
|
||||
break;
|
||||
};
|
||||
|
||||
case 'import': {
|
||||
Action.openFileDialog({ extensions: [ 'json' ] }, paths => {
|
||||
if (paths.length) {
|
||||
Renderer.send('shortcutImport', paths[0]).then((data: any) => {
|
||||
Storage.setShortcuts(data || {});
|
||||
setDummy(dummy + 1);
|
||||
});
|
||||
};
|
||||
});
|
||||
break;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue