Skip to content

Commit 53b35f5

Browse files
committed
Merge branch 'dev'
2 parents 036611b + 5a51ec7 commit 53b35f5

12 files changed

Lines changed: 89 additions & 79 deletions

File tree

@types/Renderer/webApi.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ declare namespace WebApi {
3434
},
3535
];
3636
}
37+
38+
interface SetClipboardData {
39+
format: string;
40+
data: Uint8Array;
41+
}
42+
43+
interface GetFonts {
44+
useAgent: boolean;
45+
}
46+
47+
interface GetFontFile {
48+
path: string;
49+
postscript: string;
50+
}
3751
}

@types/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type FontsMap = import("figma-linux-rust-binding").Fonts.IFonts;
2+
13
declare namespace Electron {
24
interface RemoteMainInterface {
35
app: App;
@@ -86,6 +88,10 @@ declare namespace Electron {
8688
on(channel: "set-default-theme", listener: (event: IpcMainInvokeEvent) => void): this;
8789
on(channel: "saveCreatorTheme", listener: (event: IpcMainInvokeEvent, theme: Themes.Theme) => void): this;
8890
on(channel: "sync-themes", listener: (event: IpcMainInvokeEvent) => void): this;
91+
on(
92+
channel: "set-clipboard-data",
93+
listener: (event: IpcMainInvokeEvent, data: WebApi.SetClipboardData) => void,
94+
): this;
8995

9096
handle(
9197
channel: "writeNewExtensionToDisk",
@@ -115,6 +121,11 @@ declare namespace Electron {
115121
channel: "writeFiles",
116122
listener: (event: IpcMainInvokeEvent, data: WebApi.WriteFiles) => Promise<void> | void,
117123
): void;
124+
handle(channel: "get-fonts", listener: (event: IpcMainInvokeEvent) => Promise<void> | FontsMap): void;
125+
handle(
126+
channel: "get-font-file",
127+
listener: (event: IpcMainInvokeEvent, data: WebApi.GetFontFile) => Promise<void> | Buffer,
128+
): void;
118129
}
119130

120131
interface IpcRenderer extends NodeJS.EventEmitter {
@@ -171,6 +182,7 @@ declare namespace Electron {
171182
send(channel: "set-default-theme"): this;
172183
send(channel: "saveCreatorTheme", theme: Themes.Theme): this;
173184
send(channel: "sync-themes"): this;
185+
send(channel: "set-clipboard-data", data: WebApi.SetClipboardData): this;
174186

175187
invoke(channel: "writeNewExtensionToDisk", data: WebApi.WriteNewExtensionToDiskArgs): Promise<number>;
176188
invoke(channel: "getAllLocalFileExtensionIds"): Promise<number[]>;
@@ -182,6 +194,8 @@ declare namespace Electron {
182194
invoke(channel: "createMultipleNewLocalFileExtensions", data: WebApi.CreateMultipleExtension): Promise<any>;
183195
invoke(channel: "isDevToolsOpened"): Promise<boolean>;
184196
invoke(channel: "writeFiles", data: WebApi.WriteFiles): Promise<void>;
197+
invoke(channel: "get-fonts"): Promise<FontsMap>;
198+
invoke(channel: "get-font-file", data: WebApi.GetFontFile): Promise<Buffer>;
185199
}
186200

187201
interface WebContents extends NodeJS.EventEmitter {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "figma-linux",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Figma is the first interface design tool based in the browser, making it easier for teams to create software. Join as in Telegram: https://t.me/figma_linux",
55
"main": "src/main/index.js",
66
"repository": "git@github.com:ChugunovRoman/figma-linux.git",

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: figma-linux
2-
version: '0.7.0'
2+
version: '0.7.1'
33
summary: Unofficial Figma desktop app for Linux platform
44
description: |
55
Figma is the first interface design tool based in the browser,

src/main/Fonts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "fs";
12
import { Fonts, getFonts } from "figma-linux-rust-binding";
23

34
class Fonts {
@@ -9,6 +10,10 @@ class Fonts {
910
resolve(fonts);
1011
});
1112
});
13+
14+
public static getFontFile = async (path: string): Promise<Buffer> => {
15+
return fs.promises.readFile(path);
16+
};
1217
}
1318

1419
export default Fonts;

src/main/window/Tabs.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import * as E from "electron";
22
import * as path from "path";
33

4-
import { DEFAULT_SETTINGS } from "Const";
54
import { isDev } from "Utils/Common";
6-
import Fonts from "../Fonts";
75
import { storage } from "../Storage";
8-
import { logger } from "../Logger";
96
import WindowManager from "./WindowManager";
107

118
export default class Tabs {
@@ -43,8 +40,6 @@ export default class Tabs {
4340
tab.setBounds(rect);
4441
tab.webContents.loadURL(url);
4542
tab.webContents.on("dom-ready", () => {
46-
let dirs = storage.get().app.fontDirs;
47-
4843
const currentThemeId = storage.get().theme.currentTheme;
4944
if (currentThemeId !== "0") {
5045
const wm = WindowManager.instance;
@@ -54,15 +49,6 @@ export default class Tabs {
5449
tab.webContents.send("themes-change", foundTheme);
5550
}
5651
}
57-
58-
if (!dirs) {
59-
dirs = DEFAULT_SETTINGS.app.fontDirs;
60-
}
61-
Fonts.getFonts(dirs)
62-
.catch(err => logger.error(`Failed to load local fonts, error: ${err}`))
63-
.then(fonts => {
64-
tab.webContents.send("updateFonts", fonts);
65-
});
6652
});
6753

6854
isDev && tab.webContents.toggleDevTools();

src/main/window/WindowManager.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as E from "electron";
33
import * as url from "url";
44

55
import Tabs from "./Tabs";
6+
import Fonts from "../Fonts";
67
import { storage } from "../Storage";
78
import { logger } from "../Logger";
89
import MenuState from "../MenuState";
@@ -422,6 +423,38 @@ class WindowManager {
422423
}
423424
logger.debug("Sync themes end");
424425
});
426+
E.ipcMain.on("set-clipboard-data", (event, data) => {
427+
const format = data.format;
428+
const buffer = Buffer.from(data.data);
429+
430+
if (["image/jpeg", "image/png"].indexOf(format) !== -1) {
431+
E.clipboard.writeImage(E.nativeImage.createFromBuffer(buffer));
432+
} else if (format === "image/svg+xml") {
433+
E.clipboard.writeText(buffer.toString());
434+
} else if (format === "application/pdf") {
435+
E.clipboard.writeBuffer("Portable Document Format", buffer);
436+
} else {
437+
E.clipboard.writeBuffer(format, buffer);
438+
}
439+
});
440+
E.ipcMain.handle("get-fonts", async () => {
441+
let dirs = storage.get().app.fontDirs;
442+
443+
if (!dirs) {
444+
dirs = Const.DEFAULT_SETTINGS.app.fontDirs;
445+
}
446+
447+
return Fonts.getFonts(dirs);
448+
});
449+
E.ipcMain.handle("get-font-file", async (event, data) => {
450+
const file = await Fonts.getFontFile(data.path);
451+
452+
if (file && file.byteLength > 0) {
453+
return file;
454+
}
455+
456+
return null;
457+
});
425458

426459
E.app.on("toggle-current-tab-devtools", () => {
427460
toggleDetachedDevTools(this.lastFocusedTab);

src/middleware/webBinding.ts

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ const onWebMessage = (event: MessageEvent) => {
8484
try {
8585
resultPromise = msg.name && publicAPI && publicAPI[msg.name](msg.args);
8686
} catch (e) {
87-
console.error("onWebMessage, err: ", e);
87+
console.error("onWebMessage, err: ", msg.name, e);
8888
throw e;
8989
} finally {
9090
if (msg.promiseID != null) {
9191
if (resultPromise instanceof Promise) {
9292
resultPromise
9393
.then(result => {
94-
webPort.postMessage({ result: result.data, promiseID: msg.promiseID }, result.transferList);
94+
webPort.postMessage({ result: result.data, promiseID: msg.promiseID });
9595
})
9696
.catch(error => {
9797
const errorString = (error && error.name) || "Promise error";
@@ -184,7 +184,7 @@ const initWebApi = (props: IntiApiOptions) => {
184184
return new Promise((resolve, reject) => {
185185
const id = nextPromiseID++;
186186
pendingPromises.set(id, { resolve, reject });
187-
channel.port1.postMessage({ name, args, promiseID: id }, transferList);
187+
channel.port1.postMessage({ name, args, promiseID: id });
188188
});
189189
},
190190
setMessageHandler: function(handler: () => void): void {
@@ -206,7 +206,7 @@ const initWebApi = (props: IntiApiOptions) => {
206206
if ("result" in msg) {
207207
pendingPromise.resolve(msg.result);
208208
} else {
209-
sendMsgToMain("log-error", msg.error);
209+
console.error(msg.error);
210210
pendingPromise.reject(msg.error);
211211
}
212212
}
@@ -295,10 +295,6 @@ const publicAPI: any = {
295295
console.log("unimplemented setUser, args: ", args);
296296
},
297297

298-
async getFonts() {
299-
return { data: await fontMapPromise };
300-
},
301-
302298
newFile(args: any) {
303299
sendMsgToMain("newFile", args.info);
304300
},
@@ -389,42 +385,15 @@ const publicAPI: any = {
389385
return { data: isOpened };
390386
},
391387

392-
getFontFile(args: any) {
393-
return new Promise((resolve, reject) => {
394-
const fontPath = args.path;
395-
396-
if (!fontMap) {
397-
sendMsgToMain("log-error", "No fonts");
398-
reject(new Error("No fonts"));
399-
return;
400-
}
401-
402-
const faces = fontMap[fontPath];
403-
if (!faces || faces.length === 0) {
404-
sendMsgToMain("log-error", "Invalid path: ", fontPath);
405-
reject(new Error("Invalid path"));
406-
return;
407-
}
408-
409-
let postScriptName = faces[0].postscript;
410-
try {
411-
postScriptName = args.postscript;
412-
} catch (ex) {}
413-
414-
fs.readFile(fontPath, (err, data) => {
415-
if (err) {
416-
reject(err);
417-
return;
418-
}
388+
async getFonts(args: WebApi.GetFonts) {
389+
const fonts = await E.ipcRenderer.invoke("get-fonts");
390+
return { data: fonts };
391+
},
419392

420-
if (data.byteLength > 0) {
421-
resolve({ data: data.buffer, transferList: [data.buffer] });
422-
return;
423-
}
393+
async getFontFile(args: WebApi.GetFontFile) {
394+
const fontBuffer = await E.ipcRenderer.invoke("get-font-file", args);
424395

425-
reject(new Error("No data"));
426-
});
427-
});
396+
return { data: fontBuffer, transferList: [fontBuffer] };
428397
},
429398

430399
getClipboardData(args: any) {
@@ -481,19 +450,8 @@ const publicAPI: any = {
481450
});
482451
},
483452

484-
setClipboardData(args: any) {
485-
const format = args.format;
486-
const data = Buffer.from(args.data);
487-
488-
if (["image/jpeg", "image/png"].indexOf(format) !== -1) {
489-
E.clipboard.writeImage(E.remote.nativeImage.createFromBuffer(data));
490-
} else if (format === "image/svg+xml") {
491-
E.clipboard.writeText(data.toString());
492-
} else if (format === "application/pdf") {
493-
E.clipboard.writeBuffer("Portable Document Format", data);
494-
} else {
495-
E.clipboard.writeBuffer(format, data);
496-
}
453+
setClipboardData(args: WebApi.SetClipboardData) {
454+
E.ipcRenderer.send("set-clipboard-data", args);
497455
},
498456

499457
async writeFiles(args: WebApi.WriteFiles) {
@@ -506,7 +464,7 @@ const init = (fileBrowser: boolean): void => {
506464
"message",
507465
event => {
508466
webPort = event.ports[0];
509-
console.log(`window message, webPort: `, webPort);
467+
console.log(`window message, webPort: `, webPort, event.data);
510468
webPort && (webPort.onmessage = onWebMessage);
511469
},
512470
{ once: true },
@@ -517,8 +475,6 @@ const init = (fileBrowser: boolean): void => {
517475
fileBrowser: fileBrowser,
518476
};
519477

520-
console.log("init(): window.parent.document: ", window.parent.document.body);
521-
522478
initWebBindings();
523479

524480
E.webFrame.executeJavaScript(`(${initWebApi.toString()})(${JSON.stringify(initWebOptions)})`);

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "figma-linux",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Figma is the first interface design tool based in the browser, making it easier for teams to create software. Join as in Telegram: https://t.me/figma_linux",
55
"main": "main/main.js",
66
"repository": "git@github.com:ChugunovRoman/figma-linux.git",

src/renderer/components/Tabs/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Tabs extends React.Component<TabsProps, unknown> {
3030

3131
const tabs = toJS(this.props.tabs.tabs);
3232
const currentTabId: number | undefined = toJS(this.props.tabs.current);
33-
const currentTabIndex: number = tabs.findIndex(t => t.id === id);
33+
const currentTabIndex: number = tabs.findIndex((t: any) => t.id === id);
3434

3535
E.ipcRenderer.send("closeTab", id);
3636

@@ -160,6 +160,10 @@ class Tabs extends React.Component<TabsProps, unknown> {
160160
return;
161161
}
162162

163+
e.preventDefault();
164+
e.stopPropagation();
165+
e.stopImmediatePropagation();
166+
163167
const w = E.remote.getCurrentWindow();
164168
const windowBounds = w.getBounds();
165169

0 commit comments

Comments
 (0)