mirror of
https://github.com/agam778/MS-365-Electron.git
synced 2026-02-17 09:02:10 +00:00
refactor: convert to ESM syntax
This commit is contained in:
74
app/main.js
74
app/main.js
@@ -1,26 +1,34 @@
|
||||
const { app, Menu, BrowserWindow, dialog, nativeImage } = require("electron");
|
||||
const { autoUpdater } = require("electron-updater");
|
||||
const checkInternetConnected = require("check-internet-connected");
|
||||
const ElectronDl = require("electron-dl");
|
||||
const contextMenu = require("electron-context-menu");
|
||||
const path = require("path");
|
||||
const log = require("electron-log");
|
||||
const { setActivity, loginToRPC, clearActivity } = require("./rpc");
|
||||
const useragents = require("./useragents.json");
|
||||
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
||||
const { getValue } = require("./store");
|
||||
const { menulayout } = require("./menu");
|
||||
import { app, Menu, BrowserWindow, dialog, nativeImage } from "electron";
|
||||
import { clearActivity, setActivity, loginToRPC } from './rpc.js';
|
||||
import { ElectronBlocker } from "@cliqz/adblocker-electron";
|
||||
import { getValue } from './store.js';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
import { join } from "path";
|
||||
|
||||
log.transports.file.level = "verbose";
|
||||
console.log = log.log;
|
||||
Object.assign(console, log.functions);
|
||||
import Windows from "./useragents.json" with { type: "json" };
|
||||
import checkInternetConnected from "check-internet-connected";
|
||||
import contextMenu from "electron-context-menu";
|
||||
import updaterpkg from "electron-updater";
|
||||
import ElectronDl from "electron-dl";
|
||||
import menulayout from './menu.js'
|
||||
import logpkg from 'electron-log';
|
||||
|
||||
const { transports, log: _log, functions } = logpkg;
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const { autoUpdater } = updaterpkg;
|
||||
|
||||
transports.file.level = "verbose";
|
||||
console.log = _log;
|
||||
Object.assign(console, functions);
|
||||
|
||||
function createWindow() {
|
||||
if (getValue("enterprise-or-normal") === "https://microsoft365.com/?auth=1") {
|
||||
var win = new BrowserWindow({
|
||||
width: 1181,
|
||||
height: 670,
|
||||
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
@@ -34,7 +42,7 @@ function createWindow() {
|
||||
var win = new BrowserWindow({
|
||||
width: 1181,
|
||||
height: 670,
|
||||
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
@@ -55,14 +63,14 @@ function createWindow() {
|
||||
height: 610,
|
||||
transparent: true,
|
||||
frame: false,
|
||||
icon: path.join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
});
|
||||
|
||||
splash.loadURL(`https://agam778.github.io/MS-365-Electron/loading`);
|
||||
win.loadURL(
|
||||
`${getValue("enterprise-or-normal") || "https://microsoft365.com/?auth=1"}`,
|
||||
{
|
||||
userAgent: getValue("useragentstring") || useragents.Windows,
|
||||
userAgent: getValue("useragentstring") || Windows,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -159,11 +167,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/powerpoint-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/powerpoint-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/powerpoint.png")
|
||||
join(__dirname, "../assets/icons/apps/powerpoint.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "PowerPoint");
|
||||
@@ -179,11 +187,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/word-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/word-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/word.png")
|
||||
join(__dirname, "../assets/icons/apps/word.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "Word");
|
||||
@@ -199,11 +207,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/excel-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/excel-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/excel.png")
|
||||
join(__dirname, "../assets/icons/apps/excel.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "Excel");
|
||||
@@ -219,11 +227,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/outlook-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/outlook-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/outlook.png")
|
||||
join(__dirname, "../assets/icons/apps/outlook.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "Outlook");
|
||||
@@ -239,11 +247,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/onedrive-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/onedrive-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/onedrive.png")
|
||||
join(__dirname, "../assets/icons/apps/onedrive.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "OneDrive");
|
||||
@@ -256,11 +264,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/teams-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/teams-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/teams.png")
|
||||
join(__dirname, "../assets/icons/apps/teams.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "Teams");
|
||||
@@ -273,11 +281,11 @@ app.on("web-contents-created", (event, contents) => {
|
||||
) {
|
||||
if (process.platform === "darwin") {
|
||||
app.dock.setIcon(
|
||||
path.join(__dirname, "../assets/icons/apps/onenote-mac.png")
|
||||
join(__dirname, "../assets/icons/apps/onenote-mac.png")
|
||||
);
|
||||
} else if (process.platform === "win32") {
|
||||
let nimage = nativeImage.createFromPath(
|
||||
path.join(__dirname, "../assets/icons/apps/onenote.png")
|
||||
join(__dirname, "../assets/icons/apps/onenote.png")
|
||||
);
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
window.setOverlayIcon(nimage, "OneNote");
|
||||
|
||||
40
app/menu.js
40
app/menu.js
@@ -1,20 +1,22 @@
|
||||
const useragents = require("./useragents.json");
|
||||
const {
|
||||
app,
|
||||
dialog,
|
||||
BrowserWindow,
|
||||
ShareMenu,
|
||||
clipboard,
|
||||
} = require("electron");
|
||||
const axios = require("axios");
|
||||
const { clearActivity, setActivity } = require("./rpc");
|
||||
const { shell } = require("electron");
|
||||
const { autoUpdater } = require("electron-updater");
|
||||
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
||||
const fetch = require("cross-fetch");
|
||||
const openAboutWindow = require("about-window").default;
|
||||
const path = require("path");
|
||||
const { getValue, setValue, getValueOrDefault } = require("./store");
|
||||
import { app, dialog, BrowserWindow, ShareMenu, clipboard } from "electron";
|
||||
import { getValue, setValue, getValueOrDefault } from './store.js';
|
||||
import { ElectronBlocker } from "@cliqz/adblocker-electron";
|
||||
import { clearActivity, setActivity } from './rpc.js';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { shell } from "electron";
|
||||
import { dirname } from 'path';
|
||||
|
||||
import useragents from "./useragents.json" with { type: "json" }
|
||||
import openAboutWindow from "about-window";
|
||||
import updaterpkg from "electron-updater";
|
||||
import fetch from "cross-fetch";
|
||||
import axios from "axios";
|
||||
import path from "path";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const { autoUpdater } = updaterpkg;
|
||||
|
||||
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
@@ -70,7 +72,6 @@ async function openExternalLink(url) {
|
||||
}
|
||||
|
||||
async function openLogsFolder() {
|
||||
const { shell } = require("electron");
|
||||
if (process.platform === "win32") {
|
||||
await shell.openPath(
|
||||
"C:\\Users\\" +
|
||||
@@ -1262,4 +1263,5 @@ const menulayout = [
|
||||
],
|
||||
},
|
||||
];
|
||||
module.exports = { menulayout };
|
||||
|
||||
export default menulayout;
|
||||
|
||||
20
app/rpc.js
20
app/rpc.js
@@ -1,12 +1,12 @@
|
||||
const { Client } = require("@xhayper/discord-rpc");
|
||||
const { dialog, BrowserWindow } = require("electron");
|
||||
const { setValue } = require("./store");
|
||||
import { dialog, BrowserWindow } from "electron";
|
||||
import { Client } from "@xhayper/discord-rpc";
|
||||
import { setValue } from "./store.js";
|
||||
|
||||
const client = new Client({
|
||||
clientId: "942637872530460742",
|
||||
});
|
||||
|
||||
async function rpcError(status) {
|
||||
export async function rpcError(status) {
|
||||
const rpcerror = dialog.showMessageBoxSync(BrowserWindow.getFocusedWindow(), {
|
||||
type: "error",
|
||||
title: "Discord RPC Error",
|
||||
@@ -19,14 +19,14 @@ async function rpcError(status) {
|
||||
}
|
||||
}
|
||||
|
||||
async function clearActivity() {
|
||||
export async function clearActivity() {
|
||||
await client.user?.clearActivity().catch((err) => {
|
||||
rpcError("clearing");
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
async function setActivity(details) {
|
||||
export async function setActivity(details) {
|
||||
if (!client.user) {
|
||||
await loginToRPC();
|
||||
}
|
||||
@@ -43,15 +43,9 @@ async function setActivity(details) {
|
||||
});
|
||||
}
|
||||
|
||||
async function loginToRPC() {
|
||||
export async function loginToRPC() {
|
||||
await client.login().catch((err) => {
|
||||
rpcError("logging into");
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clearActivity,
|
||||
setActivity,
|
||||
loginToRPC,
|
||||
};
|
||||
|
||||
10
app/store.js
10
app/store.js
@@ -1,15 +1,15 @@
|
||||
const Store = require("electron-store");
|
||||
import Store from "electron-store";
|
||||
const store = new Store();
|
||||
|
||||
function getValue(key) {
|
||||
export function getValue(key) {
|
||||
return store.get(key);
|
||||
}
|
||||
|
||||
function setValue(key, value) {
|
||||
export function setValue(key, value) {
|
||||
store.set(key, value);
|
||||
}
|
||||
|
||||
function getValueOrDefault(key, defaultValue) {
|
||||
export function getValueOrDefault(key, defaultValue) {
|
||||
const value = store.get(key);
|
||||
if (value === undefined) {
|
||||
store.set(key, defaultValue);
|
||||
@@ -17,5 +17,3 @@ function getValueOrDefault(key, defaultValue) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = { getValue, setValue, getValueOrDefault };
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "ms-365-electron",
|
||||
"version": "1.2.0",
|
||||
"type": "module",
|
||||
"description": "Unofficial Microsoft 365 Web Desktop Wrapper made with Electron",
|
||||
"main": "app/main.js",
|
||||
"main": "./app/main.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/agam778/MS-365-Electron.git"
|
||||
|
||||
Reference in New Issue
Block a user