Skip to content

Commit d34f32b

Browse files
committed
feat: save code
1 parent f450c62 commit d34f32b

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

src/constants/ascii-art.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { arch, platform, version } from "@tauri-apps/plugin-os";
2+
3+
import { ApplicationName } from "@/constants/application.ts";
4+
5+
export function getASCIIArt(portable: boolean): string {
6+
return (
7+
"\n __ __ " +
8+
" me@" + ApplicationName.toLowerCase() +
9+
"\n / /______ ____ ____/ /__ " +
10+
" os " + platform() + " " + version() +
11+
"\n / //_/ __ `/ _ \\/ __ / _ \\" +
12+
" arch " + arch() +
13+
"\n / ,< / /_/ / __/ /_/ / __/" +
14+
" mode " + (portable ? "portable" : "non-portable") +
15+
"\n/_/|_|\\__,_/\\___/\\__,_/\\___/ " +
16+
" online " + (
17+
(navigator?.onLine ?? "unknown") ? "yes" : "no"
18+
) +
19+
"\n "
20+
);
21+
}

src/lib/configs/scopes/get-config-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { log } from "@/lib/logging/scopes/log.ts";
1010
import Schemas from "@/lib/schemas";
1111
import type { ConfigType } from "@/types/application/config.type.ts";
1212

13-
export async function getConfigFile(): Promise<ConfigType> {
13+
export async function getConfigFile(portableStatus?: boolean): Promise<ConfigType> {
1414
const hooksArray = window[ApplicationNamespace].hooks.getConfigFile.before;
1515

1616
log.debug("Checking if launcher is in portable version");
17-
const portable = await General.checkIsPortable();
17+
const portable = portableStatus ?? await General.checkIsPortable();
1818

1919
log.debug("Getting base directory");
2020
const baseDirectory = portable

src/lib/general/scopes/initialize-launcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import Errors from "@/lib/errors";
55
import { log } from "@/lib/logging/scopes/log.ts";
66
import type { ConfigType } from "@/types/application/config.type.ts";
77

8-
export async function initializeLauncher(): Promise<void> {
8+
export async function initializeLauncher(portable: boolean): Promise<void> {
99
let config: ConfigType;
1010

1111
try {
1212
log.debug("Getting a config file");
13-
config = await Configs.get();
13+
config = await Configs.get(portable);
1414
} catch (error: unknown) {
1515
log.error("Failed to get a config file:", Errors.prettify(error));
1616
log.debug("Getting default config");

src/lib/global-state-helpers/scopes/get-config-global-states.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,9 @@ export async function getConfigGlobalStates(
3131
const baseDirectory = portable
3232
? await General.getExecutableDirectory()
3333
: await appDataDir();
34-
const portableVersion = portable ? "Portable version" : "Non-portable version";
34+
const portableVersion = portable ? "Portable" : "Non-portable";
3535

36-
log.info(
37-
`Running in the ${portableVersion}` + "\n" +
38-
" __ __ \n" +
39-
" / /______ ____ ____/ /__ \n" +
40-
" / //_/ __ `/ _ \\/ __ / _ \\\n" +
41-
" / ,< / /_/ / __/ /_/ / __/\n" +
42-
"/_/|_|\\__,_/\\___/\\__,_/\\___/ \n" +
43-
" ",
44-
);
36+
log.info(`Running in the '${portableVersion}' version`);
4537
log.debug("Finishing 'getConfigGlobalStates' execution");
4638

4739
return {
@@ -78,7 +70,7 @@ export async function getConfigGlobalStates(
7870
},
7971
"logs": {
8072
...defaultGlobalStates.logs,
81-
"show" : false,
73+
"show" : true,
8274
"lineBreaks" : false,
8375
"virtualized": false,
8476
"filtering" : "",

src/lib/logging/scopes/prepare-log-file.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function getNumberFromLogFilename(filename: string): number {
3535
*
3636
* else just write into 'latest.log' without other manipulations
3737
*/
38-
export async function prepareLogFile(): Promise<void> {
38+
export async function prepareLogFile(): Promise<{
39+
"portable": boolean;
40+
}> {
3941
const portable: boolean = await General.checkIsPortable();
4042

4143
const baseDirectory = portable
@@ -79,14 +81,14 @@ export async function prepareLogFile(): Promise<void> {
7981

8082
await newLatestLogFile.close();
8183

82-
return;
84+
return { portable };
8385
}
8486

8587
const latestLogContent = await readTextFile(latestLogPath);
8688

8789
// 'latest.log' is empty; no need to copy empty contents into another log file
8890
if (latestLogContent === "") {
89-
return;
91+
return { portable };
9092
}
9193

9294
const renamedLogPath = await join(
@@ -99,5 +101,5 @@ export async function prepareLogFile(): Promise<void> {
99101
// Clear the 'latest.log' file
100102
await writeTextFile(latestLogPath, "");
101103

102-
return;
104+
return { portable };
103105
}

src/main.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ import { createApp } from "vue";
1111

1212
import App from "@/App.vue";
1313
import { ApplicationRootID } from "@/constants/application";
14+
import { getASCIIArt } from "@/constants/ascii-art.ts";
1415
import Errors from "@/lib/errors";
1516
import General from "@/lib/general";
1617
import Globals from "@/lib/globals";
1718
import Logging from "@/lib/logging";
1819
import { log } from "@/lib/logging/scopes/log.ts";
1920

21+
// Share the 'portable' status between other functions
22+
let portable: boolean = false;
23+
2024
// No need to log yet, all logs will go into the previous launch log file
21-
await Logging.prepareLogFile().catch((error: unknown) => {
25+
try {
26+
const result = await Logging.prepareLogFile();
27+
28+
// Now the log file preparation is done (unless something threw an error)
29+
portable = result.portable;
30+
} catch (error: unknown) {
2231
log.error("Failed to prepare a log file:", Errors.prettify(error));
23-
});
32+
}
33+
34+
// Show a pretty ASCII art with the launcher name :3
35+
log.info(getASCIIArt(portable));
2436

25-
// Now the log file preparation is done (unless something threw an error)
2637
log.debug("Extending global window object in the app namespace");
2738
Globals.declareWindow();
2839

@@ -34,6 +45,6 @@ log.debug(`Mounting app instance to the DOM element (${ApplicationRootID})`);
3445
AppInstance.mount(ApplicationRootID);
3546

3647
log.debug("Initializing launcher");
37-
await General.initializeLauncher().catch((error: unknown) => {
48+
await General.initializeLauncher(portable).catch((error: unknown) => {
3849
log.error("Failed to initialize launcher:", Errors.prettify(error));
3950
});

0 commit comments

Comments
 (0)