Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: restore export functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent efc2f71 commit edfb369
Show file tree
Hide file tree
Showing 37 changed files with 1,116 additions and 410 deletions.
38 changes: 27 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"@types/mime-types": "2.1.0",
"@types/mock-fs": "3.6.30",
"@types/node": "9.6.5",
"@types/node-fetch": "2.1.1",
"@types/object-path": "0.9.29",
"@types/react": "16.3.10",
"@types/react-dom": "16.0.5",
Expand Down Expand Up @@ -145,7 +146,7 @@
},
"dependencies": {
"@brainly/html-sketchapp": "3.0.2",
"@marionebl/react-docgen-typescript": "1.6.0-1",
"@marionebl/sander": "0.6.1",
"@patternplate/load-config": "2.5.2",
"@patternplate/load-meta": "2.5.2",
"@types/feather-icons": "4.7.0",
Expand Down Expand Up @@ -177,6 +178,7 @@
"mime-types": "2.1.18",
"mobx": "5.0.3",
"mobx-react": "5.2.3",
"node-fetch": "2.1.2",
"object-path": "0.11.4",
"query-string": "6.0.0",
"re-resizable": "4.4.8",
Expand Down
112 changes: 66 additions & 46 deletions src/electron/auto-updater.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,80 @@
import { BrowserWindow, dialog } from 'electron';
import { autoUpdater } from 'electron-updater';

let showUpdateNotAvailable = false;
let window: BrowserWindow;
const registry: Map<BrowserWindow, { showUpdateNotAvailable: boolean }> = new Map();
const windows: Set<BrowserWindow> = new Set();

export function checkForUpdates(win: BrowserWindow, startedByUser?: boolean): void {
export async function checkForUpdates(win: BrowserWindow, startedByUser?: boolean): Promise<void> {
autoUpdater.autoDownload = false;
showUpdateNotAvailable = startedByUser || false;
window = win;
autoUpdater.checkForUpdatesAndNotify().catch(() => {
dialog.showErrorBox('Check for Updates', 'Error while checking for updates.');

windows.add(win);

registry.set(win, {
showUpdateNotAvailable: startedByUser || false
});

try {
await autoUpdater.checkForUpdatesAndNotify();
} catch {
dialog.showErrorBox('Check for Updates', 'Error while checking for updates.');
}
}

autoUpdater.on('update-available', info => {
dialog.showMessageBox(
{
type: 'info',
message: `There is a new version available: ${
info.version
} \nShould Alva download the update?`,
buttons: ['yes', 'no']
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate().catch(() => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually.'
);
});
export function startUpdater(): void {
autoUpdater.on('update-available', info => {
dialog.showMessageBox(
{
type: 'info',
message: `There is a new version available: ${
info.version
} \nShould Alva download the update?`,
buttons: ['yes', 'no']
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate().catch(() => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually.'
);
});
}
}
}
);
});
);
});

autoUpdater.on('update-not-available', info => {
if (showUpdateNotAvailable) {
dialog.showMessageBox({ message: 'Alva is up-to-date.' });
}
});
autoUpdater.on('update-not-available', info => {
windows.forEach(window => {
const context = registry.get(window);
if (context && context.showUpdateNotAvailable) {
dialog.showMessageBox({ message: 'Alva is up-to-date.' });
}
});
});

autoUpdater.on('error', () => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually.'
);
});

autoUpdater.on('error', () => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually.'
);
});
autoUpdater.on('download-progress', progressObj => {
windows.forEach(window => {
window.setProgressBar(progressObj.percent / 100);
});
});

autoUpdater.on('download-progress', progressObj => {
window.setProgressBar(progressObj.percent / 100);
});
autoUpdater.on('update-downloaded', info => {
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart.' });

autoUpdater.on('update-downloaded', info => {
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart.' });
// remove progress bar
windows.forEach(window => {
window.setProgressBar(-1);
});
});
}

// remove progress bar
window.setProgressBar(-1);
});
export function stopUpdater(): void {
autoUpdater.removeAllListeners();
}
106 changes: 13 additions & 93 deletions src/electron/create-main-menu/create-file-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,58 +92,11 @@ export function createFileMenu(
return;
}

const path = await queryPath({
title: 'Export Sketch as',
typeName: 'Almost Sketch JSON',
defaultName: `${activePage.getName()}.asketch`,
extname: 'json'
injection.sender.send({
id: uuid.v4(),
type: ServerMessageType.ExportSketchPage,
payload: { path: undefined }
});

Electron.dialog.showMessageBox(
{
type: 'info',
message:
'Before you can open an exported Sketch-File:\n\n(1) Download & Install "Almost Sketch Plugin"\n\n(2) Open Sketch, run "Plugins > From Almost Sketch to Sketch" and select exported file\n\nWe are currently working on a smoother experience.',
buttons: ['OK', 'Download Plugin']
},
response => {
if (response === 1) {
Electron.shell.openExternal(
'https://github.com/brainly/html-sketchapp/releases/latest'
);
}
}
);

if (path) {
injection.sender.send({
id: uuid.v4(),
type: ServerMessageType.ExportSketchTask,
payload: { path }
});
}
}
},
{
label: 'Export Page as PDF',
enabled: Boolean(activePage),
click: async () => {
if (!activePage) {
return;
}

const path = await queryPath({
title: 'Export PDF as',
typeName: 'PDF Document',
defaultName: activePage.getName(),
extname: 'pdf'
});

if (path) {
// TODO
// const pdfExporter = new PdfExporter(ctx.store);
// pdfExporter.execute(path);
}
}
},
{
Expand All @@ -154,18 +107,11 @@ export function createFileMenu(
return;
}

const path = await queryPath({
title: 'Export PNG as',
typeName: 'PNG Image',
defaultName: activePage.getName(),
extname: 'png'
injection.sender.send({
id: uuid.v4(),
type: ServerMessageType.ExportPngPage,
payload: { path: undefined }
});

if (path) {
// TODO
// const pngExporter = new PngExporter(ctx.store);
// pngExporter.execute(path);
}
}
},
{
Expand All @@ -174,23 +120,17 @@ export function createFileMenu(
{
label: 'Export Project as HTML',
enabled: Boolean(activePage),
accelerator: 'CmdOrCtrl+Shift+E',
click: async () => {
if (!project) {
return;
}

const path = await queryPath({
title: 'Export HTML as',
typeName: 'HTML File',
defaultName: project.getName(),
extname: 'html'
injection.sender.send({
id: uuid.v4(),
type: ServerMessageType.ExportHtmlProject,
payload: { path: undefined }
});

if (path) {
// TODO
// const htmlExporter = new HtmlExporter(ctx.store);
// htmlExporter.execute(path);
}
}
}
]
Expand All @@ -211,23 +151,3 @@ export function createFileMenu(
]
};
}

interface PathQuery {
defaultName: string;
extname: string;
title: string;
typeName: string;
}

function queryPath(options: PathQuery): Promise<string> {
return new Promise((resolve, reject) => {
Electron.dialog.showSaveDialog(
{
title: options.title,
defaultPath: `${options.defaultName}.${options.extname}`,
filters: [{ name: options.typeName, extensions: [options.extname] }]
},
resolve
);
});
}
2 changes: 1 addition & 1 deletion src/electron/create-main-menu/create-library-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createLibraryMenu(

injection.sender.send({
id: uuid.v4(),
payload: undefined,
payload: { library: undefined },
type: Message.ServerMessageType.ConnectPatternLibraryRequest
});
}
Expand Down
Loading

0 comments on commit edfb369

Please sign in to comment.