Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: factor out showDeleteSpace listener #129

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.11.3](https://github.com/graasp/graasp-desktop/compare/v0.11.2...v0.11.3) (2019-07-22)

### Bug Fixes

- use channel specific to each app instance to get resources ([85fa4f4](https://github.com/graasp/graasp-desktop/commit/85fa4f4)), closes [#136](https://github.com/graasp/graasp-desktop/issues/136)

## [0.11.2](https://github.com/graasp/graasp-desktop/compare/v0.11.1...v0.11.2) (2019-07-21)

### Bug Fixes

- only receive messages from intended app ([7b3cfbc](https://github.com/graasp/graasp-desktop/commit/7b3cfbc)), closes [#136](https://github.com/graasp/graasp-desktop/issues/136)

## [0.11.1](https://github.com/graasp/graasp-desktop/compare/v0.11.0...v0.11.1) (2019-07-18)

### Bug Fixes

- only respond to app that sent message ([19f9a3d](https://github.com/graasp/graasp-desktop/commit/19f9a3d)), closes [#136](https://github.com/graasp/graasp-desktop/issues/136)

# [0.11.0](https://github.com/graasp/graasp-desktop/compare/v0.10.1...v0.11.0) (2019-07-17)

### Bug Fixes

- show nearby spaces below header ([4225cce](https://github.com/graasp/graasp-desktop/commit/4225cce)), closes [#138](https://github.com/graasp/graasp-desktop/issues/138)

### Features

- activation / deactivation of location sharing ([455e554](https://github.com/graasp/graasp-desktop/commit/455e554)), closes [#107](https://github.com/graasp/graasp-desktop/issues/107)
- make apps resizable ([f8bd12c](https://github.com/graasp/graasp-desktop/commit/f8bd12c)), closes [#139](https://github.com/graasp/graasp-desktop/issues/139)

## [0.10.1](https://github.com/graasp/graasp-desktop/compare/v0.10.0...v0.10.1) (2019-07-16)

### Bug Fixes

- automatically write env.json with contents from env ([128b276](https://github.com/graasp/graasp-desktop/commit/128b276)), closes [#116](https://github.com/graasp/graasp-desktop/issues/116)
- fix order of commands in dockerfile ([e1176fc](https://github.com/graasp/graasp-desktop/commit/e1176fc)), closes [#123](https://github.com/graasp/graasp-desktop/issues/123)
- setup before testing ([93c360c](https://github.com/graasp/graasp-desktop/commit/93c360c)), closes [#122](https://github.com/graasp/graasp-desktop/issues/122)
- show quicktime videos using mp4 ([1c59c04](https://github.com/graasp/graasp-desktop/commit/1c59c04)), closes [#133](https://github.com/graasp/graasp-desktop/issues/133)
- support editing video and images locally ([4f0e960](https://github.com/graasp/graasp-desktop/commit/4f0e960)), closes [#121](https://github.com/graasp/graasp-desktop/issues/121)

# [0.10.0](https://github.com/graasp/graasp-desktop/compare/v0.9.0...v0.10.0) (2019-07-02)

### Bug Fixes
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graasp-desktop",
"version": "0.10.0",
"version": "0.11.3",
"description": "Desktop application for the Graasp ecosystem.",
"private": true,
"author": "React EPFL",
Expand All @@ -9,7 +9,7 @@
"Hassan Abdul Ghaffar"
],
"license": "MIT",
"homepage": "./",
"homepage": "https://graasp.eu/",
"main": "public/electron.js",
"keywords": [
"Graasp Desktop",
Expand All @@ -20,6 +20,9 @@
"type": "git",
"url": "https://github.com/graasp/graasp-desktop"
},
"bugs": {
"url": "https://github.com/graasp/graasp-desktop/issues"
},
"scripts": {
"dev": "yarn react-scripts start",
"build": "env-cmd -f ./.env react-scripts build",
Expand Down Expand Up @@ -52,10 +55,12 @@
"@material-ui/icons": "4.2.0",
"@sentry/browser": "5.1.1",
"@sentry/electron": "0.17.1",
"about-window": "1.13.1",
"archiver": "3.0.0",
"bson-objectid": "1.2.5",
"cheerio": "1.0.0-rc.3",
"classnames": "2.2.6",
"clsx": "1.0.4",
"connected-react-router": "6.4.0",
"download": "7.1.0",
"electron-devtools-installer": "2.2.4",
Expand All @@ -70,7 +75,7 @@
"i18next": "15.1.0",
"immutable": "4.0.0-rc.12",
"is-online": "8.2.0",
"lodash": "4.17.11",
"lodash": "4.17.13",
"lowdb": "1.0.0",
"md5": "2.2.1",
"mime-types": "2.1.24",
Expand All @@ -88,6 +93,7 @@
"react-loading": "2.0.3",
"react-redux": "7.0.3",
"react-redux-toastr": "7.4.9",
"react-resizable": "1.8.0",
"react-router": "5.0.0",
"react-router-dom": "5.0.0",
"redux": "4.0.1",
Expand Down
Binary file added public/app/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/app/config/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
SET_LANGUAGE_CHANNEL: 'user:lang:set',
SET_DEVELOPER_MODE_CHANNEL: 'user:developer-mode:set',
GET_DEVELOPER_MODE_CHANNEL: 'user:developer-mode:get',
SET_GEOLOCATION_ENABLED_CHANNEL: 'user:geolocation-enabled:set',
GET_GEOLOCATION_ENABLED_CHANNEL: 'user:geolocation-enabled:get',
GET_APP_INSTANCE_RESOURCES_CHANNEL: 'app-instance-resources:get',
POST_APP_INSTANCE_RESOURCE_CHANNEL: 'app-instance-resource:post',
PATCH_APP_INSTANCE_RESOURCE_CHANNEL: 'app-instance-resource:patch',
Expand Down
15 changes: 14 additions & 1 deletion public/app/config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { app } = require('electron');
const process = require('process');

// types that we support downloading
const DOWNLOADABLE_MIME_TYPES = [
Expand All @@ -26,23 +27,35 @@ const DOWNLOADABLE_MIME_TYPES = [
'application/pdf',
];

// resolve path for windows '\'
const escapeEscapeCharacter = str => {
return process.platform === 'win32' ? str.replace(/\\/g, '\\\\') : str;
};

// categories
const RESOURCE = 'Resource';
const APPLICATION = 'Application';

const VAR_FOLDER = `${app.getPath('userData')}/var`;
const VAR_FOLDER = `${escapeEscapeCharacter(app.getPath('userData'))}/var`;
const DATABASE_PATH = `${VAR_FOLDER}/db.json`;
const ICON_PATH = 'app/assets/icon.png';
const PRODUCT_NAME = 'Graasp';
const TMP_FOLDER = 'tmp';
const DEFAULT_LANG = 'en';
const DEFAULT_DEVELOPER_MODE = false;
const DEFAULT_GEOLOCATION_ENABLED = false;

module.exports = {
DEFAULT_DEVELOPER_MODE,
DEFAULT_GEOLOCATION_ENABLED,
DOWNLOADABLE_MIME_TYPES,
TMP_FOLDER,
RESOURCE,
APPLICATION,
DATABASE_PATH,
VAR_FOLDER,
DEFAULT_LANG,
ICON_PATH,
PRODUCT_NAME,
escapeEscapeCharacter,
};
6 changes: 6 additions & 0 deletions public/app/config/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const ERROR_GETTING_DEVELOPER_MODE =
'There was an error getting the developer mode';
const ERROR_SETTING_DEVELOPER_MODE =
'There was an error setting the developer mode';
const ERROR_GETTING_GEOLOCATION_ENABLED =
'There was an error getting the geolocation enabled';
const ERROR_SETTING_GEOLOCATION_ENABLED =
'There was an error setting the geolocation enabled';
const ERROR_GETTING_DATABASE = 'There was an error getting the database.';
const ERROR_SETTING_DATABASE = 'There was an error updating the database.';
const SUCCESS_SYNCING_MESSAGE = 'Space was successfully synced';
Expand All @@ -42,6 +46,8 @@ const ERROR_SYNCING_MESSAGE = 'There was an error syncing the space.';
module.exports = {
ERROR_GETTING_DEVELOPER_MODE,
ERROR_SETTING_DEVELOPER_MODE,
ERROR_GETTING_GEOLOCATION_ENABLED,
ERROR_SETTING_GEOLOCATION_ENABLED,
ERROR_GETTING_LANGUAGE,
ERROR_SETTING_LANGUAGE,
ERROR_DOWNLOADING_MESSAGE,
Expand Down
76 changes: 76 additions & 0 deletions public/app/listeners/exportSpace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { app } = require('electron');
const archiver = require('archiver');
const fs = require('fs');
const logger = require('../../app/logger');

const { VAR_FOLDER } = require('../config/config');
const { ERROR_GENERAL } = require('../config/errors');
const { SPACES_COLLECTION } = require('../db');
const { EXPORTED_SPACE_CHANNEL } = require('../config/channels');

// use promisified fs
const fsPromises = fs.promises;

const exportSpace = (mainWindow, db) => async (event, { archivePath, id }) => {
try {
// get space from local database
const space = db
.get(SPACES_COLLECTION)
.find({ id })
.value();

// abort if space does not exist
if (!space) {
mainWindow.webContents.send(EXPORTED_SPACE_CHANNEL, ERROR_GENERAL);
} else {
// stringify space
const spaceString = JSON.stringify(space);
const spaceDirectory = `${VAR_FOLDER}/${id}`;
const spacePath = `${spaceDirectory}/${id}.json`;

// create manifest
const manifest = {
id,
version: app.getVersion(),
createdAt: new Date().toISOString(),
};
const manifestString = JSON.stringify(manifest);
const manifestPath = `${spaceDirectory}/manifest.json`;

// write space and manifest to json file inside space folder
await fsPromises.writeFile(spacePath, spaceString);
await fsPromises.writeFile(manifestPath, manifestString);

// prepare output file for zip
const output = fs.createWriteStream(archivePath);
output.on('close', () => {
mainWindow.webContents.send(EXPORTED_SPACE_CHANNEL);
});
output.on('end', () => {
mainWindow.webContents.send(EXPORTED_SPACE_CHANNEL, ERROR_GENERAL);
});

// archive space folder into zip
const archive = archiver('zip', {
zlib: { level: 9 },
});
archive.on('warning', err => {
if (err.code === 'ENOENT') {
logger.error(err);
}
});
archive.on('error', () => {
mainWindow.webContents.send(EXPORTED_SPACE_CHANNEL, ERROR_GENERAL);
});
archive.pipe(output);
archive.directory(spaceDirectory, false);
archive.finalize();
}
} catch (err) {
logger.error(err);
mainWindow.webContents.send(EXPORTED_SPACE_CHANNEL, ERROR_GENERAL);
}
};

module.exports = exportSpace;
20 changes: 20 additions & 0 deletions public/app/listeners/getGeolocationEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { DEFAULT_GEOLOCATION_ENABLED } = require('../config/config');
const { GET_GEOLOCATION_ENABLED_CHANNEL } = require('../config/channels');
const { ERROR_GENERAL } = require('../config/errors');
const logger = require('../logger');

const getGeolocationEnabled = (mainWindow, db) => async () => {
try {
const geolocationEnabled =
db.get('user.geolocationEnabled').value() || DEFAULT_GEOLOCATION_ENABLED;
mainWindow.webContents.send(
GET_GEOLOCATION_ENABLED_CHANNEL,
geolocationEnabled
);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(GET_GEOLOCATION_ENABLED_CHANNEL, ERROR_GENERAL);
}
};

module.exports = getGeolocationEnabled;
8 changes: 8 additions & 0 deletions public/app/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const getSpaces = require('./getSpaces');
const deleteSpace = require('./deleteSpace');
const showSyncSpacePrompt = require('./showSyncSpacePrompt');
const syncSpace = require('./syncSpace');
const exportSpace = require('./exportSpace');
const showLoadSpacePrompt = require('./showLoadSpacePrompt');
const showExportSpacePrompt = require('./showExportSpacePrompt');
const showDeleteSpacePrompt = require('./showDeleteSpacePrompt');

module.exports = {
loadSpace,
Expand All @@ -14,4 +18,8 @@ module.exports = {
showSyncSpacePrompt,
syncSpace,
deleteSpace,
exportSpace,
showLoadSpacePrompt,
showExportSpacePrompt,
showDeleteSpacePrompt,
};
21 changes: 21 additions & 0 deletions public/app/listeners/setGeolocationEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { SET_GEOLOCATION_ENABLED_CHANNEL } = require('../config/channels');
const { ERROR_GENERAL } = require('../config/errors');
const logger = require('../logger');

const setGeolocationEnabled = (mainWindow, db) => async (
event,
geolocationEnabled
) => {
try {
db.set('user.geolocationEnabled', geolocationEnabled).write();
mainWindow.webContents.send(
SET_GEOLOCATION_ENABLED_CHANNEL,
geolocationEnabled
);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(SET_GEOLOCATION_ENABLED_CHANNEL, ERROR_GENERAL);
}
};

module.exports = setGeolocationEnabled;
18 changes: 18 additions & 0 deletions public/app/listeners/showDeleteSpacePrompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { dialog } = require('electron');
const { RESPOND_DELETE_SPACE_PROMPT_CHANNEL } = require('../config/channels');

const showDeleteSpacePrompt = mainWindow => () => {
const options = {
type: 'warning',
buttons: ['Cancel', 'Delete'],
defaultId: 0,
cancelId: 0,
message: 'Are you sure you want to delete this space?',
};
dialog.showMessageBox(null, options, respond => {
mainWindow.webContents.send(RESPOND_DELETE_SPACE_PROMPT_CHANNEL, respond);
});
};

module.exports = showDeleteSpacePrompt;
15 changes: 15 additions & 0 deletions public/app/listeners/showExportSpacePrompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { dialog } = require('electron');
const { RESPOND_EXPORT_SPACE_PROMPT_CHANNEL } = require('../config/channels');

const showExportSpacePrompt = mainWindow => (event, spaceTitle) => {
const options = {
title: 'Save As',
defaultPath: `${spaceTitle}.zip`,
};
dialog.showSaveDialog(null, options, filePath => {
mainWindow.webContents.send(RESPOND_EXPORT_SPACE_PROMPT_CHANNEL, filePath);
});
};

module.exports = showExportSpacePrompt;
11 changes: 11 additions & 0 deletions public/app/listeners/showLoadSpacePrompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { dialog } = require('electron');
const { RESPOND_LOAD_SPACE_PROMPT_CHANNEL } = require('../config/channels');

const showLoadSpacePrompt = mainWindow => (event, options) => {
dialog.showOpenDialog(null, options, filePaths => {
mainWindow.webContents.send(RESPOND_LOAD_SPACE_PROMPT_CHANNEL, filePaths);
});
};

module.exports = showLoadSpacePrompt;
Loading