Skip to content

Commit

Permalink
Merge pull request #2 from Dadoum/main
Browse files Browse the repository at this point in the history
Merge changes from main
  • Loading branch information
Dadoum authored Oct 29, 2023
2 parents 9700827 + 88f658d commit 8ea4406
Show file tree
Hide file tree
Showing 13 changed files with 881 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"intel-intrinsics": "~>1.11.15",
"plist-d": {
"repository": "git+https://github.com/Dadoum/libplist-d.git",
"version": "30d152e88767611e10048b25777ecb5f9075f87c"
"version": "5020d8e45ca2c77183a44ce04053ccbf8bc83262"
},
"provision": {
"repository": "git+https://github.com/Dadoum/Provision.git",
Expand Down
2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"isfreedesktop": "0.1.1",
"memutils": "1.0.9",
"plist": "~master",
"plist-d": {"version":"30d152e88767611e10048b25777ecb5f9075f87c","repository":"git+https://github.com/Dadoum/libplist-d.git"},
"plist-d": {"version":"5020d8e45ca2c77183a44ce04053ccbf8bc83262","repository":"git+https://github.com/Dadoum/libplist-d.git"},
"provision": {"version":"533dca306b86f9c7801354b78f5187addb58b740","repository":"git+https://github.com/Dadoum/Provision.git"},
"requests": "2.1.1",
"silly": "1.2.0-dev.2",
Expand Down
12 changes: 11 additions & 1 deletion linux/gtk/ui/devicewidget.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import sideload;
import ui.authentication.authenticationassistant;
import ui.sideloadprogresswindow;
import ui.sideloadergtkapplication;
import ui.toolselectionwindow;
import ui.utils;

class DeviceWidget: PreferencesGroup {
iDevice device;
LockdowndClient lockdowndClient;
Window toolSelectionWindow;

this(iDeviceInfo deviceInfo) {
string udid = deviceInfo.udid;
Expand Down Expand Up @@ -77,7 +79,9 @@ class DeviceWidget: PreferencesGroup {
}

void showTools(iDevice device) {

auto rootWindow = cast(Window) this.getRoot();
toolSelectionWindow = new ToolSelectionWindow(rootWindow, device);
toolSelectionWindow.show();
}

void selectApplication() {
Expand Down Expand Up @@ -117,4 +121,10 @@ class DeviceWidget: PreferencesGroup {

fileChooser.show();
}

void closeWindows() {
if (toolSelectionWindow) {
toolSelectionWindow.close();
}
}
}
4 changes: 3 additions & 1 deletion linux/gtk/ui/mainwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class MainWindow: Window {

void removeDeviceWidget(iDeviceInfo deviceId) {
if (deviceId in deviceWidgets) {
deviceWidgets[deviceId].unparent();
auto deviceWidget = deviceWidgets[deviceId];
deviceWidget.unparent();
deviceWidget.closeWindows();
deviceWidgets.remove(deviceId);
if (deviceWidgets.length == 0) {
connectDeviceLabel.show();
Expand Down
2 changes: 1 addition & 1 deletion linux/gtk/ui/sideloadergtkapplication.d
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class SideloaderGtkApplication: Application {
mainWindow.removeDeviceWidget(deviceInfo);
break;
default:
log.warnF!"Device %s (%s) made something unknown, event number: %d"(deviceInfo, deviceInfo.connType, event.event);
log.warnF!"Device %s (%s) triggered an unknown event (event number: %d)."(deviceInfo, deviceInfo.connType, event.event);
break;
}
});
Expand Down
93 changes: 93 additions & 0 deletions linux/gtk/ui/toolselectionwindow.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module ui.toolselectionwindow;

import core.thread;

import std.concurrency;

import adw.ActionRow;

import gdk.Cursor;

import gtk.Dialog;
import gtk.ListBox;
import gtk.MessageDialog;
import gtk.ScrolledWindow;
import gtk.Window;

import imobiledevice;

import tools;
import tools.sidestorepairingfile;

import ui.utils;

class ToolSelectionWindow: Dialog {
ListBox toolListBox;

Cursor defaultCursor;
Cursor waitCursor;

this(Window parent, iDevice device) {
this.setTitle("Additional tools");
this.setTransientFor(parent);
this.setDefaultSize(400, 400);
this.setModal(true);

defaultCursor = this.getCursor();
waitCursor = new Cursor("wait", defaultCursor);

auto scroll = new ScrolledWindow();

Tool[] tools = cast(Tool[]) [
new SideStoreTool(device)
];

toolListBox = new ListBox(); {
foreach (tool; tools) {
ActionRow toolRow = new ActionRow();
toolRow.setTitle(tool.name());

string diagnostic = tool.diagnostic();
toolRow.setActivatable(diagnostic == null);
if (diagnostic != null) {
toolRow.setTooltipText(diagnostic);
}
toolRow.addOnActivated((_) {
setBusy(true);
new Thread({
uiTry!(() => tool.run((string message, bool canCancel = true) {
Tid parentTid = thisTid();
runInUIThread({
auto messageDialog = new MessageDialog(this, DialogFlags.DESTROY_WITH_PARENT | DialogFlags.MODAL, MessageType.INFO, canCancel ? ButtonsType.OK_CANCEL : ButtonsType.OK, message);
messageDialog.addOnResponse((response, _) {
if (canCancel) {
parentTid.send(response != ResponseType.OK);
} else {
parentTid.send(true);
}
messageDialog.close();
});
messageDialog.show();
});
return receiveOnly!bool();
})
)(this);
runInUIThread({
setBusy(false);
});
}).start();
});

toolListBox.append(toolRow);
}
}

scroll.setChild(toolListBox);
this.setChild(scroll);
}

void setBusy(bool val) {
this.setSensitive(!val);
this.setCursor(val ? waitCursor : defaultCursor);
}
}
176 changes: 176 additions & 0 deletions source/imobiledevice/house_arrest.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
* @file libimobiledevice/house_arrest.h
* @brief Access app folders and their contents.
* \internal
*
* Copyright (c) 2013-2014 Martin Szulecki All Rights Reserved.
* Copyright (c) 2010 Nikias Bassen, All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

module imobiledevice.house_arrest;

import plist.c;

import imobiledevice.afc;
import imobiledevice.libimobiledevice;
import imobiledevice.lockdown;

import dynamicloader;

mixin makeBindings;
@libimobiledevice extern(C):

/** Service identifier passed to lockdownd_start_service() to start the house arrest service */
enum HOUSE_ARREST_SERVICE_NAME = "com.apple.mobile.house_arrest";

/** Error Codes */
enum house_arrest_error_t
{
HOUSE_ARREST_E_SUCCESS = 0,
HOUSE_ARREST_E_INVALID_ARG = -1,
HOUSE_ARREST_E_PLIST_ERROR = -2,
HOUSE_ARREST_E_CONN_FAILED = -3,
HOUSE_ARREST_E_INVALID_MODE = -4,
HOUSE_ARREST_E_UNKNOWN_ERROR = -256
}

struct house_arrest_client_private; /**< \private */
alias house_arrest_client_t = house_arrest_client_private*; /**< The client handle. */

/* Interface */

/**
* Connects to the house_arrest service on the specified device.
*
* @param device The device to connect to.
* @param service The service descriptor returned by lockdownd_start_service.
* @param client Pointer that will point to a newly allocated
* housearrest_client_t upon successful return.
*
* @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when
* client is NULL, or an HOUSE_ARREST_E_* error code otherwise.
*/
house_arrest_error_t house_arrest_client_new (idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t* client);

/**
* Starts a new house_arrest service on the specified device and connects to it.
*
* @param device The device to connect to.
* @param client Pointer that will point to a newly allocated
* house_arrest_client_t upon successful return. Must be freed using
* house_arrest_client_free() after use.
* @param label The label to use for communication. Usually the program name.
* Pass NULL to disable sending the label in requests to lockdownd.
*
* @return HOUSE_ARREST_E_SUCCESS on success, or an HOUSE_ARREST_E_* error
* code otherwise.
*/
house_arrest_error_t house_arrest_client_start_service (idevice_t device, house_arrest_client_t* client, const(char)* label);

/**
* Disconnects an house_arrest client from the device and frees up the
* house_arrest client data.
*
* @note After using afc_client_new_from_house_arrest_client(), make sure
* you call afc_client_free() before calling this function to ensure
* a proper cleanup. Do not call this function if you still need to
* perform AFC operations since it will close the connection.
*
* @param client The house_arrest client to disconnect and free.
*
* @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when
* client is NULL, or an HOUSE_ARREST_E_* error code otherwise.
*/
house_arrest_error_t house_arrest_client_free (house_arrest_client_t client);

/**
* Sends a generic request to the connected house_arrest service.
*
* @param client The house_arrest client to use.
* @param dict The request to send as a plist of type PLIST_DICT.
*
* @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean
* that the request was successful. To check for success or failure you
* need to call house_arrest_get_result().
* @see house_arrest_get_result
*
* @return HOUSE_ARREST_E_SUCCESS if the request was successfully sent,
* HOUSE_ARREST_E_INVALID_ARG if client or dict is invalid,
* HOUSE_ARREST_E_PLIST_ERROR if dict is not a plist of type PLIST_DICT,
* HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode,
* or HOUSE_ARREST_E_CONN_FAILED if a connection error occurred.
*/
house_arrest_error_t house_arrest_send_request (house_arrest_client_t client, plist_t dict);

/**
* Send a command to the connected house_arrest service.
* Calls house_arrest_send_request() internally.
*
* @param client The house_arrest client to use.
* @param command The command to send. Currently, only VendContainer and
* VendDocuments are known.
* @param appid The application identifier to pass along with the .
*
* @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean
* that the command was successful. To check for success or failure you
* need to call house_arrest_get_result().
* @see house_arrest_get_result
*
* @return HOUSE_ARREST_E_SUCCESS if the command was successfully sent,
* HOUSE_ARREST_E_INVALID_ARG if client, command, or appid is invalid,
* HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode,
* or HOUSE_ARREST_E_CONN_FAILED if a connection error occurred.
*/
house_arrest_error_t house_arrest_send_command (house_arrest_client_t client, const(char)* command, const(char)* appid);

/**
* Retrieves the result of a previously sent house_arrest_request_* request.
*
* @param client The house_arrest client to use
* @param dict Pointer that will be set to a plist containing the result to
* the last performed operation. It holds a key 'Status' with the value
* 'Complete' on success or a key 'Error' with an error description as
* value. The caller is responsible for freeing the returned plist.
*
* @return HOUSE_ARREST_E_SUCCESS if a result plist was retrieved,
* HOUSE_ARREST_E_INVALID_ARG if client is invalid,
* HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode,
* or HOUSE_ARREST_E_CONN_FAILED if a connection error occurred.
*/
house_arrest_error_t house_arrest_get_result (house_arrest_client_t client, plist_t* dict);

/**
* Creates an AFC client using the given house_arrest client's connection
* allowing file access to a specific application directory requested by
* functions like house_arrest_request_vendor_documents().
*
* @param client The house_arrest client to use.
* @param afc_client Pointer that will be set to a newly allocated afc_client_t
* upon successful return.
*
* @note After calling this function the house_arrest client will go in an
* AFC mode that will only allow calling house_arrest_client_free().
* Only call house_arrest_client_free() if all AFC operations have
* completed since it will close the connection.
*
* @return AFC_E_SUCCESS if the afc client was successfully created,
* AFC_E_INVALID_ARG if client is invalid or was already used to create
* an afc client, or an AFC_E_* error code returned by
* afc_client_new_with_service_client().
*/
afc_error_t afc_client_new_from_house_arrest_client (house_arrest_client_t client, afc_client_t* afc_client);

Loading

0 comments on commit 8ea4406

Please sign in to comment.