Skip to content

Commit

Permalink
chore: merge pull request #20 from antonreshetov/dev
Browse files Browse the repository at this point in the history
chore: merge dev
  • Loading branch information
antonreshetov authored Jan 17, 2020
2 parents 5d6c92a + 4e3cf88 commit 8265c19
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "masscode",
"version": "0.8.0",
"author": "Anton Reshetov <reshetov.art@gmail.com>",
"description": "Snippets app",
"description": "A free and open source code snippets manager for developers",
"license": "AGPL-3.0",
"main": "./dist/electron/main.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
store.app.set('bounds', mainWindow.getBounds())
})

app.on('activate', () => {
Expand Down
81 changes: 72 additions & 9 deletions src/main/lib/main-menu.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { app, shell } from 'electron'
import { app, shell, dialog, BrowserWindow } from 'electron'
import os from 'os'
const { version, author } = require('../../../package.json')

if (process.platform !== 'win32') {
const isMac = process.platform === 'darwin'
const year = new Date().getFullYear()

if (isMac) {
app.setAboutPanelOptions({
applicationName: 'massCode',
applicationVersion: version,
version,
copyright: author
copyright: `${author}\n https://masscode.io \n©2019-${year}`
})
}

export default mainWindow => {
const massCode = {
label: 'massCode',
submenu: [
function creatMassCodeMenu (mainWindow) {
if (isMac) {
return [
{
label: 'About massCode',
selector: 'orderFrontStandardAboutPanel:'
Expand All @@ -23,7 +26,7 @@ export default mainWindow => {
},
{
label: 'Preferences',
accelerator: 'Command+,',
accelerator: 'CommandOrControl+,',
click () {
mainWindow.webContents.send('menu:preferences')
}
Expand Down Expand Up @@ -54,6 +57,31 @@ export default mainWindow => {
accelerator: 'CommandOrControl+Q'
}
]
} else {
return [
{
label: 'Preferences',
accelerator: 'CommandOrControl+,',
click () {
mainWindow.webContents.send('menu:preferences')
}
},
{
type: 'separator'
},
{
label: 'Quit massCode',
role: 'quit',
accelerator: 'CommandOrControl+Q'
}
]
}
}

export default mainWindow => {
const massCode = {
label: 'massCode',
submenu: creatMassCodeMenu(mainWindow)
}

const file = {
Expand Down Expand Up @@ -173,10 +201,45 @@ export default mainWindow => {
role: 'help',
submenu: [
{
label: 'GitHub Repo',
label: 'Website',
click () {
shell.openExternal('https://masscode.io')
}
},
{
label: 'GitHub',
click () {
shell.openExternal('https://github.com/antonreshetov/massCode')
}
},
{
label: 'Donate',
click () {
shell.openExternal('https://masscode.io/donate')
}
},
{
type: 'separator'
},
{
label: 'About',
click () {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: 'massCode',
message: 'massCode',
type: 'info',
detail: `
Version: ${version}
Electron: ${process.versions.electron}
Chrome: ${process.versions.chrome}
Node.js: ${process.versions.node}
V8: ${process.versions.v8}
OS: ${os.type()} ${os.arch()} ${os.release()}
©2019-${year} Anton Reshetov <reshetov-art@gmail.com>
`
})
}
}
]
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/store/module/preferences.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import Store from 'electron-store'
import { homedir } from 'os'
import { homedir, platform } from 'os'

const isWin = platform() === 'win32'

const defaultPath = isWin ? homedir() + '\\massCode' : homedir() + '/massCode'

const preferences = new Store({
name: 'preferences',
cwd: 'massCode',

schema: {
storagePath: {
default: homedir() + '/massCode'
default: defaultPath
},
theme: {
default: 'dark'
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from 'fs-extra'
class DataStore {
constructor () {
this._defaultPath = remote.app.getPath('home') + '/massCode'
this._storedPath = electronStore.app.get('storagePath')
this._storedPath = electronStore.preferences.get('storagePath')
this._path = this._storedPath || this._defaultPath

this.init()
Expand All @@ -29,20 +29,20 @@ class DataStore {
}

updatePath () {
this._storedPath = electronStore.app.get('storagePath')
this._storedPath = electronStore.preferences.get('storagePath')
this._path = this._storedPath || this._defaultPath
this.init()
}

import (from) {
electronStore.set('storagePath', from)
electronStore.preferences.set('storagePath', from)
this.updatePath()
}

async move (to) {
try {
await fs.move(this._path, to, { overwrite: true })
electronStore.app.set('storagePath', to)
electronStore.preferences.set('storagePath', to)
this.updatePath()
} catch (err) {
console.error(err)
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/views/Preferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,21 @@ export default {
properties: ['openDirectory', 'createDirectory']
})
if (dir) {
db.move(dir[0])
const path = dir[0]
db.move(path)
this.updateData()
this.$store.commit('app/SET_STORAGE_PATH', path)
}
},
async onOpenStorage () {
const dir = dialog.showOpenDialogSync({
properties: ['openDirectory']
})
if (dir) {
db.import(dir[0])
const path = dir[0]
db.import(path)
this.updateData()
this.$store.commit('app/SET_STORAGE_PATH', path)
}
},
async updateData () {
Expand Down

0 comments on commit 8265c19

Please sign in to comment.