Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/* eslint-disable no-use-before-define */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable global-require */
/* eslint-disable @typescript-eslint/no-var-requires */
import { app, BrowserWindow, dialog, ipcMain, shell } from 'electron';
import Store from 'electron-store';
import { autoUpdater } from 'electron-updater';
import path from 'path';
const DiscordRPC = require('discord-rpc');
import { OPEN_NEW_ISSUE_URL, SPONSOR_URL } from '../constants/utils';
import { getAccessToken } from '../modules/anilist/anilistApi';
import { fetchAccessToken } from '../modules/anilist/anilistApi';
import { clientData } from '../modules/clientData';
import isAppImage from '../modules/packaging/isAppImage';
import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';
import { OS } from '../modules/os';
import { STORE } from '../modules/storeVariables';

const STORE = new Store();
const DiscordRPC = require('../../release/app/node_modules/discord-rpc');

app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors');

Expand Down Expand Up @@ -91,8 +94,6 @@ const createWindow = async () => {
mainWindow.show();
mainWindow.maximize();

if (STORE.get('logged') !== true) STORE.set('logged', false);

autoUpdater.checkForUpdates();
}
});
Expand Down Expand Up @@ -154,6 +155,7 @@ app.on('window-all-closed', () => {

app
.whenReady()
// eslint-disable-next-line promise/always-return
.then(() => {
createWindow();
app.on('activate', () => {
Expand All @@ -179,7 +181,7 @@ const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', async (event, commandLine, workingDirectory) => {
app.on('second-instance', async (_, commandLine) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
Expand Down Expand Up @@ -235,11 +237,11 @@ app.on('open-url', async (event, url) => {

async function handleLogin(code: any) {
try {
const token = await getAccessToken(code);
const token = await fetchAccessToken(code);
STORE.set('access_token', token);
STORE.set('logged', true);
} catch (error: any) {
console.log('login failed with error: ' + error.message);
console.log(`login failed with error: ${error.message}`);
}
}

Expand All @@ -256,9 +258,9 @@ ipcMain.on('minimize-window', () => {
mainWindow?.minimize();
});

ipcMain.on('toggle-maximize-window', () => {
mainWindow?.isMaximized() ? mainWindow.unmaximize() : mainWindow?.maximize();
});
ipcMain.on('toggle-maximize-window', () =>
mainWindow?.isMaximized() ? mainWindow.unmaximize() : mainWindow?.maximize(),
);

ipcMain.on('close-window', () => {
mainWindow?.close();
Expand All @@ -276,6 +278,7 @@ autoUpdater.on('update-available', (info) => {
});

autoUpdater.on('update-downloaded', (info) => {
console.log('update downloaded', info);
autoUpdater.quitAndInstall();
});

Expand All @@ -290,7 +293,24 @@ autoUpdater.on('error', (info) => {
});

ipcMain.on('download-update', () => {
let pth = autoUpdater.downloadUpdate();
autoUpdater.downloadUpdate();
});

ipcMain.handle('getStore', () => {
const value = STORE.store;
console.log('store - get state', JSON.stringify(value));
return value;
});

ipcMain.handle('getStoreValue', (_, key) => {
const value = STORE.get(key);
console.log('store - get', key, value);
return value;
});

ipcMain.handle('setStoreValue', (_, key, value) => {
console.log('store - set', key, value);
return STORE.set(key, value);
});

/* DISCORD RPC */
Expand Down
4 changes: 2 additions & 2 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ export default class MenuBuilder {
label: 'Electron',
submenu: [
{
label: 'About ElectronReact',
label: 'About akuse',
selector: 'orderFrontStandardAboutPanel:',
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide ElectronReact',
label: 'Hide akuse',
accelerator: 'Command+H',
selector: 'hide:',
},
Expand Down
61 changes: 37 additions & 24 deletions src/modules/anilist/anilistApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Store from 'electron-store';

import {
AnimeData,
CurrentListAnime,
Expand All @@ -12,8 +10,9 @@ import { clientData } from '../clientData';
import { getOptions, makeRequest } from '../requests';
import isAppImage from '../packaging/isAppImage';
import { app, ipcRenderer } from 'electron';
import { STORAGE } from '../storage';
import { access } from 'fs';

const STORE: any = new Store();
const CLIENT_DATA: ClientData = clientData;
const PAGES: number = 20;
const METHOD: string = 'POST';
Expand Down Expand Up @@ -86,7 +85,7 @@ const MEDIA_DATA: string = `
* @param {*} code
* @returns access token
*/
export const getAccessToken = async (code: string): Promise<string> => {
export const fetchAccessToken = async (code: string): Promise<string> => {
const url = 'https://anilist.co/api/v2/oauth/token';

const data = {
Expand All @@ -110,7 +109,7 @@ export const getAccessToken = async (code: string): Promise<string> => {
*
* @returns viewer id
*/
export const getViewerId = async (): Promise<number> => {
export const getViewerId = async (accessToken: string): Promise<number> => {
var query = `
query {
Viewer {
Expand All @@ -120,7 +119,7 @@ export const getViewerId = async (): Promise<number> => {
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -137,7 +136,7 @@ export const getViewerId = async (): Promise<number> => {
* @param {*} viewerId
* @returns object with viewer info
*/
export const getViewerInfo = async (viewerId: number | null) => {
export const getViewerInfo = async (accessToken: string, viewerId: number | null) => {
var query = `
query($userId : Int) {
User(id: $userId, sort: ID) {
Expand All @@ -151,7 +150,7 @@ export const getViewerInfo = async (viewerId: number | null) => {
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -174,6 +173,7 @@ export const getViewerInfo = async (viewerId: number | null) => {
* @returns object with anime entries
*/
export const getViewerList = async (
accessToken: string,
viewerId: number,
status: MediaListStatus,
): Promise<CurrentListAnime> => {
Expand All @@ -197,7 +197,7 @@ export const getViewerList = async (
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -216,7 +216,7 @@ export const getViewerList = async (
};

// NOT WORKING
export const getFollowingUsers = async (viewerId: any) => {
export const getFollowingUsers = async (accessToken: string, viewerId: any) => {
var query = `
query($userId : Int) {
User(id: $userId, sort: ID) {
Expand All @@ -230,7 +230,7 @@ export const getFollowingUsers = async (viewerId: any) => {
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -249,7 +249,7 @@ export const getFollowingUsers = async (viewerId: any) => {
* @param {*} animeId
* @returns object with anime info
*/
export const getAnimeInfo = async (animeId: any) => {
export const getAnimeInfo = async (accessToken: string, animeId: any) => {
var query = `
query($id: Int) {
Media(id: $id, type: ANIME) {
Expand All @@ -259,7 +259,7 @@ export const getAnimeInfo = async (animeId: any) => {
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -282,6 +282,7 @@ export const getAnimeInfo = async (animeId: any) => {
* @returns object with trending animes
*/
export const getTrendingAnime = async (
accessToken: string,
viewerId: number | null,
): Promise<TrendingAnime> => {
var query = `
Expand All @@ -301,7 +302,7 @@ export const getTrendingAnime = async (

if (viewerId) {
var headers: any = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -325,6 +326,7 @@ export const getTrendingAnime = async (
* @returns object with most popular animes
*/
export const getMostPopularAnime = async (
accessToken: string,
viewerId: number | null,
): Promise<MostPopularAnime> => {
var query = `
Expand All @@ -344,7 +346,7 @@ export const getMostPopularAnime = async (

if (viewerId) {
var headers: any = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -366,7 +368,10 @@ export const getMostPopularAnime = async (
*
* @returns object with next anime releases
*/
export const getNextReleases = async (viewerId: number | null) => {
export const getNextReleases = async (
accessToken: string,
viewerId: number | null,
) => {
var query = `
{
Page(page: 1, perPage: ${PAGES}) {
Expand All @@ -384,7 +389,7 @@ export const getNextReleases = async (viewerId: number | null) => {

if (viewerId) {
var headers: any = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -409,6 +414,7 @@ export const getNextReleases = async (viewerId: number | null) => {
*/
export const searchFilteredAnime = async (
args: string,
accessToken: string,
viewerId: number | null,
): Promise<AnimeData> => {
var query = `
Expand All @@ -428,7 +434,7 @@ export const searchFilteredAnime = async (

if (viewerId) {
var headers: any = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand Down Expand Up @@ -480,7 +486,11 @@ export const releasingAnimes = async () => {
* @param {*} viewerId
* @returns object with animes entries filtered by genre
*/
export const getAnimesByGenre = async (genre: any, viewerId: number | null) => {
export const getAnimesByGenre = async (
genre: any,
accessToken: string,
viewerId: number | null,
) => {
var query = `
{
Page(page: 1, perPage: ${PAGES}) {
Expand All @@ -498,7 +508,7 @@ export const getAnimesByGenre = async (genre: any, viewerId: number | null) => {

if (viewerId) {
var headers: any = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand Down Expand Up @@ -550,13 +560,15 @@ export const getSearchedAnimes = async (input: any) => {
/**
* Updates a media entry list
*
* @param accessToken
* @param mediaId
* @param status
* @param scoreRaw
* @param progress
* @returns media list entry id
*/
export const updateAnimeFromList = async (
accessToken: string,
mediaId: any,
status?: any,
scoreRaw?: any,
Expand All @@ -572,7 +584,7 @@ export const updateAnimeFromList = async (
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -599,7 +611,7 @@ export const updateAnimeFromList = async (
}
};

export const deleteAnimeFromList = async (id: any): Promise<boolean> => {
export const deleteAnimeFromList = async (accessToken: string, id: any): Promise<boolean> => {
try {
var query = `
mutation($id: Int){
Expand All @@ -612,7 +624,7 @@ export const deleteAnimeFromList = async (id: any): Promise<boolean> => {
console.log('delte: ', id);

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand All @@ -636,6 +648,7 @@ export const deleteAnimeFromList = async (id: any): Promise<boolean> => {
* @param {*} progress
*/
export const updateAnimeProgress = async (
accessToken: string,
mediaId: number,
progress: number,
) => {
Expand All @@ -649,7 +662,7 @@ export const updateAnimeProgress = async (
`;

var headers = {
Authorization: 'Bearer ' + STORE.get('access_token'),
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'application/json',
Accept: 'application/json',
};
Expand Down
Loading