Skip to content

Commit

Permalink
Merge pull request #12 from Jarvay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Jarvay authored May 8, 2019
2 parents ca6db96 + c838563 commit f24e886
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 259 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "desktop48",
"version": "1.0.0",
"version": "1.0.1",
"author": "jarvay <[email protected]>",
"description": "",
"license": null,
Expand All @@ -19,12 +19,13 @@
"build": {
"productName": "Desktop48",
"appId": "cn.jarvay.desktop48",
"asar": false,
"asar": true,
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
"dist/electron/**/*",
"!**/@ffmpeg-installer/*"
],
"dmg": {
"contents": [
Expand Down Expand Up @@ -54,7 +55,7 @@
"oneClick": false,
"allowToChangeInstallationDirectory": true,
"perMachine": true,
"createDesktopShortcut": false
"createDesktopShortcut": true
}
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/assets/js/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Apis {
static syncInfo() {
return new Promise((resolve, reject) => {
Apis.request(ApiUrls.UPDATE_INFO_URL).then(content => {
Database.db().set('members', content.starInfo).write();
Database.db().set('teams', content.teamInfo).write();
Database.db().set('groups', content.groupInfo).write();
Database.db.set('members', content.starInfo).write();
Database.db.set('teams', content.teamInfo).write();
Database.db.set('groups', content.groupInfo).write();
resolve();
}).catch(error => {
reject(error);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/assets/js/chatroom-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ChatRoomTools {
* @returns {Promise<any>}
*/
static chatroom(options) {
if (typeof Database.getAccid() !== "undefined") {
if (Database.getAccid() != null) {
Dev.info('user account login im');
return new Promise((resolve, reject) => {
const chatroom = new Chatroom({
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/assets/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ JUJU_MSG_TYPE.LIVE_PUSH = 'LIVEPUSH';
JUJU_MSG_TYPE.FLIP_CARD = 'FLIPCARD';
JUJU_MSG_TYPE.AUDIO = 'AUDIO';
JUJU_MSG_TYPE.VIDEO = 'VIDEO';
JUJU_MSG_TYPE.PRESENT_TEXT = 'PRESENT_TEXT';
Constants.JUJU_MSG_TYPE = JUJU_MSG_TYPE;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ Constants.REVIEW_SCREEN = REVIEW_SCREEN;
const EVENT = {};
EVENT.LOGIN = 'LOGIN';
EVENT.USER_INFO = 'USER_INFO';
EVENT.LOGOUT = 'LOGOUT';
EVENT.LIVE_OPEN = 'LIVE_OPEN';
Constants.EVENT = EVENT;

Constants.UNKNOWN_USER = {
Expand Down
131 changes: 62 additions & 69 deletions src/renderer/assets/js/database.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,24 @@
import Constants from "./constants";
import Dev from "./dev";

class Database {
static db() {
if (Database._db == null) {
const low = require('lowdb');
const LocalStorage = require('lowdb/adapters/LocalStorage')
const adapter = new LocalStorage();

Database._db = low(adapter);
}
return Database._db;
}

static membersDB() {
if (Database._membersDB == null) {
Database._membersDB = Database.db().get('members').cloneDeep();
}
return Database._membersDB;
}

static teamsDB() {
if (Database._teamsDB == null) {
Database._teamsDB = Database.db().get('teams').cloneDeep();
}
return Database._teamsDB;
}

static groupsDB() {
if (Database._groupsDB == null) {
Database._groupsDB = Database.db().get('groups').cloneDeep();
}
return Database._groupsDB;
}

static member(memberId) {
memberId = parseInt(memberId);
let member = Database.membersDB().find({userId: memberId}).value();
let member = Database.membersDB.find({userId: memberId}).value();
if (typeof member === "undefined") {
member = Constants.UNKNOWN_USER;
member.team = {
teamName: 'unknown',
teamColor: 'ccc'
};
} else {
member.team = Database.teamsDB().find({teamId: member.teamId}).value();
member.team = Database.teamsDB.find({teamId: member.teamId}).value();
}
return member;
}

static team(teamId) {
const team = Database.teamsDB().find({teamId: teamId}).value();
const members = Database.membersDB().filter({teamId: teamId}).value();
const team = Database.teamsDB.find({teamId: teamId}).value();
const members = Database.membersDB.filter({teamId: teamId}).value();

const tmpMembers = [];
for (let i = 0; i < members.length; i++) {
Expand All @@ -63,9 +30,9 @@ class Database {
}

static group(groupId) {
const group = Database.groupsDB().find({groupId: groupId}).value();
const group = Database.groupsDB.find({groupId: groupId}).value();

const teams = Database.teamsDB().filter({groupId: groupId}).value();
const teams = Database.teamsDB.filter({groupId: groupId}).value();

const tmpTeams = [];
for (let i = 0; i < teams.length; i++) {
Expand All @@ -80,7 +47,7 @@ class Database {
* @returns {Array}
*/
static groups() {
const groups = Database.groupsDB().value();
const groups = Database.groupsDB.value();
const result = [];
for (let i = 0; i < groups.length; i++) {
result.push(Database.group(groups[i].groupId));
Expand All @@ -89,91 +56,117 @@ class Database {
}

static setLoginUserInfo(userInfo) {
Database._db.set('loginUserInfo', userInfo).write();
Database.db.set('loginUserInfo', userInfo).write();
}

static getLoginUserInfo() {
return Database._db.get('loginUserInfo').cloneDeep().value();
return Database.get('loginUserInfo', null);
}

static removeLoginUserInfo() {
Database._db.unset('loginUserInfo').write();
Database.db.unset('loginUserInfo').write();
}

static getToken() {
const token = Database._db.get('token').value();
if (typeof token === "undefined" || token == null){
return '';
}
return token;
return Database.get('token', '');
}

static setToken(token) {
Database._db.set('token', token).write();
Database.db.set('token', token).write();
}

static removeToken() {
Database._db.unset('token').write();
Database.db.unset('token').write();
}

static isLogin() {
return Database._db.has('token').value();
return Database.db.has('token').value();
}

static setAccid(accid) {
Database._db.set('accid', accid).write();
Database.db.set('accid', accid).write();
}

static getAccid() {
return Database._db.get('accid').cloneDeep().value();
return Database.get('accid', null);
}

static setIMPwd(accid) {
Database._db.set('imPwd', accid).write();
Database.db.set('imPwd', accid).write();
}

static getIMPwd() {
return Database._db.get('imPwd').cloneDeep().value();
return Database.get('imPwd', '');
}

static incrementBadgeCount(ownerId) {
if (!Database._db.has('badgeCount').value()) {
Database._db.set('badgeCount', []).write();
}
if (typeof Database._db.get('badgeCount').find({ownerId: ownerId}).value() === "undefined") {
Database._db.get('badgeCount').push({
if (typeof Database.db.get('badgeCount').find({ownerId: ownerId}).value() === "undefined") {
Database.db.get('badgeCount').push({
ownerId: ownerId,
count: 1
}).write();
} else {
Database._db.get('badgeCount').find({ownerId: ownerId}).update('count', n => n + 1).write();
Database.db.get('badgeCount').find({ownerId: ownerId}).update('count', n => n + 1).write();
}
}

static clearBadgeCount(ownerId) {
Database._db.get('badgeCount').remove({ownerId: ownerId}).write();
Database.db.get('badgeCount').remove({ownerId: ownerId}).write();
}

static getBadgeCount(ownerId) {
const item = Database._db.get('badgeCount').find({ownerId: ownerId}).value();
const item = Database.db.get('badgeCount').find({ownerId: ownerId}).value();
if (typeof item === "undefined") {
return 0;
}
return item.count;
}

static setLastCheckInTime(lastCheckInTime) {
Database._db.set('lastCheckInTime', lastCheckInTime).write();
Database.db.set('lastCheckInTime', lastCheckInTime).write();
}

static getLastCheckInTime() {
Database._db.get('lastCheckInTime').cloneDeep().value();
return Database.get('lastCheckInTime', null);
}

static setConfig(key, value) {
Database.db.set(`config.${key}`, value).write();
}

static getConfig(key, defaultValue) {
return Database.get(`config.${key}`, defaultValue);
}

static init() {
const low = require('lowdb');
const LocalStorage = require('lowdb/adapters/LocalStorage')
const adapter = new LocalStorage();

Database.db = low(adapter);

Database.membersDB = Database.db.get('members').cloneDeep();
Database.teamsDB = Database.db.get('teams').cloneDeep();
Database.groupsDB = Database.db.get('groups').cloneDeep();

if (!Database.db.has('config')) {
Database.db.set('config', {}).write();
}

if (!Database.db.has('badgeCount').value()) {
Database.db.set('badgeCount', []).write();
}
}

static get(key, defaultValue) {
const result = Database.db.get(`${key}`).cloneDeep().value();
if (typeof result === "undefined" || result == null) {
return defaultValue;
}
return result;
}
}

Database._membersDB = null;
Database._groupsDB = null;
Database._teamsDB = null;
Database._db = null;
Database.init();

export default Database;
28 changes: 17 additions & 11 deletions src/renderer/assets/js/tools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ffmpeg from 'fluent-ffmpeg';

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path.replace('app.asar', 'app.asar.unpacked');
ffmpeg.setFfmpegPath(ffmpegPath);

Date.prototype.format = function (fmt) {
Expand Down Expand Up @@ -68,14 +68,6 @@ class Tools {
return localStorage.getItem('senderName');
}

static setVolume(volume) {
localStorage.setItem('volume', volume);
}

static getVolume() {
return localStorage.getItem('volume') || 0.8;
}

static lyricsParse(lyrics) {
const barrages = [];
const lines = lyrics.split('\n');
Expand Down Expand Up @@ -123,8 +115,22 @@ class Tools {
static checkForUpdate() {
return new Promise((resolve, reject) => {
axios.get('https://raw.githubusercontent.com/Jarvay/desktop48/master/package.json').then(response => {
const latestVersion = response.data.version;
const hasUpdate = require('../../../../package').version != latestVersion;
const remoteVersion = response.data.version;
const localVersion = require('../../../../package').version;
const localVerArray = localVersion.split('.');
const remoteVerArray = remoteVersion.split('.');
let hasUpdate = false;
if (remoteVerArray[0] > localVerArray[0]){
hasUpdate = true;
} else if (remoteVerArray[0] == localVerArray[0]){
if (remoteVerArray[1] > localVerArray[1]) {
hasUpdate = true;
}else if (remoteVerArray[1] == localVerArray[1]){
if (remoteVerArray[2] > localVerArray[2]){
hasUpdate = true;
}
}
}
if (hasUpdate) {
resolve();
} else {
Expand Down
Loading

0 comments on commit f24e886

Please sign in to comment.