Skip to content

Commit

Permalink
feat: resolve file icon from github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardssh committed Feb 14, 2022
1 parent 83d6dfe commit 92e5794
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { sep } from 'path';
import { dataClass } from './data';
import { isObject } from './helpers/isObject';
import { isExcluded } from './helpers/isExcluded';
import { resolveFileIcon, toLower, toTitle, toUpper } from './helpers/resolveFileIcon';
import { getFileIcon, resolveFileIcon, toLower, toTitle, toUpper } from './helpers/resolveFileIcon';

let totalProblems = 0;

Expand Down Expand Up @@ -57,10 +57,10 @@ export function activity(previous: Presence = {}, isViewing = false): Presence {
const insiders = appName.includes('Insiders');

const defaultSmallImageKey = debug.activeDebugSession
? DEBUGGING_IMAGE_KEY
? getFileIcon(DEBUGGING_IMAGE_KEY)
: insiders
? VSCODE_INSIDERS_IMAGE_KEY
: VSCODE_IMAGE_KEY;
? getFileIcon(VSCODE_INSIDERS_IMAGE_KEY)
: getFileIcon(VSCODE_IMAGE_KEY);

const defaultSmallImageText = config[CONFIG_KEYS.SmallImage].replace(
REPLACE_KEYS.AppName,
Expand Down Expand Up @@ -96,7 +96,9 @@ export function activity(previous: Presence = {}, isViewing = false): Presence {
startTimestamp: config[CONFIG_KEYS.RemoveElapsedTime]
? undefined
: previous.startTimestamp ?? Date.now(),
largeImageKey: insiders ? IDLE_VSCODE_IMAGE_KEY : IDLE_VSCODE_INSIDERS_IMAGE_KEY,
largeImageKey: insiders
? getFileIcon(IDLE_VSCODE_IMAGE_KEY)
: getFileIcon(IDLE_VSCODE_INSIDERS_IMAGE_KEY),
largeImageText: defaultLargeImageText,
smallImageKey: defaultSmallImageKey,
smallImageText: defaultSmallImageText
Expand Down Expand Up @@ -155,7 +157,7 @@ export function activity(previous: Presence = {}, isViewing = false): Presence {
CONFIG_KEYS.LowerDetailsDebugging,
isViewing
),
largeImageKey,
largeImageKey: getFileIcon(largeImageKey),
largeImageText
};

Expand Down
14 changes: 10 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getConfig } from './config';
import { CONFIG_KEYS, IDLE_SMALL_IMAGE_KEY } from './constants';
import { getApplicationId } from './helpers/getApplicationId';
import { dataClass } from './data';
import { getFileIcon } from './helpers/resolveFileIcon';

let state: Presence = {};
let rpc: Client | undefined = undefined;
Expand Down Expand Up @@ -76,7 +77,7 @@ export const toggleIdling = async (windowState: WindowState) => {
idleCheckTimeout = setTimeout(async () => {
state = {
...state,
smallImageKey: IDLE_SMALL_IMAGE_KEY,
smallImageKey: getFileIcon(IDLE_SMALL_IMAGE_KEY),
smallImageText: config[CONFIG_KEYS.IdleText]
};

Expand Down Expand Up @@ -116,6 +117,8 @@ export const login = async () => {
rpc.on('disconnected', () => {
cleanUp();

rpc && rpc.destroy();

statusBarIcon.text = '$(search-refresh) Reconnect to Discord Gateway';
statusBarIcon.command = 'rpc.reconnect';
statusBarIcon.tooltip = 'Reconnect to Discord Gateway';
Expand All @@ -130,7 +133,8 @@ export const login = async () => {
} catch (error: any) {
logError(`Encountered following error while trying to login:\n${error as string}`);

void rpc?.destroy();
rpc && rpc.destroy();

logInfo(`[002] Destroyed Discord RPC client`);

if (!config[CONFIG_KEYS.SuppressNotifications]) {
Expand Down Expand Up @@ -174,7 +178,8 @@ export const registerComamnds = (ctx: ExtensionContext) => {

cleanUp();

void rpc?.destroy();
rpc && rpc.destroy();

logInfo(`[003] Destroyed Discord RPC client`);

statusBarIcon.hide();
Expand Down Expand Up @@ -255,7 +260,8 @@ export function deactivate() {
idleCheckTimeout = undefined;
}

void rpc?.destroy();
rpc && rpc.destroy();

logInfo(`[004] Destroyed Discord RPC client`);
}

Expand Down
3 changes: 3 additions & 0 deletions src/helpers/resolveFileIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const toLower = (str: string) => str.toLocaleLowerCase();
export const toUpper = (str: string) => str.toLocaleUpperCase();
export const toTitle = (str: string) => toLower(str).replace(/^\w/, (c) => toUpper(c));

export const getFileIcon = (name: string) =>
`https://raw.githubusercontent.com/LeonardSSH/vscord/main/assets/icons/${name}.png`;

export function resolveFileIcon(document: TextDocument) {
const config = getConfig();
const filename = basename(document.fileName);
Expand Down

0 comments on commit 92e5794

Please sign in to comment.