Skip to content

Commit a3bbdb6

Browse files
authored
Merge pull request #39 from Syn-Tax/refactoring
Refactoring
2 parents f59fbbb + 82d67aa commit a3bbdb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1066
-1145
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Memento",
3-
"version": "1.6.4-dev",
3+
"version": "1.6.5",
44
"author": {
55
"name": "Oscar Morris",
66
"email": "twocap06@gmail.com"
@@ -23,6 +23,7 @@
2323
"decompress-zip": "^0.3.3",
2424
"electron-debug": "^3.2.0",
2525
"electron-is-dev": "^2.0.0",
26+
"electron-window-state": "^5.0.3",
2627
"fs-extra": "^10.0.0",
2728
"jimp": "^0.16.1",
2829
"query-string": "^7.0.0",

public/electron.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11

22
// Modules to control application life and create native browser window
3-
const {app, BrowserWindow, nativeTheme, protocol} = require('electron')
3+
const { app, BrowserWindow, nativeTheme, protocol } = require('electron')
44
const path = require('path')
5-
const isDev = require('electron-is-dev');
5+
const isDev = require('electron-is-dev')
66
const debug = require('electron-debug')
7+
const windowStateKeeper = require('electron-window-state')
78

89
const dataFolder = path.join(app.getPath('userData'), "./Data")
910

10-
debug({isEnabled: true})
11+
debug()
1112

12-
function createWindow () {
13+
function createWindow(windowState) {
14+
// force light theme since no dark theme has been implemented
1315
nativeTheme.themeSource = 'light'
1416
// Create the browser window.
1517
const mainWindow = new BrowserWindow({
16-
width: 800,
17-
height: 600,
18+
width: windowState.width,
19+
height: windowState.height,
20+
x: windowState.x,
21+
y: windowState.y,
1822
webPreferences: {
1923
preload: path.join(__dirname, 'preload.js'),
2024
nodeIntegration: true,
@@ -23,11 +27,13 @@ function createWindow () {
2327
preload: path.join(__dirname, "preload.js")
2428
})
2529

30+
// remove the menubar from the window
2631
mainWindow.removeMenu()
2732

2833
// and load the index.html of the app.
2934
mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`)
3035

36+
// if running in dev mode, open the developer tools automatically
3137
if (isDev) {
3238
mainWindow.webContents.openDevTools()
3339
}
@@ -38,14 +44,27 @@ function createWindow () {
3844
// initialization and is ready to create browser windows.
3945
// Some APIs can only be used after this event occurs.
4046
app.whenReady().then(() => {
41-
createWindow()
47+
// allow the window to remember where it was placed and what size it was
48+
let win
49+
let windowState = windowStateKeeper({
50+
defaultWidth: 800,
51+
defaultHeight: 600
52+
})
53+
54+
// create the window
55+
createWindow(windowState)
56+
57+
// allow the window state to be managed
58+
windowState.manage(win)
4259

60+
// register the custom file protocol for getting images dynamically
4361
protocol.registerFileProtocol('imgid', (request, callback) => {
4462
const url = request.url.substr(8)
4563
console.log(url)
46-
callback({path: path.join(dataFolder, ".images", url)})
64+
callback({ path: path.join(dataFolder, ".images", url) })
4765
})
4866

67+
// boilerplate for MacOS
4968
app.on('activate', function () {
5069
// On macOS it's common to re-create a window in the app when the
5170
// dock icon is clicked and there are no other windows open.
@@ -58,7 +77,4 @@ app.whenReady().then(() => {
5877
// explicitly with Cmd + Q.
5978
app.on('window-all-closed', function () {
6079
if (process.platform !== 'darwin') app.quit()
61-
})
62-
63-
// In this file you can include the rest of your app's specific main process
64-
// code. You can also put them in separate files and require them here.
80+
})

public/logo192.png

-5.22 KB
Binary file not shown.

public/logo512.png

-9.44 KB
Binary file not shown.

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Go to the releases page - https://github.com/Syn-Tax/memento/releases - and down
1818

1919
# Changelog
2020

21-
## v1.6.3-dev
21+
## v1.6.5
2222

2323
Features:
2424

src/App.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import Home from './Views/Home';
33
import Folder from './Views/Folder';
4-
import CreateFolder from './Views/CreateFolder';
54
import CreateList from './Views/CreateList';
65
import List from './Views/List';
76
import Test from './Views/Test';
@@ -17,40 +16,34 @@ const appPath = electron.remote.app.getPath('userData');
1716

1817
const dataFolder = path.join(appPath, "./Data/")
1918

20-
console.log(appPath)
21-
if (!fs.existsSync(dataFolder)){
19+
// create the data directory if it doesn't exist
20+
if (!fs.existsSync(dataFolder)) {
2221
fs.mkdirSync(dataFolder);
2322
}
2423

24+
// create the images directory if it doesn't exist
2525
if (!fs.existsSync(path.join(dataFolder, "./.images"))) {
2626
fs.mkdirSync(path.join(dataFolder, "./.images"))
2727
}
2828

29+
// get the files in the data directory
2930
let files = getFiles(dataFolder)
3031

32+
/**
33+
* @function App - the base component
34+
* @return {JSX} - The JSX for the current page
35+
*/
3136
function App() {
37+
// state for storing the files in object form
3238
const [gridItems, setGridItems] = React.useState(files)
3339

34-
const recreateFiles = () => {
40+
// if a file has been changed, get the files again
41+
fs.watch(dataFolder, { recursive: true }, (event, file) => {
3542
files = getFiles(dataFolder)
3643
setGridItems(files)
37-
}
38-
39-
fs.watch(dataFolder, {recursive: true}, (event, file) => {
40-
files = getFiles(dataFolder)
41-
setGridItems(files)
42-
})
43-
44-
/*
45-
let watcher = chokidar.watch(dataFolder)
46-
47-
watcher.on('all', (evt, name) => {
48-
recreateFiles()
4944
})
5045

51-
console.log(watcher.getWatched())
52-
*/
53-
46+
// return the current page using react-router
5447
return (
5548
<div className="App">
5649
<Router>
@@ -67,9 +60,6 @@ function App() {
6760
<Route path="/test/:pathStr">
6861
<Test />
6962
</Route>
70-
<Route path="/create-folder/:pathStr">
71-
<CreateFolder gridItems={gridItems} />
72-
</Route>
7363
<Route path="/create-list/:pathStr">
7464
<CreateList gridItems={gridItems} />
7565
</Route>

src/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Components/BackButton.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Fab } from '@material-ui/core';
22
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
3-
3+
/**
4+
* @function BackButton - The component for the button to navigate to the previous page.
5+
* @return {JSX} - The JSX for the component.
6+
*/
47
function BackButton() {
58
return (
69
<Fab variant="extended" size="small" style={{ backgroundColor: "white", top: "2%", left: "5%", position: "absolute" }}>

0 commit comments

Comments
 (0)