1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

screenshots for templates

This commit is contained in:
Andrew Simachev 2021-03-29 20:05:29 +03:00
parent 8fe133675a
commit e6cb1b330b
9 changed files with 90 additions and 25 deletions

View file

@ -25,6 +25,7 @@ const KEYTAR_SERVICE = 'Anytype';
let isUpdating = false;
let userPath = app.getPath('userData');
let tmpPath = path.join(userPath, 'tmp');
let waitLibraryPromise;
let useGRPC = !process.env.ANYTYPE_USE_ADDON && (process.env.ANYTYPE_USE_GRPC || (process.platform == "win32") || is.development);
let defaultChannel = version.match('alpha') ? 'alpha' : 'latest';
@ -61,9 +62,7 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) {
storage.setDataPath(userPath);
if (process.env.DATA_PATH) {
try {
fs.mkdirSync(process.env.DATA_PATH);
} catch (err) {};
try { fs.mkdirSync(process.env.DATA_PATH); } catch (e) {};
dataPath.push(process.env.DATA_PATH);
} else {
@ -74,6 +73,8 @@ if (process.env.DATA_PATH) {
dataPath.push('data');
};
try { fs.mkdirSync(tmpPath); } catch (e) {};
if (useGRPC) {
console.log('Connect via gRPC');
@ -291,6 +292,20 @@ function createWindow () {
send.apply(this, args);
});
ipcMain.on('screenshot', (event, arg) => {
win.webContents.capturePage().then((image) => {
const fp = path.join(tmpPath, 'screenshot.jpg');
fs.writeFile(fp, image.toJPEG(90), (err) => {
if (err) {
throw err;
};
send('commandEditor', 'screenshot', fp);
});
});
});
ipcMain.on('winCommand', (e, cmd) => {
switch (cmd) {
case 'menu':

View file

@ -12,6 +12,7 @@
.iconCommon.c20, .smileImage.c20, .iconImage.c20, .iconFile.c20, .iconCheckbox.c20 { @include pos-abs-mid; width: 20px; height: 20px; margin: -10px 0px 0px -10px; }
.iconCommon.c22, .smileImage.c22, .iconImage.c22, .iconFile.c22, .iconCheckbox.c22 { @include pos-abs-mid; width: 22px; height: 22px; margin: -11px 0px 0px -11px; }
.iconCommon.c24, .smileImage.c24, .iconImage.c24, .iconFile.c24, .iconCheckbox.c24 { @include pos-abs-mid; width: 24px; height: 24px; margin: -12px 0px 0px -12px; }
.iconCommon.c26, .smileImage.c26, .iconImage.c26, .iconFile.c26, .iconCheckbox.c26 { @include pos-abs-mid; width: 26px; height: 26px; margin: -13px 0px 0px -13px; }
.iconCommon.c28, .smileImage.c28, .iconImage.c28, .iconFile.c28, .iconCheckbox.c28 { @include pos-abs-mid; width: 28px; height: 28px; margin: -14px 0px 0px -14px; }
.iconCommon.c30, .smileImage.c30, .iconImage.c30, .iconFile.c30, .iconCheckbox.c30 { @include pos-abs-mid; width: 30px; height: 30px; margin: -15px 0px 0px -15px; }
.iconCommon.c32, .smileImage.c32, .iconImage.c32, .iconFile.c32, .iconCheckbox.c32 { @include pos-abs-mid; width: 32px; height: 32px; margin: -16px 0px 0px -16px; }

View file

@ -21,7 +21,6 @@
.content { max-height: 362px; padding: 12px 0px; }
}
.menu.menuBlockAdd {
.item.withColor { border-radius: 8px; }
.item.withColor.gray {
.icon, .iconObject { background-color: #f3f2ec; }
}

View file

@ -78,6 +78,15 @@
.line { bottom: -16px; }
}
.item.template { margin: 0px 24px 28px 0px; width: 304px; height: 252px; }
.item.template:nth-child(3n + 3) { margin-right: 0px; }
.item.template {
.img {
width: 100%; height: 180px; background: $colorDarkGrey; background-repeat: no-repeat; background-size: cover;
background-position: center center; border-radius: 8px; margin-bottom: 12px;
}
}
.item.relation { width: 300px; padding-left: 60px; height: 48px; margin: 0px 30px 16px 0px; line-height: 48px; }
.item.relation:nth-child(3n + 3) { margin-right: 0px; }
.item.relation {

View file

@ -23,6 +23,7 @@ const Errors = require('json/error.json');
const $ = require('jquery');
const THROTTLE = 20;
const fs = window.require('fs');
const path = window.require('path');
@observer
class EditorPage extends React.Component<Props, {}> {
@ -142,7 +143,7 @@ class EditorPage extends React.Component<Props, {}> {
Storage.set('askSurvey', 1);
ipcRenderer.removeAllListeners('commandEditor');
ipcRenderer.on('commandEditor', (e: any, cmd: string) => { this.onCommand(cmd); });
ipcRenderer.on('commandEditor', (e: any, cmd: string, arg: any) => { this.onCommand(cmd, arg); });
};
componentDidUpdate () {
@ -222,9 +223,7 @@ class EditorPage extends React.Component<Props, {}> {
C.BlockOpen(this.id, (message: any) => {
if (message.error.code) {
if (message.error.code == Errors.Code.ANYTYPE_NEEDS_UPGRADE) {
Util.onErrorUpdate(() => {
history.push('/main/index');
});
Util.onErrorUpdate(() => { history.push('/main/index'); });
} else {
history.push('/main/index');
};
@ -237,6 +236,13 @@ class EditorPage extends React.Component<Props, {}> {
this.resize();
this.getScrollContainer().scrollTop(Storage.getScroll('editor' + (isPopup ? 'Popup' : ''), rootId));
const object = blockStore.getDetails(rootId, rootId);
if (object.type == '_ottemplate') {
window.setInterval(() => {
ipcRenderer.send('screenshot');
}, 3000);
};
blockStore.setNumbers(rootId);
if (onOpen) {
@ -245,7 +251,7 @@ class EditorPage extends React.Component<Props, {}> {
});
};
onCommand (cmd: string) {
onCommand (cmd: string, arg: any) {
if (keyboard.isFocused) {
return;
};
@ -274,6 +280,20 @@ class EditorPage extends React.Component<Props, {}> {
case 'search':
this.onSearch();
break;
case 'screenshot':
if (!arg) {
break;
};
C.UploadFile('', arg, I.FileType.Image, true, (message: any) => {
if (message.error.code) {
return;
};
DataUtil.pageSetCover(rootId, I.CoverType.Upload, message.hash, 0, -0.5);
});
break;
};
};
@ -1122,7 +1142,7 @@ class EditorPage extends React.Component<Props, {}> {
const { dataset, rootId } = this.props;
const { selection } = dataset || {};
const { focused, range } = focus;
const { path } = authStore;
const filePath = authStore.path;
const currentFrom = range.from;
const currentTo = range.to;
@ -1156,26 +1176,19 @@ class EditorPage extends React.Component<Props, {}> {
commonStore.progressSet({ status: 'Processing...', current: 0, total: files.length });
for (let file of files) {
const dir = path + '/tmp';
const fn = dir + '/' + file.name;
const dir = path.join(filePath, 'tmp');
const fn = path.join(dir, file.name);
const reader = new FileReader();
reader.readAsBinaryString(file);
reader.onloadend = () => {
try {
fs.mkdirSync(dir);
} catch (e) {};
fs.writeFile(fn, reader.result, 'binary', (err: any) => {
if (err) {
console.error(err);
return;
};
data.files.push({
name: file.name,
path: fn,
});
data.files.push({ name: file.name, path: fn });
commonStore.progressSet({ status: 'Processing...', current: data.files.length, total: files.length });

View file

@ -64,7 +64,16 @@ class MenuBlockAdd extends React.Component<Props, {}> {
action.iconSize = 40;
};
return <MenuItemVertical key={action.id + '-' + i} {...action} withDescription={action.isBlock} onMouseEnter={(e: any) => { this.onMouseEnter(e, action); }} onClick={(e: any) => { this.onClick(e, action); }} />;
return (
<MenuItemVertical
key={action.id + '-' + i}
{...action}
className={action.isHidden ? 'isHidden' : ''}
withDescription={action.isBlock}
onMouseEnter={(e: any) => { this.onMouseEnter(e, action); }}
onClick={(e: any) => { this.onClick(e, action); }}
/>
);
})}
</div>
</div>

View file

@ -138,6 +138,20 @@ class PopupStore extends React.Component<Props, State> {
break;
case Tab.Template:
Item = (item: any) => {
const author = blockStore.getDetails(rootId, item.creator);
return (
<div className={[ 'item', tab, meta.viewId ].join(' ')} onClick={(e: any) => { this.onClick(e, item); }}>
<div className="img" />
<div className="info">
<div className="name">{item.name}</div>
<div className="descr">{item.description}</div>
<Author {...author} />
</div>
</div>
);
};
mid = (
<div className="mid">
<Title text="Template space" />
@ -320,7 +334,7 @@ class PopupStore extends React.Component<Props, State> {
let h = 0;
if (tab == Tab.Type) h = 96;
if (tab == Tab.Template) h = 2;
if (tab == Tab.Template) h = 280;
if (tab == Tab.Relation) h = 64;
return h;
};

View file

@ -36,7 +36,7 @@ const Size = {
18: 18,
20: 18,
24: 20,
26: 20,
26: 22,
28: 22,
32: 28,
40: 24,

View file

@ -458,8 +458,7 @@ class DataUtil {
menuGetBlockObject () {
const { config } = commonStore;
const objectTypes = dbStore.objectTypes.filter((it: I.ObjectType) => { return !it.isHidden; });
let ret: any[] = [
{ type: I.BlockType.File, id: I.FileType.File, icon: 'file', lang: 'File' },
{ type: I.BlockType.File, id: I.FileType.Image, icon: 'image', lang: 'Image' },
@ -470,6 +469,11 @@ class DataUtil {
let i = 0;
if (config.allowDataview) {
let objectTypes = Util.objectCopy(dbStore.objectTypes);
if (!config.debug.ho) {
objectTypes = objectTypes.filter((it: I.ObjectType) => { return !it.isHidden; })
};
for (let type of objectTypes) {
ret.push({
type: I.BlockType.Page,
@ -479,6 +483,7 @@ class DataUtil {
name: type.name || Constant.default.name,
description: type.description,
isObject: true,
isHidden: type.isHidden,
});
};
} else {