Skip to content
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
34 changes: 6 additions & 28 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ chardet = "0.2.4"
chardetng = "0.1.17"
encoding_rs = "0.8.34"
dirs-next = "2.0.0"
discord-rich-presence = "0.2.4"
regex = "1.10.5"
runas = "1.2.0"
sysinfo = "0.30.13"
Expand Down
3 changes: 1 addition & 2 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ pub async fn inject(
dll: &str,
omp_file: &str,
password: &str,
discord: bool,
) -> std::result::Result<(), String> {
match injector::run_samp(name, ip, port, exe, dll, omp_file, password, discord).await {
match injector::run_samp(name, ip, port, exe, dll, omp_file, password).await {
Ok(_) => Ok(()),
Err(e) => {
log::warn!("{}", e);
Expand Down
10 changes: 2 additions & 8 deletions src-tauri/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub async fn run_samp(
_dll_path: &str,
_omp_file: &str,
_password: &str,
_discord: bool,
) -> Result<()> {
Ok(())
}
Expand All @@ -31,7 +30,6 @@ pub async fn run_samp(
dll_path: &str,
omp_file: &str,
password: &str,
discord: bool,
) -> Result<()> {
// Prepare the command to spawn the executable
let mut cmd = Command::new(format!("{}/{}", executable_dir, GTA_SA_EXECUTABLE));
Expand All @@ -49,16 +47,12 @@ pub async fn run_samp(
ready_for_exec = ready_for_exec.arg("-z").arg(password);
}

if discord {
ready_for_exec = ready_for_exec.arg("--discord");
}

let process = ready_for_exec.current_dir(executable_dir).spawn();

match process {
Ok(p) => {
inject_dll(p.id(), dll_path, 0, false)?;
inject_dll(p.id(), omp_file, 0, false)
inject_dll(p.id(), dll_path, 0, false)
// inject_dll(p.id(), omp_file, 0, false)
}
Err(e) => {
info!("[injector.rs] Process creation failed: {}", e);
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ async fn handle_cli_args() -> Result<()> {
&format!("{}/{}", gamepath, SAMP_DLL),
&omp_client_path,
&password,
true,
)
.await
.map_err(|e| LauncherError::InternalError(e.to_string()))?;
Expand Down
12 changes: 8 additions & 4 deletions src/containers/AddThirdPartyServer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isValidDomain,
validateServerAddressIPv4,
} from "../../utils/validation";
import { Log } from "../../utils/logger";

const AddThirdPartyServerModal = () => {
const { visible, showAddThirdPartyServer } = useAddThirdPartyServerModal();
Expand All @@ -31,11 +32,14 @@ const AddThirdPartyServerModal = () => {

useEffect(() => {
if (visible) {
clipboard.readText().then((text) => {
if (text) {
setServerAddress(text);
(async () => {
try {
const text = await clipboard.readText();
if (text) setServerAddress(text);
} catch (e) {
Log.error(e);
}
});
})();
}
}, [visible]);

Expand Down
15 changes: 8 additions & 7 deletions src/containers/ExternalServerHandler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ const ExternalServerHandler = () => {
const { addToFavorites } = usePersistentServers();

useEffect(() => {
try {
(async () => {
(async () => {
try {
const value = await invoke<string>("get_uri_scheme_value");
if (
typeof value === "string" &&
value.length &&
(value.includes("omp://") || value.includes("samp://"))
) {
Expand All @@ -48,10 +49,10 @@ const ExternalServerHandler = () => {
showModal(true);
setServerAddress(serverAddress);
}
})();
} catch (e) {
Log.error(e);
}
} catch (e) {
Log.error(e);
}
})();

const unlisten = listen<string>("scheme-request-received", (event) => {
if (typeof event.payload === "string") {
Expand All @@ -71,7 +72,7 @@ const ExternalServerHandler = () => {
});

return () => {
unlisten.then((f) => f());
unlisten.then((f) => f()).catch((e) => Log.error(e));
};
}, []);

Expand Down
25 changes: 1 addition & 24 deletions src/containers/Settings/Tab/Advanced.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { t } from "i18next";
import { Pressable, StyleSheet, TouchableOpacity, View } from "react-native";
import CheckBox from "../../../components/CheckBox";
import { StyleSheet, TouchableOpacity, View } from "react-native";
import Text from "../../../components/Text";
import { useGenericPersistentState } from "../../../states/genericStates";
import { useTheme } from "../../../states/theme";
import {
exportFavoriteListFile,
Expand All @@ -12,8 +10,6 @@ import { sc } from "../../../utils/sizeScaler";

const Advanced = () => {
const { theme } = useTheme();
const { shouldUpdateDiscordStatus, toggleDiscordStatus } =
useGenericPersistentState();
return (
<View
style={{
Expand All @@ -31,25 +27,6 @@ const Advanced = () => {
marginTop: sc(10),
}}
>
<Pressable
style={{
flexDirection: "row",
alignItems: "center",
}}
onPress={async () => {
toggleDiscordStatus(!shouldUpdateDiscordStatus);
}}
>
<CheckBox
value={shouldUpdateDiscordStatus}
style={{ marginRight: sc(7) }}
/>
<Text semibold color={theme.textPrimary} size={2}>
{`${t("settings_advanced_discord_status")} ${t(
"settings_advanced_discord_status_requires_restart"
)}`}
</Text>
</Pressable>
<TouchableOpacity
style={[
styles.importButton,
Expand Down
36 changes: 17 additions & 19 deletions src/containers/Settings/Tab/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,19 @@ const General = () => {
};

const importFavListFromSAMP = async () => {
await invoke("get_samp_favorite_list").then((a) => {
const userData: {
file_id: string;
file_version: number;
server_count: number;
favorite_servers: {
ip: string;
port: number;
name: string;
password: string;
rcon: string;
}[];
} = JSON.parse(a as string);
try {
const a = await invoke("get_samp_favorite_list");
let userData: any = null;
try {
userData = JSON.parse(a as string);
} catch (err) {
Log.debug("Failed to parse samp favorite list:", err);
return;
}

if (userData.file_id === "SAMP") {
if (userData?.file_id === "SAMP") {
const { addToFavorites } = usePersistentServers.getState();
userData.favorite_servers.forEach((server) => {
userData.favorite_servers?.forEach((server: any) => {
const serverInfo: Server = {
ip: "",
port: 0,
Expand All @@ -88,24 +84,26 @@ const General = () => {
rules: {} as Server["rules"],
};

if (server.ip.length) {
if (server?.ip?.length) {
serverInfo.ip = server.ip;
serverInfo.port = server.port;
if (server.name.includes("(Retrieving info...)")) {
if (server.name?.includes("(Retrieving info...)")) {
serverInfo.hostname += ` (${serverInfo.ip}:${serverInfo.port})`;
} else {
serverInfo.hostname = server.name;
}

if (server.password.length) {
if (server.password?.length) {
serverInfo.password = server.password;
}

addToFavorites(serverInfo);
}
});
}
});
} catch (err) {
Log.debug(err);
}
};

return (
Expand Down
5 changes: 0 additions & 5 deletions src/states/genericStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,17 @@ const useGenericTempState = create<GenericTempStates>()((set, get) => ({
interface GenericPersistentStates {
sideLists: boolean;
language: LanguageType;
shouldUpdateDiscordStatus: boolean;
showSideLists: (show: boolean) => void;
setLanguage: (lang: LanguageType) => void;
toggleDiscordStatus: (toggle: boolean) => void;
}

const useGenericPersistentState = create<GenericPersistentStates>()(
persist(
(set) => ({
sideLists: true,
language: "en",
shouldUpdateDiscordStatus: true,
showSideLists: (show: boolean) => set(() => ({ sideLists: show })),
setLanguage: (lang) => set(() => ({ language: lang })),
toggleDiscordStatus: (toggle) =>
set(() => ({ shouldUpdateDiscordStatus: toggle })),
}),
{
name: "generic-state-storage",
Expand Down
8 changes: 3 additions & 5 deletions src/utils/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ResourceInfo,
validFileChecksums,
} from "../constants/app";
import { useGenericPersistentState } from "../states/genericStates";
import { useJoinServerPrompt } from "../states/joinServerPrompt";
import { useMessageBox } from "../states/messageModal";
import { useNotification } from "../states/notification";
Expand All @@ -35,11 +34,12 @@ const getLocalPath = async (...segments: string[]) =>
export const copySharedFilesIntoGameFolder = async () => {
const { gtasaPath } = useSettings.getState();
const shared = await getLocalPath("samp", "shared");
// invoke resolves on success and rejects on failure — don't turn a
// successful resolution into an exception. Await and let callers
// handle rejections via try/catch.
await invoke("copy_files_to_gtasa", {
src: shared,
gtasaDir: gtasaPath,
}).then((e) => {
throw e;
});
};

Expand Down Expand Up @@ -72,7 +72,6 @@ export const startGame = async (
const { sampVersion } = useSettings.getState();
const { showPrompt, setServer } = useJoinServerPrompt.getState();
const { setSelected } = useServers.getState();
const { shouldUpdateDiscordStatus } = useGenericPersistentState.getState();

if (IN_GAME) {
invoke("send_message_to_game", {
Expand Down Expand Up @@ -218,7 +217,6 @@ export const startGame = async (
dll: ourSAMPDllPath,
ompFile: await getLocalPath("omp", "omp-client.dll"),
password,
discord: shouldUpdateDiscordStatus,
})
.then(() => {
addToRecentlyJoined(server);
Expand Down