Skip to content

Commit

Permalink
Merge pull request #138 from TankNee/rebuild/fix
Browse files Browse the repository at this point in the history
2.1.6 Mindmap, Directory sort, bug fix and so forth
  • Loading branch information
TankNee authored Aug 6, 2021
2 parents fc6ec6b + bc9ff76 commit 57e0877
Show file tree
Hide file tree
Showing 60 changed files with 1,337 additions and 389 deletions.
580 changes: 568 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cn.memocast.app",
"version": "2.1.5",
"version": "2.1.6",
"description": "An Awesome WizNote Desktop Application",
"productName": "Memocast",
"author": "tanknee <[email protected]>",
Expand Down Expand Up @@ -47,6 +47,8 @@
"lodash": "^4.17.21",
"markdown-it": "^8.4.2",
"markdown-it-pangu": "^1.0.2",
"markmap-lib": "^0.11.6",
"markmap-view": "^0.2.6",
"md5": "^2.3.0",
"mermaid": "^8.4.8",
"monaco-editor": "^0.25.2",
Expand Down
1 change: 1 addition & 0 deletions share/channels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default {
exportMarkdownFile: 'export-markdown-file',
exportPng: 'export-png',
exportFile: 'export-file',
exportMarkdownFiles: 'export-markdown-files',
importImage: 'import-image',
uploadImages: 'upload-images',
Expand Down
34 changes: 33 additions & 1 deletion src-electron/main-process/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ export default {
})
}).catch(err => throw err)
}).catch(err => throw err)

handleApi('export-png', (event, { content, title }) => {
return dialog.showSaveDialog({
title: i18n.t('export'),
defaultPath: path.join(app.getPath('documents'), `${title}`),
defaultPath: path.join(app.getPath('pictures'), `${title}`),
filters: [
{
name: 'Portable Network Graphics',
Expand Down Expand Up @@ -111,6 +112,37 @@ export default {
}).catch(err => throw err)
}).catch(err => throw err)

handleApi('export-file', (event, { content, fileName, fileType }) => {
console.log({ fileName, fileType })
return dialog.showSaveDialog({
title: i18n.t('export'),
defaultPath: path.join(app.getPath('documents'), `${fileName}`),
filters: [
{
name: 'Export File',
extensions: [fileType]
}
]
}).then((result) => {
if (result.canceled) return
fs.writeFile(result.filePath, content).then(() => {
sendNotification({
msg: 'ExportSuccessfully',
type: 'positive',
icon: 'check',
filePath: result.filePath
}, event).catch(err => throw err)
})
.catch(err => {
sendNotification({
msg: err.msg,
type: 'negative',
icon: 'delete'
}, event).catch(err => throw err)
})
}).catch(err => throw err)
}).catch(err => throw err)

/**
* batch export notes
*/
Expand Down
7 changes: 4 additions & 3 deletions src-electron/main-process/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { openNewGitHubIssue, debugInfo, enforceMacOSAppLocation } from 'electron
import KeyBindings from './keyboard/shortcut'
import { registerMemocastProtocol } from './utlis/resource-loader'
import Store from 'electron-store'
import i18n from './i18n'

const ClientStorage = new Store({
name: 'ClientFileStorage'
Expand Down Expand Up @@ -132,10 +133,10 @@ function createWindow () {
}
dialog.showMessageBox(mainWindow, {
type: 'question',
title: 'Open link url in your default browser!',
message: 'Open link url in your default browser!',
title: i18n.t('openLinkHint'),
message: i18n.t('openLinkHint'),
detail: linkUrl,
buttons: ['Confirm', 'Cancel']
buttons: [i18n.t('confirm'), i18n.t('cancel')]
}).then((res) => {
if (!res.response) {
shell.openExternal(linkUrl).then()
Expand Down
6 changes: 5 additions & 1 deletion src-electron/main-process/i18n/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export default class I18n {
availableLocales,
messages
} = options
this._locale = locale
if (!availableLocales.includes(locale)) {
this._locale = availableLocales[0]
} else {
this._locale = locale
}
this._availableLocales = availableLocales
this._messages = messages
}
Expand Down
5 changes: 5 additions & 0 deletions src-electron/main-process/i18n/src/en-us/electron-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
confirm: 'Confirm',
cancel: 'Cancel',
openLinkHint: 'Open link url in your default browser!'
}
4 changes: 3 additions & 1 deletion src-electron/main-process/i18n/src/en-us/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import menu from './menu'
import api from './api'
import electronMain from './electron-main'
export default {
...menu,
...api
...api,
...electronMain
}
5 changes: 5 additions & 0 deletions src-electron/main-process/i18n/src/zh-cn/electron-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
confirm: '确认',
cancel: '取消',
openLinkHint: '使用浏览器打开链接!'
}
4 changes: 3 additions & 1 deletion src-electron/main-process/i18n/src/zh-cn/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import menu from './menu'
import api from './api'
import electronMain from './electron-main'
export default {
...menu,
...api
...api,
...electronMain
}
17 changes: 9 additions & 8 deletions src/ApiHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Notify } from 'quasar'
import bus from 'components/bus'
import events from 'src/constants/events'
import { i18n } from '../src/boot/i18n'
import debugLogger from './utils/debugLogger'

/**
* 在本地注册对应的事件句柄,用于解决对应的事件
Expand Down Expand Up @@ -33,7 +34,7 @@ async function handleApi (channel, api) {

export default {
RegisterApiHandler () {
console.log('[API Handler] Render Process registers handler successfully!')
debugLogger.Info('[API Handler] Render Process registers handler successfully!')

handleApi('show-notification', (event, payload) => {
const { msg, type = 'primary', icon = 'check', filePath } = payload
Expand Down Expand Up @@ -78,7 +79,7 @@ export default {
}).catch(err => throw err)

handleApi('editor-view-action', (event, { type }) => {
console.log(type)
debugLogger.Log(type)
bus.$emit(events.VIEW_SHORTCUT_CALL[type], type)
}).catch(err => throw err)

Expand All @@ -87,32 +88,32 @@ export default {
}).catch(err => throw err)

handleApi('updater-update-available', (event, info) => {
console.log(info)
debugLogger.Log(info)
bus.$emit(events.UPDATE_EVENTS.updateAvailable, info)
}).catch(err => throw err)

handleApi('updater-update-not-available', (event, info) => {
console.log(info)
debugLogger.Log(info)
bus.$emit(events.UPDATE_EVENTS.updateNotAvailable, info)
}).catch(err => throw err)

handleApi('updater-update-downloading', (event, progress) => {
console.log(progress)
debugLogger.Log(progress)
bus.$emit(events.UPDATE_EVENTS.updateDownloading, progress)
}).catch(err => throw err)

handleApi('updater-update-downloaded', (event, info) => {
console.log(info)
debugLogger.Log(info)
bus.$emit(events.UPDATE_EVENTS.updateDownloaded)
}).catch(err => throw err)

handleApi('updater-update-error', (event, error) => {
console.log(error)
debugLogger.Log(error)
bus.$emit(events.UPDATE_EVENTS.updateError, error)
}).catch(err => throw err)
},
UnregisterApiHandler () {
console.log('[API Handler] Render Process unregisters handler successfully!')
debugLogger.Info('[API Handler] Render Process unregisters handler successfully!')
ipcRenderer.removeAllListeners('show-notification')
}
}
5 changes: 5 additions & 0 deletions src/ApiInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ async function exportPng (note) {
return ipcRenderer.invoke(channels.exportPng, note)
}

async function exportFile (file) {
return ipcRenderer.invoke(channels.exportFile, file)
}

/**
* 批量导出markdown文件
* @param notes 笔记列表
Expand Down Expand Up @@ -85,6 +89,7 @@ async function saveUploadedImage (buffer, kbGuid, docGuid, name) {
export {
exportMarkdownFile,
exportPng,
exportFile,
exportMarkdownFiles,
importImage,
uploadImages,
Expand Down
2 changes: 2 additions & 0 deletions src/ErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Notify } from 'quasar'
import bus from 'components/bus'
import events from 'src/constants/events'
import { i18n } from 'boot/i18n'
import debugLogger from './utils/debugLogger'

function registerRequestErrorHandler () {
bus.$on(events.REQUEST_ERROR, (error) => {
Expand All @@ -17,6 +18,7 @@ function registerRequestErrorHandler () {

export default {
RegisterErrorHandler () {
debugLogger.Info('[API Handler] Render Process registers error handler successfully!')
registerRequestErrorHandler()
}
}
4 changes: 3 additions & 1 deletion src/ScheduleHandler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import schedule from 'node-schedule'
import api from 'src/utils/api'
import debugLogger from './utils/debugLogger'
import ServerFileStorage from './utils/storage/ServerFileStorage'
const refreshWizToken = (app) => {
schedule.scheduleJob('30 * * * * *', async () => {
schedule.scheduleJob('30 */12 * * * *', async () => {
if (!ServerFileStorage.isKeyExistsInLocalStorage('token') || !app.isLogin) return
try {
await api.AccountServerApi.keepTokenAlive()
Expand All @@ -14,6 +15,7 @@ const refreshWizToken = (app) => {

export default {
RegisterScheduleJobs (app) {
debugLogger.Info('[API Handler] Render Process registers schedule handler successfully!')
refreshWizToken(app)
}
}
49 changes: 1 addition & 48 deletions src/boot/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,6 @@ axios.defaults.timeout = 50000 // 响应时间
const baseUrl = 'https://ac.wiz.cn'
axios.defaults.baseURL = baseUrl

/**
* execute network request
* @param {'GET','POST','DELETE','PUT'} method
* @param {string} url
* @param {Object} body
* @param token
* @param {Object} extraConfig
* @param {boolean} returnFullResult
* @param {boolean} ignoreStatusCode
* @returns {Promise<*>}
*/
// export async function execRequest (method, url, body = {}, token = null, extraConfig = {}, returnFullResult = false, ignoreStatusCode = false) {
// const config = {
// url,
// method,
// data: body
// }
//
// if (token) {
// config.headers = {
// 'X-Wiz-Token': token
// }
// } else if (ServerFileStorage.isKeyExistsInLocalStorage('token')) {
// config.headers = {
// 'X-Wiz-Token': ServerFileStorage.getValueFromLocalStorage('token')
// }
// }
//
// Object.assign(config, extraConfig)
//
// const res = await axios(config)
// const data = res.data
//
// if (data.returnCode !== 200 && data.code !== 200 && !ignoreStatusCode) {
// const { returnMessage, returnCode, externCode } = data
// bus.$emit(events.REQUEST_ERROR, new NeetoError(returnMessage, returnCode, externCode))
// const err = new Error(returnMessage)
// err.code = returnCode
// err.externCode = data.externCode
// throw err
// }
//
// return typeof data === 'object' && ('result' in data || !returnFullResult)
// ? data.result
// : data
// }

/**
* execute network request
* @param {'GET','POST','DELETE','PUT'} method
Expand Down Expand Up @@ -98,7 +51,7 @@ export async function execRequest (method, url, body = {}, token = null, extraCo
throw err
}

return typeof data === 'object' && ('result' in data || !returnFullResult)
return typeof data === 'object' && ('result' in data && !returnFullResult)
? data.result
: data
}
Expand Down
Loading

0 comments on commit 57e0877

Please sign in to comment.