Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiajingren committed Nov 13, 2020
1 parent 0cee88e commit 2094453
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 26 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"name": "xhznl-todo-list",
"version": "0.1.0",
"private": true,
"author": "xhznl",
"description": "a todo list application",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down
Binary file added public/logo.icns
Binary file not shown.
Binary file added public/logo.ico
Binary file not shown.
Binary file added public/tary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 35 additions & 9 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@ import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
//import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
const isDevelopment = process.env.NODE_ENV !== "production";

import '@/utils/backgroundExtra'
import { initExtra, createTray } from "@/utils/backgroundExtra";

import pkg from "../package.json";

let win;

if (app.requestSingleInstanceLock()) {
app.on("second-instance", (event, commandLine, workingDirectory) => {
if (win) {
setPosition();
}
});
} else {
app.quit();
}

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
]);

async function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
win = new BrowserWindow({
width: 320,
height: 290,
type: "toolbar",
Expand All @@ -26,7 +38,7 @@ async function createWindow() {
minimizable: false,
maximizable: false,
skipTaskbar: true,
closable: false,
//closable: false,
//show: false,
transparent: true,
alwaysOnTop: true,
Expand All @@ -38,10 +50,7 @@ async function createWindow() {
},
});

const size = screen.getPrimaryDisplay().workAreaSize;
const winSize = win.getSize();

win.setPosition(size.width - winSize[0], 0);
setPosition();

if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
Expand All @@ -52,6 +61,10 @@ async function createWindow() {
// Load the index.html when not in development
win.loadURL("app://./index.html");
}

win.on("closed", () => {
win = null;
});
}

// Quit when all windows are closed.
Expand All @@ -66,7 +79,7 @@ app.on("window-all-closed", () => {
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow();
if (BrowserWindow.getAllWindows().length === 0) init();
});

// This method will be called when Electron has finished
Expand All @@ -81,9 +94,16 @@ app.on("ready", async () => {
// console.error("Vue Devtools failed to install:", e.toString());
// }
// }
createWindow();

init();
});

function init() {
createWindow();
initExtra();
createTray(setPosition);
}

// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === "win32") {
Expand All @@ -98,3 +118,9 @@ if (isDevelopment) {
});
}
}

function setPosition() {
const size = screen.getPrimaryDisplay().workAreaSize;
const winSize = win.getSize();
win.setPosition(size.width - winSize[0] - 30, 30);
}
37 changes: 34 additions & 3 deletions src/utils/backgroundExtra.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { app, ipcMain } from "electron";
import { app, ipcMain, Tray, Menu } from "electron";
import DB from "./db";
import path from "path";

const storePath = getDataPath();
DB.initDB(storePath);
import pkg from "../../package.json";

let tray;

export function getDataPath() {
return app.getPath("userData");
Expand All @@ -11,3 +13,32 @@ export function getDataPath() {
ipcMain.handle("getDataPath", (event) => {
return getDataPath();
});

export function initExtra() {
const storePath = getDataPath();
DB.initDB(storePath);
}

export function createTray(setPosition) {
tray = new Tray(path.join(__static, "./tary.png"));

const contextMenu = Menu.buildFromTemplate([
{
label: "联系作者",
click: () => {},
},
{
label: "退出",
click: () => {
app.quit();
},
},
]);
tray.setContextMenu(contextMenu);

tray.setToolTip(pkg.name);

tray.on("click", (event, bounds, position) => {
setPosition();
});
}
4 changes: 2 additions & 2 deletions src/views/Done.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default {
done_datetime: getNowDateTime(),
todo_date: getNowDate(),
todo_datetime: getNowDateTime(),
content: "快乐",
id: "9e3b08c5-c870-4aeb-a2a5-8a039db21ace",
content: "告诉自己:All is well :)",
id: "37e4c3de-6d02-5a40-b4db-069f115c9be0",
},
];
return;
Expand Down
12 changes: 11 additions & 1 deletion src/views/Todo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ export default {
{
todo_date: getNowDate(),
todo_datetime: getNowDateTime(),
content: "“愿你快乐每一天”:)",
content: "“长按”Todo,可进行拖动排序",
},
{
todo_date: getNowDate(),
todo_datetime: getNowDateTime(),
content: "【重要】给爱的人一个温暖的拥抱",
},
{
todo_date: getNowDate(),
todo_datetime: getNowDateTime(),
content: "【重要】给自己一个鼓励的拥抱",
},
];
return;
Expand Down
22 changes: 11 additions & 11 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ module.exports = {
allowToChangeInstallationDirectory: true,
shortcutName: "xhznl-todo-list",
},
publish: [
{
provider: "generic",
url: "",
},
],
releaseInfo: {
releaseName: "",
releaseNotes: "新版本",
releaseDate: "2020/11/10",
},
// publish: [
// {
// provider: "generic",
// url: "",
// },
// ],
// releaseInfo: {
// releaseName: "",
// releaseNotes: "新版本",
// releaseDate: "2020/11/10",
// },
},
nodeIntegration: true,
},
Expand Down

0 comments on commit 2094453

Please sign in to comment.